question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Stack overflow when running a test with many `assertTrue`s combined

See original GitHub issue

The following code produces java.lang.StackOverflowError when you run the test.

object Test extends DefaultRunnableSpec {
  def spec = suite("Test")(
    test("1") {
      val asserts = List.fill(10000)(assertTrue(true))
      asserts.reduce(_ && _)
    }
  )
}
java.lang.StackOverflowError
	at zio.test.TestArrow$.$anonfun$run$1(TestArrow.scala:101)
	at scala.util.Try$.apply(Try.scala:210)
	at zio.test.TestArrow$.attempt(TestArrow.scala:94)
	at zio.test.TestArrow$.run(TestArrow.scala:100)
	at zio.test.TestArrow$.$anonfun$run$1(TestArrow.scala:113)
	at scala.util.Try$.apply(Try.scala:210)
	at zio.test.TestArrow$.attempt(TestArrow.scala:94)
	at zio.test.TestArrow$.run(TestArrow.scala:100)
...

Happens on both ZIO 1.0.14 and 2.0.0-RC6 (with DefaultRunnableSpec -> ZIOSpecDefault).

Issue Analytics

  • State:open
  • Created a year ago
  • Comments:8 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
emilhotkowskicommented, May 15, 2022

Because of operators like And and Or this function runs DFS on graph created by TestArrow in pessimistic case. The only way to make recursive DFS stack safe is to manage stack by yourself AFAIK. If this was up for grabs I’d be happy to help 😃

0reactions
emilhotkowskicommented, Jul 20, 2022

@kitlangton is this still relavent? I didn’t get any answer last time. I think we could use trampolining, either with ZIO object or TailRec from standard Scala.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Stop requiring only one assertion per unit test
One way to handle this is to refactor the test code into a method that can then be shared between two separate tests....
Read more >
Can you have multiple assertEquals(answer, result) in the ...
All asserts will be run, in order. The first assertion to fail causes the test to fail and no further asserts are run...
Read more >
Is it OK to have multiple asserts in a single unit test?
The main reason people like to have multiple Assertions is they are trying to have a one [TestFixture] class for each class being...
Read more >
Stack Overflow for test while main runs fine : r/rust - Reddit
Hi All, I'm working my way through Advent of code, and I ran into this weird issue while working on Day 03's puzzle....
Read more >
JUnit 5 User Guide
Ask JUnit 5 related questions on Stack Overflow or chat with the ... for test cases designed to be invoked multiple times depending...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found