|
@ -2,7 +2,9 @@ package example |
|
|
|
|
|
|
|
|
import ( |
|
|
import ( |
|
|
"fmt" |
|
|
"fmt" |
|
|
|
|
|
"math/rand" |
|
|
"net" |
|
|
"net" |
|
|
|
|
|
"os" |
|
|
"reflect" |
|
|
"reflect" |
|
|
"testing" |
|
|
"testing" |
|
|
"time" |
|
|
"time" |
|
@ -23,6 +25,10 @@ import ( |
|
|
"github.com/tendermint/tendermint/abci/types" |
|
|
"github.com/tendermint/tendermint/abci/types" |
|
|
) |
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
func init() { |
|
|
|
|
|
rand.Seed(time.Now().UnixNano()) |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
func TestKVStore(t *testing.T) { |
|
|
func TestKVStore(t *testing.T) { |
|
|
fmt.Println("### Testing KVStore") |
|
|
fmt.Println("### Testing KVStore") |
|
|
testStream(t, kvstore.NewApplication()) |
|
|
testStream(t, kvstore.NewApplication()) |
|
@ -40,9 +46,12 @@ func TestGRPC(t *testing.T) { |
|
|
|
|
|
|
|
|
func testStream(t *testing.T, app types.Application) { |
|
|
func testStream(t *testing.T, app types.Application) { |
|
|
numDeliverTxs := 20000 |
|
|
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
|
|
|
// Start the listener
|
|
|
server := abciserver.NewSocketServer("unix://test.sock", app) |
|
|
|
|
|
|
|
|
server := abciserver.NewSocketServer(socket, app) |
|
|
server.SetLogger(log.TestingLogger().With("module", "abci-server")) |
|
|
server.SetLogger(log.TestingLogger().With("module", "abci-server")) |
|
|
if err := server.Start(); err != nil { |
|
|
if err := server.Start(); err != nil { |
|
|
require.NoError(t, err, "Error starting socket server") |
|
|
require.NoError(t, err, "Error starting socket server") |
|
@ -50,7 +59,7 @@ func testStream(t *testing.T, app types.Application) { |
|
|
defer server.Stop() |
|
|
defer server.Stop() |
|
|
|
|
|
|
|
|
// Connect to the socket
|
|
|
// Connect to the socket
|
|
|
client := abcicli.NewSocketClient("unix://test.sock", false) |
|
|
|
|
|
|
|
|
client := abcicli.NewSocketClient(socket, false) |
|
|
client.SetLogger(log.TestingLogger().With("module", "abci-client")) |
|
|
client.SetLogger(log.TestingLogger().With("module", "abci-client")) |
|
|
if err := client.Start(); err != nil { |
|
|
if err := client.Start(); err != nil { |
|
|
t.Fatalf("Error starting socket client: %v", err.Error()) |
|
|
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) { |
|
|
func testGRPCSync(t *testing.T, app types.ABCIApplicationServer) { |
|
|
numDeliverTxs := 2000 |
|
|
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
|
|
|
// Start the listener
|
|
|
server := abciserver.NewGRPCServer("unix://test.sock", app) |
|
|
|
|
|
|
|
|
server := abciserver.NewGRPCServer(socket, app) |
|
|
server.SetLogger(log.TestingLogger().With("module", "abci-server")) |
|
|
server.SetLogger(log.TestingLogger().With("module", "abci-server")) |
|
|
if err := server.Start(); err != nil { |
|
|
if err := server.Start(); err != nil { |
|
|
t.Fatalf("Error starting GRPC server: %v", err.Error()) |
|
|
t.Fatalf("Error starting GRPC server: %v", err.Error()) |
|
@ -123,7 +135,7 @@ func testGRPCSync(t *testing.T, app types.ABCIApplicationServer) { |
|
|
defer server.Stop() |
|
|
defer server.Stop() |
|
|
|
|
|
|
|
|
// Connect to the socket
|
|
|
// 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 { |
|
|
if err != nil { |
|
|
t.Fatalf("Error dialing GRPC server: %v", err.Error()) |
|
|
t.Fatalf("Error dialing GRPC server: %v", err.Error()) |
|
|
} |
|
|
} |
|
|