Remove a test with race condition in ClusterSpec, #30743 (#30758)

This commit is contained in:
Patrik Nordwall 2021-10-07 15:48:44 +02:00 committed by GitHub
parent 5da7dc6c19
commit e0db5f4e64
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 4 additions and 7 deletions

View file

@ -406,7 +406,8 @@ class Cluster(val system: ExtendedActorSystem) extends Extension {
/**
* The supplied thunk will be run, once, when current cluster member is `Removed`.
* If the cluster has already been shutdown the thunk will run on the caller thread immediately.
* Typically used together `cluster.leave(cluster.selfAddress)` and then `system.terminate()`.
* If this is called "at the same time" as `shutdown()` there is a possibility that the the thunk
* is not invoked. It's often better to use [[akka.actor.CoordinatedShutdown]] for this purpose.
*/
def registerOnMemberRemoved[T](code: => T): Unit =
registerOnMemberRemoved(new Runnable { override def run(): Unit = code })
@ -414,7 +415,8 @@ class Cluster(val system: ExtendedActorSystem) extends Extension {
/**
* Java API: The supplied thunk will be run, once, when current cluster member is `Removed`.
* If the cluster has already been shutdown the thunk will run on the caller thread immediately.
* Typically used together `cluster.leave(cluster.selfAddress)` and then `system.terminate()`.
* If this is called "at the same time" as `shutdown()` there is a possibility that the the thunk
* is not invoked. It's often better to use [[akka.actor.CoordinatedShutdown]] for this purpose.
*/
def registerOnMemberRemoved(callback: Runnable): Unit = {
if (_isTerminated.get())

View file

@ -137,17 +137,12 @@ class ClusterSpec extends AkkaSpec(ClusterSpec.config) with ImplicitSender {
// this should be the last test step, since the cluster is shutdown
"publish MemberRemoved when shutdown" in {
val callbackProbe = TestProbe()
cluster.registerOnMemberRemoved(callbackProbe.ref ! "OnMemberRemoved")
cluster.subscribe(testActor, classOf[ClusterEvent.MemberRemoved])
// first, is in response to the subscription
expectMsgClass(classOf[ClusterEvent.CurrentClusterState])
cluster.shutdown()
expectMsgType[ClusterEvent.MemberRemoved].member.address should ===(selfAddress)
callbackProbe.expectMsg("OnMemberRemoved")
}
"allow join and leave with local address" in {