Skip to content

Commit c1cddf9

Browse files
authored
Deflake TestNodeStartStop under CI coverage load (#3016)
- bind RPC to a random free port to avoid cross-test port collisions - subscribe to NewBlock before starting the node to avoid missing early events - increase block wait timeout from 10s to 30s for heavily loaded CI - guard cleanup behind successful start to avoid cleanup deadlocks on start failure
1 parent 1e74e66 commit c1cddf9

1 file changed

Lines changed: 16 additions & 8 deletions

File tree

sei-tendermint/node/node_test.go

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ func newLocalNodeService(ctx context.Context, cfg *config.Config, logger log.Log
5454
func TestNodeStartStop(t *testing.T) {
5555
cfg, err := config.ResetTestRoot(t.TempDir(), "node_node_test")
5656
require.NoError(t, err)
57+
cfg.RPC.ListenAddress = "tcp://" + testFreeAddr(t)
5758

5859
ctx := t.Context()
5960

@@ -64,26 +65,33 @@ func TestNodeStartStop(t *testing.T) {
6465

6566
n, ok := ns.(*nodeImpl)
6667
require.True(t, ok)
68+
t.Cleanup(leaktest.CheckTimeout(t, time.Second))
69+
70+
started := false
6771
t.Cleanup(func() {
72+
if !started {
73+
return
74+
}
6875
if n.IsRunning() {
6976
n.Stop()
7077
}
7178
n.Wait()
7279
require.False(t, n.IsRunning(), "node must shut down")
7380
})
74-
t.Cleanup(leaktest.CheckTimeout(t, time.Second))
7581

76-
require.NoError(t, n.Start(ctx))
77-
// wait for the node to produce a block
78-
tctx, cancel := context.WithTimeout(ctx, 10*time.Second)
79-
defer cancel()
80-
81-
blocksSub, err := n.EventBus().SubscribeWithArgs(tctx, pubsub.SubscribeArgs{
82-
ClientID: "node_test",
82+
blocksSub, err := n.EventBus().SubscribeWithArgs(ctx, pubsub.SubscribeArgs{
83+
ClientID: "node_test_start_stop",
8384
Query: types.EventQueryNewBlock,
8485
Limit: 1000,
8586
})
8687
require.NoError(t, err)
88+
89+
require.NoError(t, n.Start(ctx))
90+
started = true
91+
92+
// wait for the node to produce a block
93+
tctx, cancel := context.WithTimeout(ctx, 30*time.Second)
94+
defer cancel()
8795
_, err = blocksSub.Next(tctx)
8896
require.NoError(t, err, "waiting for event")
8997
}

0 commit comments

Comments
 (0)