Github user BryanCutler commented on a diff in the pull request: https://github.com/apache/spark/pull/6205#discussion_r32291362 --- Diff: core/src/test/scala/org/apache/spark/rpc/akka/AkkaRpcEnvSuite.scala --- @@ -47,4 +56,60 @@ class AkkaRpcEnvSuite extends RpcEnvSuite { } } + test("timeout on ask Future with RpcTimeout") { + + class EchoActor(sleepDuration: Long) extends Actor { + def receive: Receive = { + case msg => + Thread.sleep(sleepDuration) + sender() ! msg + } + } + + val system = ActorSystem("EchoSystem") + val echoActor = system.actorOf(Props(new EchoActor(0)), name = "echo") + val sleepyActor = system.actorOf(Props(new EchoActor(50)), name = "sleepy") + + val shortProp = "spark.rpc.short.timeout" + val timeout = new RpcTimeout(10 millis, shortProp) + + try { + + // Ask with immediate response + var fut = echoActor.ask("hello")(timeout.duration).mapTo[String]. + recover(timeout.addMessageIfTimeout) + + // This should complete successfully + val result = timeout.awaitResult(fut) + + assert(result.nonEmpty) + + // Ask with delayed response + fut = sleepyActor.ask("goodbye")(timeout.duration).mapTo[String]. + recover(timeout.addMessageIfTimeout) + + // Allow future to complete with failure using plain Await.result, this will return + // once the future is complete + val msg1 = + intercept[RpcTimeoutException] { + Await.result(fut, 200 millis) + }.getMessage() + + assert(msg1.contains(shortProp)) + + // Use RpcTimeout.awaitResult to process Future, since it has already failed with + // RpcTimeoutException, the same exception should be thrown + val msg2 = + intercept[RpcTimeoutException] { + timeout.awaitResult(fut) + }.getMessage() --- End diff -- done
--- If your project is set up for it, you can reply to this email and have your reply appear on GitHub as well. If your project does not have this feature enabled and wishes so, or if the feature is enabled but not working, please contact infrastructure at infrastruct...@apache.org or file a JIRA ticket with INFRA. --- --------------------------------------------------------------------- To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org For additional commands, e-mail: reviews-h...@spark.apache.org