The test should make sure the set is healthy, with a primary (and all other nodes are up) before adding roles/users.
var rstest = new ReplSetTest({name: name, nodes: 1, nodeOptions: {}}); rstest.startSet(); rstest.initiate(); m0 = rstest.nodes[0]; ... rstest.add(); rstest.reInitiate(); rstest.getPrimary().getDB("db1").createRole({...
After the reInitiate call m0 might no longer be primary, or be stepping down. There should be a write(w:2)/await or something to ensure that the set has a primary is healthy (all members).