Fixed racy test, which was ported from ActorPoolSpec. See #1557

This commit is contained in:
Patrik Nordwall 2012-01-10 17:50:07 +01:00
parent 19845d93e8
commit 0d4763c3b0

View file

@ -155,9 +155,6 @@ class ResizerSpec extends AkkaSpec(ResizerSpec.config) with DefaultTimeout with
// make sure the pool starts at the expected lower limit and grows to the upper as needed // make sure the pool starts at the expected lower limit and grows to the upper as needed
// as influenced by the backlog of blocking pooled actors // as influenced by the backlog of blocking pooled actors
var latch = TestLatch(3)
val count = new AtomicInteger(0)
val resizer = DefaultResizer( val resizer = DefaultResizer(
lowerBound = 2, lowerBound = 2,
upperBound = 4, upperBound = 4,
@ -168,7 +165,7 @@ class ResizerSpec extends AkkaSpec(ResizerSpec.config) with DefaultTimeout with
val router = system.actorOf(Props(new Actor { val router = system.actorOf(Props(new Actor {
def receive = { def receive = {
case n: Int case (n: Int, latch: TestLatch, count: AtomicInteger)
(n millis).dilated.sleep (n millis).dilated.sleep
count.incrementAndGet count.incrementAndGet
latch.countDown() latch.countDown()
@ -180,26 +177,29 @@ class ResizerSpec extends AkkaSpec(ResizerSpec.config) with DefaultTimeout with
Await.result(router ? CurrentRoutees, 5 seconds).asInstanceOf[RouterRoutees].routees.size must be(2) Await.result(router ? CurrentRoutees, 5 seconds).asInstanceOf[RouterRoutees].routees.size must be(2)
def loop(loops: Int, t: Int) = { def loop(loops: Int, t: Int, latch: TestLatch, count: AtomicInteger) = {
latch = TestLatch(loops)
count.set(0) count.set(0)
for (m 0 until loops) { for (m 0 until loops) {
router ! t router.!((t, latch, count))
(10 millis).dilated.sleep (10 millis).dilated.sleep
} }
} }
// 2 more should go thru without triggering more // 2 more should go thru without triggering more
loop(2, 200) val count1 = new AtomicInteger
Await.ready(latch, TestLatch.DefaultTimeout) val latch1 = TestLatch(2)
count.get must be(2) loop(2, 200, latch1, count1)
Await.ready(latch1, TestLatch.DefaultTimeout)
count1.get must be(2)
Await.result(router ? CurrentRoutees, 5 seconds).asInstanceOf[RouterRoutees].routees.size must be(2) Await.result(router ? CurrentRoutees, 5 seconds).asInstanceOf[RouterRoutees].routees.size must be(2)
// a whole bunch should max it out // a whole bunch should max it out
loop(10, 200) val count2 = new AtomicInteger
Await.ready(latch, TestLatch.DefaultTimeout) val latch2 = TestLatch(10)
count.get must be(10) loop(10, 200, latch2, count2)
Await.ready(latch2, TestLatch.DefaultTimeout)
count2.get must be(10)
Await.result(router ? CurrentRoutees, 5 seconds).asInstanceOf[RouterRoutees].routees.size must be(4) Await.result(router ? CurrentRoutees, 5 seconds).asInstanceOf[RouterRoutees].routees.size must be(4)