From 9afc27994cb613a46c3d040742b3ea83665c9989 Mon Sep 17 00:00:00 2001 From: Jasmina Malicevic Date: Tue, 20 Feb 2024 09:22:09 +0100 Subject: [PATCH] fix(e2e): Reduce flakiness of TestGRPC_GetBlockResults (#2367) The test is failing often due to the fact that it asks for the first block via RPC Status then waits to be notified about the latest height via gRPC and then requests block results at the first and last heights. If pruning is happening fast enough, there is a high chance the results will be pruned at the time of asking. This fix is not making the behaviour fully deterministic but increases the chances the block is still around because it sets the first height to be the last reported first height + retain blocks. --- #### PR checklist - [ ] Tests written/updated - [ ] Changelog entry added in `.changelog` (we use [unclog](https://github.com/informalsystems/unclog) to manage our changelog) - [ ] Updated relevant documentation (`docs/` or `spec/`) and code comments - [ ] Title follows the [Conventional Commits](https://www.conventionalcommits.org/en/v1.0.0/) spec (cherry picked from commit 2c6e0c160da65cc8eece50cea4cc25043365b85f) --- test/e2e/tests/block_test.go | 8 +++++++- test/e2e/tests/grpc_test.go | 10 ++++++++-- test/e2e/tests/validator_test.go | 8 +++++++- 3 files changed, 22 insertions(+), 4 deletions(-) diff --git a/test/e2e/tests/block_test.go b/test/e2e/tests/block_test.go index 14741a35c9d..3c1c52675ad 100644 --- a/test/e2e/tests/block_test.go +++ b/test/e2e/tests/block_test.go @@ -27,7 +27,13 @@ func TestBlock_Header(t *testing.T) { first := status.SyncInfo.EarliestBlockHeight last := status.SyncInfo.LatestBlockHeight if node.RetainBlocks > 0 { - first++ // avoid race conditions with block pruning + // This was done in case pruning is activated. + // As it happens in the background this lowers the chances + // that the block at height=first will be pruned by the time we test + // this. If this test starts to fail often, it is worth revisiting this logic. + // To reproduce this failure locally, it is advised to set the storage.pruning.interval + // to 1s instead of 10s. + first += int64(node.RetainBlocks) // avoid race conditions with block pruning } for _, block := range blocks { diff --git a/test/e2e/tests/grpc_test.go b/test/e2e/tests/grpc_test.go index cb797876165..5be0b1c7620 100644 --- a/test/e2e/tests/grpc_test.go +++ b/test/e2e/tests/grpc_test.go @@ -106,7 +106,13 @@ func TestGRPC_GetBlockResults(t *testing.T) { first := status.SyncInfo.EarliestBlockHeight last := status.SyncInfo.LatestBlockHeight if node.RetainBlocks > 0 { - first++ + // This was done in case pruning is activated. + // As it happens in the background this lowers the chances + // that the block at height=first will be pruned by the time we test + // this. If this test starts to fail often, it is worth revisiting this logic. + // To reproduce this failure locally, it is advised to set the storage.pruning.interval + // to 1s instead of 10s. + first += int64(node.RetainBlocks) } ctx, ctxCancel := context.WithTimeout(context.Background(), time.Minute) @@ -136,7 +142,7 @@ func TestGRPC_GetBlockResults(t *testing.T) { errorCases := []struct { requestHeight int64 }{ - {first - 2}, + {first - int64(node.RetainBlocks) - 2}, {last + 100000}, } diff --git a/test/e2e/tests/validator_test.go b/test/e2e/tests/validator_test.go index 1d75bc20060..3b7887b03cf 100644 --- a/test/e2e/tests/validator_test.go +++ b/test/e2e/tests/validator_test.go @@ -30,7 +30,13 @@ func TestValidator_Sets(t *testing.T) { // skip first block if node is pruning blocks, to avoid race conditions if node.RetainBlocks > 0 { - first++ + // This was done in case pruning is activated. + // As it happens in the background this lowers the chances + // that the block at height=first will be pruned by the time we test + // this. If this test starts to fail often, it is worth revisiting this logic. + // To reproduce this failure locally, it is advised to set the storage.pruning.interval + // to 1s instead of 10s. + first += int64(node.RetainBlocks) } valSchedule := newValidatorSchedule(*node.Testnet)