From 2b8aa65e4f5ce818a52dd66fa0252f62e5de4fc4 Mon Sep 17 00:00:00 2001 From: Callum Waters Date: Tue, 13 Apr 2021 17:59:15 +0200 Subject: [PATCH] e2e: tx load to use broadcast sync instead of commit (#6347) --- test/e2e/runner/load.go | 20 +++++++++++++------- test/e2e/tests/app_test.go | 17 +++++++++-------- 2 files changed, 22 insertions(+), 15 deletions(-) diff --git a/test/e2e/runner/load.go b/test/e2e/runner/load.go index 151f4511d..adeb9c93b 100644 --- a/test/e2e/runner/load.go +++ b/test/e2e/runner/load.go @@ -14,7 +14,7 @@ import ( ) // Load generates transactions against the network until the given context is -// canceled. A multiplier of great than one can be supplied if load needs to +// canceled. A multiplier of greater than one can be supplied if load needs to // be generated beyond a minimum amount. func Load(ctx context.Context, testnet *e2e.Testnet, multiplier int) error { // Since transactions are executed across all nodes in the network, we need @@ -38,9 +38,9 @@ func Load(ctx context.Context, testnet *e2e.Testnet, multiplier int) error { logger.Info(fmt.Sprintf("Starting transaction load (%v workers)...", concurrency)) started := time.Now() - go loadGenerate(ctx, chTx) + go loadGenerate(ctx, chTx, multiplier) - for w := 0; w < concurrency*multiplier; w++ { + for w := 0; w < concurrency; w++ { go loadProcess(ctx, testnet, chTx, chSuccess) } @@ -66,13 +66,13 @@ func Load(ctx context.Context, testnet *e2e.Testnet, multiplier int) error { } // loadGenerate generates jobs until the context is canceled -func loadGenerate(ctx context.Context, chTx chan<- types.Tx) { +func loadGenerate(ctx context.Context, chTx chan<- types.Tx, multiplier int) { for i := 0; i < math.MaxInt64; i++ { // We keep generating the same 1000 keys over and over, with different values. // This gives a reasonable load without putting too much data in the app. id := i % 1000 - bz := make([]byte, 2048) // 4kb hex-encoded + bz := make([]byte, 1024) // 1kb hex-encoded _, err := rand.Read(bz) if err != nil { panic(fmt.Sprintf("Failed to read random bytes: %v", err)) @@ -81,7 +81,7 @@ func loadGenerate(ctx context.Context, chTx chan<- types.Tx) { select { case chTx <- tx: - time.Sleep(10 * time.Millisecond) + time.Sleep(time.Duration(100/multiplier) * time.Millisecond) case <-ctx.Done(): close(chTx) @@ -107,10 +107,16 @@ func loadProcess(ctx context.Context, testnet *e2e.Testnet, chTx <-chan types.Tx continue } + // check that the node is up + _, err = client.Health(ctx) + if err != nil { + continue + } + clients[node.Name] = client } - if _, err = client.BroadcastTxCommit(ctx, tx); err != nil { + if _, err = client.BroadcastTxSync(ctx, tx); err != nil { continue } diff --git a/test/e2e/tests/app_test.go b/test/e2e/tests/app_test.go index 3fc11351b..d53cf09fb 100644 --- a/test/e2e/tests/app_test.go +++ b/test/e2e/tests/app_test.go @@ -1,6 +1,7 @@ package e2e_test import ( + "bytes" "fmt" "math/rand" "testing" @@ -81,17 +82,17 @@ func TestApp_Tx(t *testing.T) { value := fmt.Sprintf("%x", bz) tx := types.Tx(fmt.Sprintf("%v=%v", key, value)) - resp, err := client.BroadcastTxCommit(ctx, tx) + _, err = client.BroadcastTxSync(ctx, tx) require.NoError(t, err) - // wait for the tx to be persisted in the tx indexer - time.Sleep(500 * time.Millisecond) - hash := tx.Hash() - txResp, err := client.Tx(ctx, hash, false) - require.NoError(t, err) - assert.Equal(t, txResp.Tx, tx) - assert.Equal(t, txResp.Height, resp.Height) + waitTime := 20 * time.Second + require.Eventuallyf(t, func() bool { + txResp, err := client.Tx(ctx, hash, false) + return err == nil && bytes.Equal(txResp.Tx, tx) + }, waitTime, time.Second, + "submitted tx wasn't committed after %v", waitTime, + ) // NOTE: we don't test abci query of the light client if node.Mode == e2e.ModeLight {