Skip to content

Instantly share code, notes, and snippets.

@ndwade
Last active December 23, 2015 10:19
Show Gist options
  • Save ndwade/6621018 to your computer and use it in GitHub Desktop.
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…
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))
}
}
}
@ndwade
Copy link
Author

ndwade commented Oct 6, 2013

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