Permalink
Browse files

release connection after getting the response if the connection has e…

…xpired
  • Loading branch information...
1 parent eefb143 commit a2d0b26b4a9169de242a7771327deea4d265745b Wanli Yang committed Mar 21, 2011
View
8 finagle-core/src/main/scala/com/twitter/finagle/service/ExpiringService.scala
@@ -97,8 +97,12 @@ class ExpiringService[Req, Rep](
requestCount -= 1
if (requestCount == 0) {
require(!idleTimeTask.isDefined)
- maxIdleTime foreach { time =>
- idleTimeTask = Some(timer.schedule(time.fromNow) { maybeIdleExpire() })
+ if (expired) {
+ didExpire()
+ } else {
+ maxIdleTime foreach { time =>
+ idleTimeTask = Some(timer.schedule(time.fromNow) { maybeIdleExpire() })
+ }
}
}
}
View
26 finagle-core/src/test/scala/com/twitter/finagle/service/ExpiringServiceSpec.scala
@@ -146,6 +146,32 @@ object ExpiringServiceSpec extends Specification with Mockito {
there was one(underlying).release()
}
}
+
+ "life timer fires while there are requests" in {
+ val service = new ExpiringService[Any, Any](underlying, Some(10.seconds), Some(5.seconds), timer)
+ timer.tasks must haveSize(2)
+ timer.tasks forall(!_.isCancelled) must beTrue
+
+ "expire after the given life time" in {
+ service(123)
+ timer.tasks must haveSize(1)
+ timer.tasks.head.isCancelled must beFalse
+
+ timeControl.advance(8.seconds)
+ timer.tick()
+
+ timer.tasks must beEmpty
+ service.isAvailable must beFalse
+ there was no(underlying).release()
+
+ promise() = Return(321)
+ timer.tasks must beEmpty
+ service.isAvailable must beFalse
+ there was one(underlying).release()
+
+ service(132)() must throwA[WriteException]
+ }
+ }
}
}
}

0 comments on commit a2d0b26

Please sign in to comment.