diff --git a/abci/example/example_test.go b/abci/example/example_test.go index d40976015..71964ce5c 100644 --- a/abci/example/example_test.go +++ b/abci/example/example_test.go @@ -2,7 +2,9 @@ package example import ( "fmt" + "math/rand" "net" + "os" "reflect" "testing" "time" @@ -23,6 +25,10 @@ import ( "github.com/tendermint/tendermint/abci/types" ) +func init() { + rand.Seed(time.Now().UnixNano()) +} + func TestKVStore(t *testing.T) { fmt.Println("### Testing KVStore") testStream(t, kvstore.NewApplication()) @@ -40,9 +46,12 @@ func TestGRPC(t *testing.T) { func testStream(t *testing.T, app types.Application) { numDeliverTxs := 20000 + socketFile := fmt.Sprintf("test-%08x.sock", rand.Int31n(1<<30)) + defer os.Remove(socketFile) + socket := fmt.Sprintf("unix://%v", socketFile) // Start the listener - server := abciserver.NewSocketServer("unix://test.sock", app) + server := abciserver.NewSocketServer(socket, app) server.SetLogger(log.TestingLogger().With("module", "abci-server")) if err := server.Start(); err != nil { require.NoError(t, err, "Error starting socket server") @@ -50,7 +59,7 @@ func testStream(t *testing.T, app types.Application) { defer server.Stop() // Connect to the socket - client := abcicli.NewSocketClient("unix://test.sock", false) + client := abcicli.NewSocketClient(socket, false) client.SetLogger(log.TestingLogger().With("module", "abci-client")) if err := client.Start(); err != nil { t.Fatalf("Error starting socket client: %v", err.Error()) @@ -113,9 +122,12 @@ func dialerFunc(ctx context.Context, addr string) (net.Conn, error) { func testGRPCSync(t *testing.T, app types.ABCIApplicationServer) { numDeliverTxs := 2000 + socketFile := fmt.Sprintf("test-%08x.sock", rand.Int31n(1<<30)) + defer os.Remove(socketFile) + socket := fmt.Sprintf("unix://%v", socketFile) // Start the listener - server := abciserver.NewGRPCServer("unix://test.sock", app) + server := abciserver.NewGRPCServer(socket, app) server.SetLogger(log.TestingLogger().With("module", "abci-server")) if err := server.Start(); err != nil { t.Fatalf("Error starting GRPC server: %v", err.Error()) @@ -123,7 +135,7 @@ func testGRPCSync(t *testing.T, app types.ABCIApplicationServer) { defer server.Stop() // Connect to the socket - conn, err := grpc.Dial("unix://test.sock", grpc.WithInsecure(), grpc.WithContextDialer(dialerFunc)) + conn, err := grpc.Dial(socket, grpc.WithInsecure(), grpc.WithContextDialer(dialerFunc)) if err != nil { t.Fatalf("Error dialing GRPC server: %v", err.Error()) }