Execute post stop for guardian behaviors

Fixes #28557
This commit is contained in:
Christopher Batey 2020-02-04 09:53:01 +00:00
parent 918b556b0a
commit d84266e357
2 changed files with 33 additions and 1 deletions

View file

@ -29,5 +29,36 @@ final class OnSignalSpec extends ScalaTestWithActorTestKit with AnyWordSpecLike
spawn[Nothing](behavior)
probe.expectMessage(Done)
}
def stopper(probe: TestProbe[Done]) = Behaviors
.receiveMessage[String] {
case "stop" =>
println("Stopping")
Behaviors.stopped
}
.receiveSignal {
case (_, PostStop) =>
println("Post stop called")
probe.ref ! Done
Behaviors.same
}
"execute post stop" in {
val probe = createTestProbe[Done]("post-stop-child")
val stopperRef = spawn(stopper(probe))
stopperRef ! "stop"
probe.expectMessage(Done)
}
"post stop for guardian behavior" in {
val probe = createTestProbe[Done]("post-stop-probe")
val system = ActorSystem(stopper(probe), "work")
try {
system ! "stop"
probe.expectMessage(Done)
} finally {
system.terminate()
}
}
}
}

View file

@ -73,7 +73,8 @@ private[akka] object GuardianStartupBehavior {
next
else {
ctx.asScala.system.terminate()
Behaviors.ignore
// return next so that the adapter can call post stop on the previous behavior
next
}
}
}