While not the source of your problems, your test configuration has a few race conditions which you should take care of before they cause problems. Always check for issues with the
-race option. You should also let the OS allocate the port so you don't run into conflicts. See for example how
Your failure here is that you're not creating a new
rpc.Server for each test, you're reusing the
rpc.DefaultServer. The first call to
CreateRPCServer registers a
TestAPI under the name
TestMaster. Each subsequent call uses the already registered instance.
If you create a new
rpc.Server each time you setup the test and register a new TestAPI, the final test will pass.
srv := rpc.NewServer() srv.RegisterName("TestMaster", testAPI) ... // and then use srv to handle the new connection srv.ServeCodec(RpcCodecServer(conn))