Skip to content

Instantly share code, notes, and snippets.

@seanparsons
Created July 7, 2011 15:58
Show Gist options
  • Save seanparsons/1069838 to your computer and use it in GitHub Desktop.
Save seanparsons/1069838 to your computer and use it in GitHub Desktop.
Basic timed property for use with ScalaCheck.
import org.scalacheck.Prop
import org.scalacheck.Prop.Params
import java.util.concurrent.atomic.AtomicBoolean
class TimedProp(maximumMs: Int, wrappedProp: => Prop) extends Prop {
def apply(prms: Params) = {
val atLeastOnce = new AtomicBoolean(true)
val startTime = System.currentTimeMillis()
val resultStream = Stream.continually{
Thread.sleep(20)
wrappedProp.apply(prms)
}
resultStream.takeWhile(prop => (!prop.success && System.currentTimeMillis() < startTime + maximumMs) || atLeastOnce.getAndSet(false)).last
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment