Skip to content

Instantly share code, notes, and snippets.

@som-snytt
Created September 21, 2017 18:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save som-snytt/f0cb3468662de2977e635c8ffebff028 to your computer and use it in GitHub Desktop.
Save som-snytt/f0cb3468662de2977e635c8ffebff028 to your computer and use it in GitHub Desktop.
test for firstCompletedOf
package scala.concurrent
import org.junit.Assert._
import org.junit.Test
import org.junit.runner.RunWith
import org.junit.runners.JUnit4
import scala.tools.testing.AssertUtil._
import scala.util.Try
import java.util.concurrent.CountDownLatch
@RunWith(classOf[JUnit4])
class FutureTest {
@Test
def `bug/issues#10513 firstCompletedOf must not leak references`: Unit = {
import ExecutionContext.Implicits._
val unfulfilled = Promise[AnyRef]
val quick = Promise[AnyRef]
val result = new AnyRef
val first = Future.firstCompletedOf(List(quick.future, unfulfilled.future))
assertNotReachable(result, unfulfilled) {
quick.complete(Try(result))
}
/* The test has this structure:
val p = Promise[String]
val q = Promise[String]
val res = Promise[String]
val s = "hi"
p.future.onComplete(t => res.complete(t))
q.future.onComplete(t => res.complete(t))
assertNotReachable(s, q) {
p.complete(Try(s))
}
*/
}
}
@eyalfa
Copy link

eyalfa commented Sep 21, 2017

Interesting, I wasn't aware of this testing style, I most definitely like it better than guessing when's the jvm's going to break...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment