Browse Source

test/abci: use random socket names to avoid collisions (#4885)

Fixes these test failures:

```
=== RUN   TestKVStore
### Testing KVStore 
I[2020-05-25|13:32:31.303] Starting ABCIServer service                  module=abci-server impl=ABCIServer
    TestKVStore: example_test.go:48: 
                Error Trace:    example_test.go:48
                                                        example_test.go:28
                Error:          Received unexpected error:
                                listen unix test.sock: bind: address already in use
                Test:           TestKVStore
                Messages:       Error starting socket server
--- FAIL: TestKVStore (0.00s) 
```
pull/4890/head
Erik Grinaker 5 years ago
committed by GitHub
parent
commit
0566646373
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 16 additions and 4 deletions
  1. +16
    -4
      abci/example/example_test.go

+ 16
- 4
abci/example/example_test.go View File

@ -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())
}


Loading…
Cancel
Save