Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -524,7 +524,7 @@ func (s *BackendExecutionDataSuite) subscribe(subscribeFunc func(ctx context.Con

assert.Equal(s.T(), b.Height, resp.Height)
assert.Equal(s.T(), execData.BlockExecutionData, resp.ExecutionData)
}, time.Second, fmt.Sprintf("timed out waiting for exec data for block %d %v", b.Height, b.ID()))
}, 10*time.Second, fmt.Sprintf("timed out waiting for exec data for block %d %v", b.Height, b.ID()))
}

// make sure there are no new messages waiting. the channel should be opened with nothing waiting
Expand Down
6 changes: 3 additions & 3 deletions engine/access/state_stream/backend/handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ func (s *HandlerTestSuite) TestHeartbeatResponse() {
require.NoError(s.T(), err)
require.Equal(s.T(), b.ID(), blockID)
require.Equal(s.T(), b.Height, resp.BlockHeight)
}, time.Second, fmt.Sprintf("timed out waiting for exec data for block %d %v", b.Height, b.ID()))
}, 10*time.Second, fmt.Sprintf("timed out waiting for exec data for block %d %v", b.Height, b.ID()))
}
})

Expand Down Expand Up @@ -146,7 +146,7 @@ func (s *HandlerTestSuite) TestHeartbeatResponse() {
require.NoError(s.T(), err)
require.Equal(s.T(), b.ID(), blockID)
require.Equal(s.T(), b.Height, resp.BlockHeight)
}, time.Second, fmt.Sprintf("timed out waiting for exec data for block %d %v", b.Height, b.ID()))
}, 10*time.Second, fmt.Sprintf("timed out waiting for exec data for block %d %v", b.Height, b.ID()))
}
})

Expand Down Expand Up @@ -192,7 +192,7 @@ func (s *HandlerTestSuite) TestHeartbeatResponse() {
require.Equal(s.T(), b.Height, resp.BlockHeight)
require.Equal(s.T(), b.ID(), blockID)
require.Empty(s.T(), resp.Events)
}, time.Second, fmt.Sprintf("timed out waiting for exec data for block %d %v", b.Height, b.ID()))
}, 10*time.Second, fmt.Sprintf("timed out waiting for exec data for block %d %v", b.Height, b.ID()))
}
})
}
Expand Down
11 changes: 7 additions & 4 deletions engine/verification/fetcher/chunkconsumer/consumer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,9 @@ func TestProduceConsume(t *testing.T) {
<-consumer.Done()

// expect the mock engine receive only the first 3 calls (since it is blocked on those, hence no
// new job is fetched to process).
require.Equal(t, locators[:3], called)
// new job is fetched to process). The 3 concurrent workers append in nondeterministic
// order, so assert the multiset rather than the exact sequence.
require.ElementsMatch(t, locators[:3], called)
})
})

Expand Down Expand Up @@ -91,8 +92,10 @@ func TestProduceConsume(t *testing.T) {

finishAll.Wait() // wait until all 10 jobs are processed and notified
<-consumer.Done()
// expect the mock engine receives all 10 calls
require.Equal(t, locators, called)
// expect the mock engine receives all 10 calls.
// the consumer processes jobs with 3 concurrent workers, so the receive order is
// not deterministic; assert the multiset rather than the exact sequence.
require.ElementsMatch(t, locators, called)
})
})

Expand Down
27 changes: 20 additions & 7 deletions ledger/complete/wal/checkpoint_v6_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,11 +96,22 @@ func randPathPayload() (ledger.Path, ledger.Payload) {
return path, *payload
}

