Scala Test Runner Reports Error Erroneously for Prime Factors

For at least two solutions that pass locally the Scala test runner reports:

An error occurred while running your tests. This might mean that there was an issue in our infrastructure, or it might mean that you have something in your code that’s causing our systems to break.

Please check your code, and if nothing seems to be wrong, try running the tests again.

The solutions are

object PrimeFactors {
  case class Accumulator(remaining: Long, factors: List[Long], factor: Long)

  def factors(n: Long): List[Long] = {
    def reduceForFactor(acc: Accumulator): Accumulator = {
      if (acc.remaining!= 0 && acc.remaining % acc.factor == 0) reduceForFactor(Accumulator(acc.remaining / acc.factor, acc.factor :: acc.factors, acc.factor))
      else acc
    }

    def go(acc: Accumulator): Accumulator = {
      if(acc.remaining <=1) acc
      else go(reduceForFactor(acc.copy(factor = acc.factor+1)))
    }

    go(Accumulator(n, List(), 1)).factors.reverse
  }
}

and

import scala.annotation.tailrec

object PrimeFactors {

  def factors(nbr: Long): List[Long] = {

    @tailrec
    def factorRecurEven(nbr: Long, output: List[Long]): List[Long] =
      nbr match {
        case nbr if (2L > nbr)       => output
        case nbr if ((nbr & 1) != 0) => output
        case nbr                     => factorRecurEven(nbr >> 1, 2L :: output)
      }

    @tailrec
    def factorRecurOdd(
        nbr: Long,
        factor: Long,
        output: List[Long]
    ): List[Long] =
      nbr match {
        case nbr if (factor > nbr) => output
        case nbr if (nbr % factor != 0) =>
          factorRecurOdd(nbr, factor + 2, output)
        case nbr => factorRecurOdd(nbr / factor, factor, factor :: output)
      }

    factorRecurOdd(nbr, 3, factorRecurEven(nbr, List.empty[Long])).reverse
  }
}

@ErikSchierboom One for you to check please!

Bump, as meanwhile .Net has come up as an issue and been fixed.

I’m still looking into this!

@bobahop I could reproduce this locally. It looks like there might have been some syncing issue of sorts. For me, the tests file somehow was still using the old test format and there was no update notification on the exercise’s page. I managed to fix it by doing exercism download --force --track scala --exercise prime-factors

@ErikSchierboom, thank you very much for looking into this!

The top solution still gets

An error occurred while running your tests. This might mean that there was an issue in our infrastructure, or it might mean that you have something in your code that’s causing our systems to break.

For the bottom solution it’s claiming the tests time out.

Your tests timed out. This might mean that there was an issue in our infrastructure, but more likely it suggests that your code is running slowly. Is there an infinite loop or something similar?

Both still pass locally. The bottom one returns

[info] Run completed in 389 milliseconds.
[info] Total number of tests run: 7
[info] Suites: completed 1, aborted 0
[info] Tests: succeeded 7, failed 0, canceled 0, ignored 0, pending 0
[info] All tests passed.
[success] Total time: 6 s, completed Jul 11, 2023, 7:25:58 AM

The top one returns

[info] Run completed in 631 milliseconds.
[info] Total number of tests run: 7
[info] Suites: completed 1, aborted 0
[info] Tests: succeeded 7, failed 0, canceled 0, ignored 0, pending 0
[info] All tests passed.
[success] Total time: 8 s, completed Jul 11, 2023, 7:30:33 AM

On multiple runs the bottom solution sometimes gives “An error occurred” instead of the timeout.

Could you post your tests file?

import org.scalatest.funsuite.AnyFunSuite
import org.scalatest.matchers.should.Matchers

/** @version 1.1.0 */
class PrimeFactorsTest extends AnyFunSuite with Matchers {

test(“no factors”) {
PrimeFactors.factors(1) should be(List())
}

test(“prime number”) {
// pending
PrimeFactors.factors(2) should be(List(2))
}

test(“square of a prime”) {
// pending
PrimeFactors.factors(9) should be(List(3, 3))
}

test(“cube of a prime”) {
// pending
PrimeFactors.factors(8) should be(List(2, 2, 2))
}

test(“product of primes and non-primes”) {
// pending
PrimeFactors.factors(12) should be(List(2, 2, 3))
}

test(“product of primes”) {
// pending
PrimeFactors.factors(901255) should be(List(5, 17, 23, 461))
}

test(“factors include a large prime”) {
// pending
PrimeFactors.factors(93819012551L) should be(List(11, 9539, 894119))
}
}

I’ve been getting this same error message for the last couple of days in the Scala track for the Yacht exercise. As far as I can tell, there aren’t any issues with my code. My code compiles locally, tests pass and it also works in Scastie with all the Scala 2 build settings matching the Exercism test runner as best I can.

I went as far as cloning the Scala Test Runner and trying to run it locally but I wasn’t having any luck. I couldn’t get bin/run.sh to work at all. The Docker version ran without reporting any issues but it did in fact fail to run any of the tests. I could not figure out why.

Lastly, I tried running the tests in my own Docker container using the same image as the Exercism test runner but it kept hanging on a particular dependency and I gave up. I was able to compile my code without issue in that container, though.

I will gladly share my code, if that helps. Thanks!

I’m digging a bit deeper into this issue and for some reason the logs show this:

Exception in thread "main" java.io.FileNotFoundException: /tmp/exercise/test-reports/TEST-PrimefactorsTest.xml (No such file or directory)

So it sounds like something goes wrong, but stderr is empty and stdout is:

prime-factors: testing...
prime-factors: done

It sounds like something went wrong with compiling or testing the project, but I don’t see anything in the logging. @KirillArtamonov you have the most knowledge about the test runner, do you have any idea?

Hey Erik. I was seeing the exact same error when using the Exercism test runner with Docker locally but for the Yacht exercise.

Here’s a fix for Yacht: Fix Yacht tests in online test runner by artamonovkirill · Pull Request #790 · exercism/scala · GitHub
As for Prime Numbers, I cannot reproduce it locally yet with ./bin/run-in-docker.sh. I’ll dig further.

2 Likes

Thanks so much for the fix for the Yacht tests, @KirillArtamonov!

As per discussion here, created: Ensure test results are parseable by test runner by artamonovkirill · Pull Request #791 · exercism/scala · GitHub (and also added an issue for improving test runner).

Given there were other types of issues with the test runner before (e.g., this or that), it is interesting to see top exercises by failure rate at test runner (maybe, for last 10-20 submissions only?).

Or maybe I can get Fixes https://github.com/exercism/scala-test-runner/issues/50 by artamonovkirill · Pull Request #51 · exercism/scala-test-runner · GitHub reviewed (and the shell script checking test files/classes can be dropped)?

@bobahop We’ve merged the PRs of @KirillArtamonov to fix the test runner. Could you check if things have improved for you?

Prime Numbers with one of the solutions @bobahop posted :raised_hands:

As Ensure test results are parseable by test runner by artamonovkirill · Pull Request #791 · exercism/scala · GitHub - I removed the check script, but maybe we can still merge the change of class names - just to fix IDE warnings?

1 Like

It’s a great day! I’ll try to find the student who was having a problem and let them know. Thank you very very much!