fix: proper path when promise actor terminated quickly (#1156)

This commit is contained in:
AndyChen(Jingzhang) 2024-02-28 16:15:01 +08:00 committed by GitHub
parent d884540c92
commit 2fdf7c9e9b
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 24 additions and 1 deletions

View file

@ -266,6 +266,29 @@ class AskSpec extends PekkoSpec("""
val (promiseActorRefForSelection, "ask") = p.expectMsgType[(ActorRef, String)]: @unchecked
promiseActorRefForSelection.path.name should startWith("_user_myName")
}
"proper path when promise actor terminated" in {
implicit val timeout: Timeout = Timeout(300 millis)
val p = TestProbe()
val act = system.actorOf(Props(new Actor {
def receive = {
case _ =>
val senderRef: ActorRef = sender()
senderRef ! "complete"
p.ref ! senderRef
}
}), "pathPrefix")
val f = (act ? "ask").mapTo[String]
val promiseActorRef = p.expectMsgType[ActorRef]: @unchecked
// verify ask complete
val completed = f.futureValue
completed should ===("complete")
// verify path was proper
promiseActorRef.path.toString should include("pathPrefix")
}
}
}

View file

@ -604,7 +604,7 @@ private[pekko] final class PromiseActorRef(
case StoppedWithPath(p) => p
case Stopped =>
// even if we are already stopped we still need to produce a proper path
updateState(Stopped, StoppedWithPath(provider.tempPath()))
updateState(Stopped, StoppedWithPath(provider.tempPath(refPathPrefix)))
path
case Registering => path // spin until registration is completed
case unexpected => throw new IllegalStateException(s"Unexpected state: $unexpected")