func randNPathPayloads(n int) ([]ledger.Path, []ledger.Payload) {
// randNPathPayloadsUnique returns n random path/payload pairs whose payload keys are unique
// with respect to each other and to the keys already present in `used` (which it updates).
// Tests compare the payloads of the final trie by payload key, so a duplicate key with a
// different value makes the comparison nondeterministic: with 1-byte random keys this
// happens with probability ~1/256 per colliding pair (observed as a rare flake).
func randNPathPayloadsUnique(n int, used map[string]struct{}) ([]ledger.Path, []ledger.Payload) {
paths := make([]ledger.Path, n)
payloads := make([]ledger.Payload, n)
for i := 0; i < n; i++ {
path, payload := randPathPayload()
key := hex.EncodeToString(payload.EncodedKey())
for _, dup := used[key]; dup; _, dup = used[key] {
path, payload = randPathPayload()
key = hex.EncodeToString(payload.EncodedKey())
}
used[key] = struct{}{}
paths[i] = path
payloads[i] = payload
}
Expand All @@ -110,23 +121,24 @@ func randNPathPayloads(n int) ([]ledger.Path, []ledger.Payload) {
func createMultipleRandomTries(t *testing.T) []*trie.MTrie {
tries := make([]*trie.MTrie, 0)
activeTrie := trie.NewEmptyMTrie()
usedKeys := make(map[string]struct{})

var err error
// add tries with no shared paths
for i := 0; i < 100; i++ {
paths, payloads := randNPathPayloads(100)
paths, payloads := randNPathPayloadsUnique(100, usedKeys)
activeTrie, _, err = trie.NewTrieWithUpdatedRegisters(activeTrie, paths, payloads, false)
require.NoError(t, err, "update registers")
tries = append(tries, activeTrie)
}

// add trie with some shared path
sharedPaths, payloads1 := randNPathPayloads(100)
sharedPaths, payloads1 := randNPathPayloadsUnique(100, usedKeys)
activeTrie, _, err = trie.NewTrieWithUpdatedRegisters(activeTrie, sharedPaths, payloads1, false)
require.NoError(t, err, "update registers")
tries = append(tries, activeTrie)

_, payloads2 := randNPathPayloads(100)
_, payloads2 := randNPathPayloadsUnique(100, usedKeys)
activeTrie, _, err = trie.NewTrieWithUpdatedRegisters(activeTrie, sharedPaths, payloads2, false)
require.NoError(t, err, "update registers")
tries = append(tries, activeTrie)
Expand Down Expand Up @@ -156,23 +168,24 @@ func isTrieDeepEnough(trie *trie.MTrie) bool {
func createMultipleRandomTriesMini(t *testing.T) ([]*trie.MTrie, *trie.MTrie) {
tries := make([]*trie.MTrie, 0)
activeTrie := trie.NewEmptyMTrie()
usedKeys := make(map[string]struct{})

var err error
// add tries with no shared paths
for i := 0; i < 5; i++ {
paths, payloads := randNPathPayloads(20)
paths, payloads := randNPathPayloadsUnique(20, usedKeys)
activeTrie, _, err = trie.NewTrieWithUpdatedRegisters(activeTrie, paths, payloads, false)
require.NoError(t, err, "update registers")
tries = append(tries, activeTrie)
}

// add trie with some shared path
sharedPaths, payloads1 := randNPathPayloads(10)
sharedPaths, payloads1 := randNPathPayloadsUnique(10, usedKeys)
activeTrie, _, err = trie.NewTrieWithUpdatedRegisters(activeTrie, sharedPaths, payloads1, false)
require.NoError(t, err, "update registers")
tries = append(tries, activeTrie)

_, payloads2 := randNPathPayloads(10)
_, payloads2 := randNPathPayloadsUnique(10, usedKeys)
activeTrie, _, err = trie.NewTrieWithUpdatedRegisters(activeTrie, sharedPaths, payloads2, false)
require.NoError(t, err, "update registers")
tries = append(tries, activeTrie)
Expand Down
16 changes: 10 additions & 6 deletions network/alsp/manager/manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -416,12 +416,16 @@ func TestHandleReportedMisbehavior_And_DisallowListing_RepeatOffender_Integratio

penalty1 := record.Penalty

// wait for one heartbeat to be processed.
time.Sleep(1 * time.Second)

record, ok = victimSpamRecordCache.Get(ids[spammerIndex].NodeID)
require.True(t, ok)
require.NotNil(t, record)
// wait for one heartbeat to be processed: poll for the first penalty change instead of
// sleeping exactly one heartbeat interval. A fixed 1s sleep races the 1s heartbeat ticker
// (which can be delayed under load) and may span 0 or 2 decays; polling at 10ms granularity
// reliably catches the state after exactly one decay.
require.Eventually(t, func() bool {
record, ok = victimSpamRecordCache.Get(ids[spammerIndex].NodeID)
require.True(t, ok)
require.NotNil(t, record)
return record.Penalty != penalty1
}, 10*time.Second, 10*time.Millisecond, "penalty did not decay after one heartbeat")

// check the penalty of the spammer node, which should be below the disallow-listing threshold.
// i.e. spammer penalty should be more negative than the disallow-listing threshold, hence disallow-listed.
Expand Down
Loading