finish EventFilter work and apply in three places

- fix memory visibility issue with occurrences counter
- add non-throwing awaitCond and use that for better error reporting
- move occurrence book-keeping (side-effect) out of PF guard, was
  evaluated multiple times (of course!)
- apply in cases where EventFilter.custom was used (one legitimate use
  case remains)
This commit is contained in:
Roland 2011-11-09 11:04:39 +01:00
parent c1a9475015
commit b3249e0adb
4 changed files with 68 additions and 67 deletions

View file

@ -559,19 +559,24 @@ object TestKit {
*
* Note that the timeout is scaled using Duration.timeFactor.
*/
def awaitCond(p: Boolean, max: Duration, interval: Duration = 100.millis) {
def awaitCond(p: Boolean, max: Duration, interval: Duration = 100.millis, noThrow: Boolean = false): Boolean = {
val stop = now + max
@tailrec
def poll(t: Duration) {
def poll(): Boolean = {
if (!p) {
assert(now < stop, "timeout " + max + " expired")
Thread.sleep(t.toMillis)
poll((stop - now) min interval)
}
val toSleep = stop - now
if (toSleep <= Duration.Zero) {
if (noThrow) false
else throw new AssertionError("timeout " + max + " expired")
} else {
Thread.sleep((toSleep min interval).toMillis)
poll()
}
} else true
}
poll(max min interval)
poll()
}
/**