Shutting down the LARS test driver too early might fail one of the tests. See #3005

This commit is contained in:
Björn Antonsson 2013-02-05 16:28:30 +01:00
parent fb69f33dd1
commit 01b8f68be4

View file

@ -443,7 +443,7 @@ class LightArrayRevolverSchedulerSpec extends AkkaSpec(SchedulerSpec.testConfRev
withScheduler() { (sched, driver)
import system.dispatcher
val counter = new AtomicInteger
future { Thread.sleep(5); sched.close() }
future { Thread.sleep(5); driver.close(); sched.close() }
val headroom = 200
var overrun = headroom
val cap = 1000000
@ -466,6 +466,7 @@ class LightArrayRevolverSchedulerSpec extends AkkaSpec(SchedulerSpec.testConfRev
def expectWait(d: FiniteDuration) { expectWait() must be(d) }
def probe: TestProbe
def step: FiniteDuration
def close(): Unit
}
val localEC = new ExecutionContext {
@ -489,22 +490,12 @@ class LightArrayRevolverSchedulerSpec extends AkkaSpec(SchedulerSpec.testConfRev
prb.ref ! ns
try time += (lbq.get match {
case q: LinkedBlockingQueue[Long] q.take()
case _
val start = System.nanoTime()
super.waitNanos(ns)
System.nanoTime() - start
case _ 0L
})
catch {
case _: InterruptedException Thread.currentThread.interrupt()
}
}
override def close(): Unit = {
lbq.getAndSet(null) match {
case q: LinkedBlockingQueue[Long] q.offer(0L)
case _
}
super.close()
}
}
val driver = new Driver {
def wakeUp(d: FiniteDuration) = lbq.get match {
@ -514,15 +505,22 @@ class LightArrayRevolverSchedulerSpec extends AkkaSpec(SchedulerSpec.testConfRev
def expectWait(): FiniteDuration = probe.expectMsgType[Long].nanos
def probe = prb
def step = sched.TickDuration
def close() = lbq.getAndSet(null) match {
case q: LinkedBlockingQueue[Long] q.offer(0L)
case _
}
}
driver.expectWait()
try thunk(sched, driver)
catch {
case NonFatal(ex)
try sched.close()
catch { case _: Exception }
try {
driver.close()
sched.close()
} catch { case _: Exception }
throw ex
}
driver.close()
sched.close()
}