Skip to content

Commit

Permalink
Remove race condition from timeout test and add explicit state check
Browse files Browse the repository at this point in the history
  • Loading branch information
Michael Zalimeni committed Jan 13, 2015
1 parent 92466c3 commit 7f41856
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ class ParrotFeeder(config: ParrotFeederConfig) extends Service {
private[this] val log = Logger.get(getClass.getName)
val requestsRead = new AtomicLong(0)
@volatile
private[this] var state = FeederState.RUNNING
protected[this] var state = FeederState.RUNNING

private[this] val initializedParrots = mutable.Set[RemoteParrot]()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,9 +123,11 @@ class EndToEndSpec extends WordSpec with MustMatchers with FeederFixture {
feederConfig.batchSize = 3

val feederDone = Promise[Unit]
var feederState = FeederState.RUNNING
val feeder = new ParrotFeeder(feederConfig) {
override def shutdown() = {
feederDone.setDone() // give this test ability to wait on shutdown call to test for timeout
feederDone.setDone() // give this test ability to wait on shutdown call
feederState = state // capture state at beginning of shutdown call
super.shutdown()
}
}
Expand All @@ -136,8 +138,7 @@ class EndToEndSpec extends WordSpec with MustMatchers with FeederFixture {
case e: TimeoutException =>
fail(String.format("Server did not time out in %s", PrettyDuration(secondsToRun.seconds)))
}
val (requestsRead, allRequests, rp) = report(feeder, transport, serverConfig)
allRequests must be <= expectedRequests + 1 // allow for small margin due to race condition
feederState must be === FeederState.TIMEOUT
}

"honor the max request limit" in {
Expand Down

0 comments on commit 7f41856

Please sign in to comment.