I am using Akka Testkit in a project, and I’ve always used expectNoMsg() with the default timeout of three seconds. However, another developer says that we should be using expectNoMsg(0.seconds) instead so that our tests don’t take longer and longer to run as we add more of these asserts. I agree with the goal but am unsure about whether it’s safe to use a 0 second timeout.
The rational about using 0 seconds is that since we are invoking expectNoMsg on a TestActorRef, and the ! function to/in a TestActorRef is a synchronous operation, waiting for 0 seconds is enough. I tested with a couple of my test cases and found that the tests did fail if an unexpected message is sent. But is that reliable? Should we adopt “expectNoMsg(0.seconds)” as a testing best practice?
Please let me know if there are any subtleties or caveats to be aware of.