Hi, I am trying to find the best way to isolate msg expectations when testing. I started having issues with messages for one test are making an other test (in the same scala-test class) fail, especially since I started using akka cluster and broadcasting via DistributedPubSubExtension.
I always create new instances of my actors. But since they use the same system (via TestKit) I get this problem where the first test succeeds bit subsequent tests fail because of (currently) SubscribeAck message.
One way ofcourse would be to reset the actor system for each test, but it doesn't seem to be supported by TestKit.
This is my base test class:
class BaseActorSuite(config: Config = ConfigFactory.empty) extends TestKit(ActorSystem("testSystem", config)) with ImplicitSender with FunSuiteLike with Matchers with BeforeAndAfterAll
{
    override def afterAll {
        TestKit.shutdownActorSystem(system)
    }
}
And this is how I do testing:
class ClusterKeeperActorTest extends BaseActorSuite(ConfigFactory.load("org/distributedrange/cluster/actors/ClusterKeeperActorTest.conf")) with MockitoSugar
{
    // simulate a remote cluster keeper
    def remoteClusterKeeperActor = {
        val remote = TestProbe()
        val mediator = DistributedPubSubExtension(system).mediator
        mediator ! Subscribe(ClusterKeeperActor.Subscriptions.Index, remote.ref)
        remote
    }
    def newActor = system.actorOf(Props(new ClusterKeeperActor))
    test("sends SyncIndex to remote cluster keepers") {
        val clusterKeeper = newActor
        val remoteClusterKeeper = remoteClusterKeeperActor
        val rangeRef = RangeRef("id", IntKey.min, IntKey.max, testActor)
        clusterKeeper ! SyncIndex(rangeRef)
        remoteClusterKeeper.expectMsg(RemoteSyncIndex(rangeRef))
    }
    test("keeps track of new members") {
        val clusterKeeper = newActor
        val m1 = mockMember
        val m2 = mockMember
        clusterKeeper ! MemberUp(m1)
        clusterKeeper ! MemberUp(m2)
        clusterKeeper ! messages.AllMembers
        expectMsg(Set(m1, m2))
    }
}
"keeps track of new members" runs fine if I comment out the 1st test, but fails otherwise with 
java.lang.AssertionError: assertion failed: expected Set(Mock for Member, hashCode: 405006382, Mock for Member, hashCode: 1566584931), found SubscribeAck(Subscribe(index,None,Actor[akka://testSystem/system/testActor2#640267634]))
As you can see, the SubscribeAck comes from the 1st test.
Ideas? Is there a way say to reset the mailboxes in-between tests?
Thanks