Before doing a transaction this test steps down the primary node and waits until it becomes secondary, however, the router might not find out about that election so the following transaction fails with a noMaster error.
The test should wait until the mongos finds a primary, something like this test