Last active
December 23, 2015 10:19
-
-
Save ndwade/6621018 to your computer and use it in GitHub Desktop.
Suspecting a bug in org.scalatest.concurrent.AsynchronousAssertions.Waiter. The code below fails pretty reliably. There seems to be a window of vulnerability in awaitImpl(): if the last (or last few) dismiss() calls happen after the dismissals count test at the top of the while() loop, but the associated notifyAll() invocations happen before the…
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package scratch | |
// scalatest 2.0.M8 | |
import org.scalatest.WordSpec | |
import org.scalatest.matchers.ShouldMatchers | |
import org.scalatest.concurrent.AsyncAssertions | |
import org.scalatest.time.{ Span, Millis } | |
class WaiterSpec extends WordSpec with ShouldMatchers with AsyncAssertions { | |
"A Waiter instance" should { | |
"not break when beaten on" in { | |
val n = 100000 | |
val w = new Waiter | |
new Thread(new Runnable { | |
override def run(): Unit = { | |
var i = 0 | |
while (i < n) { w.dismiss(); i += 1 } | |
println(s"i=$i") | |
} | |
}).start | |
w.await(timeout(Span(2000, Millis)), dismissals(n)) | |
} | |
} | |
} |
Huzzah! Scalatest built and tests ran ok. Instructions were a big help. (Yeah I'd discovered the memory and JDK-7 issues.)
Now working on integrating my fix.
OK, pull request made. Happy to iterate if necessary.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Sorry it took me a while to get enough focused time to study this. I think your reasoning makes sense. Can you submit a pull request?
Also we have added instructions on building ScalaTest to the scalatest.org site and the github project. With the advent of Scala 2.10.3 it has become much easier (because of a memory-leak fix in the Scala compiler that affected ScalaTest badly). Previously I couldn't build it with sbt on my laptop with 8Gb (though I could with ant)! Now the sbt build works fine in much less memory, so I'd recommend using that instead of ant now. We also as of this morning made a tweak that enables ScalaTest to be built on JDK 7 as well as JDK6. The problem was that some Swing classes, which were raw in JDK6, were generified in JDK7. We had to use code gen to deal with that, but that was another thing that made ScalaTest hard to build.
Thanks.
Bill