From a016747b1f0ae26156f63bb9a1132f1beb9970bc Mon Sep 17 00:00:00 2001 From: "Masih H. Derkani" Date: Fri, 1 Mar 2024 17:19:50 +0000 Subject: [PATCH] Use fixed RNG seed for actor event tests Improve determinism in actor event tests by using a fixed RNG seed. This makes up a more reproducible test suit. --- node/impl/full/actor_events_test.go | 49 ++++++++++++++--------------- 1 file changed, 24 insertions(+), 25 deletions(-) diff --git a/node/impl/full/actor_events_test.go b/node/impl/full/actor_events_test.go index 9fb858651..a8743783c 100644 --- a/node/impl/full/actor_events_test.go +++ b/node/impl/full/actor_events_test.go @@ -24,11 +24,6 @@ import ( var testCid = cid.MustParse("bafyreicmaj5hhoy5mgqvamfhgexxyergw7hdeshizghodwkjg6qmpoco7i") func TestParseHeightRange(t *testing.T) { - epochPtr := func(i int) *abi.ChainEpoch { - e := abi.ChainEpoch(i) - return &e - } - testCases := []struct { name string heaviest abi.ChainEpoch @@ -139,10 +134,13 @@ func TestGetActorEvents(t *testing.T) { ctx := context.Background() req := require.New(t) - seed := time.Now().UnixNano() + const ( + seed = 984651320 + maxFilterHeightRange = 100 + ) + t.Logf("seed: %d", seed) rng := pseudo.New(pseudo.NewSource(seed)) - const maxFilterHeightRange = 100 minerAddr, err := address.NewIDAddress(uint64(rng.Int63())) req.NoError(err) @@ -250,18 +248,19 @@ func TestSubscribeActorEvents(t *testing.T) { ctx, cancel := context.WithTimeout(context.Background(), 3*time.Second) defer cancel() - seed := time.Now().UnixNano() + const ( + seed = 984651320 + maxFilterHeightRange = 100 + blockDelay = 30 * time.Second + filterStartHeight = 0 + currentHeight = 10 + finishHeight = 20 + eventsPerEpoch = 2 + ) t.Logf("seed: %d", seed) rng := pseudo.New(pseudo.NewSource(seed)) mockClock := clock.NewMock() - const maxFilterHeightRange = 100 - const blockDelay = 30 * time.Second - const filterStartHeight = 0 - const currentHeight = 10 - const finishHeight = 20 - const eventsPerEpoch = 2 - minerAddr, err := address.NewIDAddress(uint64(rng.Int63())) require.NoError(t, err) @@ -415,18 +414,18 @@ func TestSubscribeActorEvents_OnlyHistorical(t *testing.T) { // Similar to TestSubscribeActorEvents but we set an explicit end that caps out at the current height ctx, cancel := context.WithTimeout(context.Background(), 3*time.Second) defer cancel() - - seed := time.Now().UnixNano() + const ( + seed = 984651320 + maxFilterHeightRange = 100 + blockDelay = 30 * time.Second + filterStartHeight = 0 + currentHeight = 10 + eventsPerEpoch = 2 + ) t.Logf("seed: %d", seed) rng := pseudo.New(pseudo.NewSource(seed)) mockClock := clock.NewMock() - const maxFilterHeightRange = 100 - const blockDelay = 30 * time.Second - const filterStartHeight = 0 - const currentHeight = 10 - const eventsPerEpoch = 2 - minerAddr, err := address.NewIDAddress(uint64(rng.Int63())) require.NoError(t, err) @@ -602,14 +601,14 @@ func (m *mockFilter) ClearSubChannel() { m.ch = nil } -func (m *mockFilter) TakeCollectedEvents(ctx context.Context) []*filter.CollectedEvent { +func (m *mockFilter) TakeCollectedEvents(context.Context) []*filter.CollectedEvent { e := m.historicalEvents m.historicalEvents = nil m.lastTaken = time.Now() return e } -func (m *mockFilter) CollectEvents(ctx context.Context, tse *filter.TipSetEvents, reorg bool, ar filter.AddressResolver) error { +func (m *mockFilter) CollectEvents(context.Context, *filter.TipSetEvents, bool, filter.AddressResolver) error { m.t.Fatalf("unexpected call to CollectEvents") return nil }