Skip to content

Commit 5a391f8

Browse files
authored
network/stream/v2: more resilient TestNodesExchangeCorrectBinIndexes (ethersphere#1760)
1 parent 5824b64 commit 5a391f8

File tree

1 file changed

+23
-15
lines changed

1 file changed

+23
-15
lines changed

network/stream/v2/cursors_test.go

Lines changed: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -68,31 +68,39 @@ func TestNodesExchangeCorrectBinIndexes(t *testing.T) {
6868
t.Fatal(err)
6969
}
7070

71-
result := sim.Run(ctx, func(ctx context.Context, sim *simulation.Simulation) error {
71+
result := sim.Run(ctx, func(ctx context.Context, sim *simulation.Simulation) (err error) {
7272
nodeIDs := sim.UpNodeIDs()
7373
if len(nodeIDs) != nodeCount {
7474
return errors.New("not enough nodes up")
7575
}
7676

77-
// wait for the nodes to exchange StreamInfo messages
78-
time.Sleep(100 * time.Millisecond)
77+
// periodically check for cursors
78+
for i := 0; i < 100; i++ {
79+
// wait for the nodes to exchange StreamInfo messages
80+
time.Sleep(10 * time.Millisecond)
7981

80-
idOne := nodeIDs[0]
81-
idOther := nodeIDs[1]
82-
onesCursors := nodeRegistry(sim, idOne).getPeer(idOther).getCursorsCopy()
83-
othersCursors := nodeRegistry(sim, idOther).getPeer(idOne).getCursorsCopy()
82+
idOne := nodeIDs[0]
83+
idOther := nodeIDs[1]
84+
onesCursors := nodeRegistry(sim, idOne).getPeer(idOther).getCursorsCopy()
85+
othersCursors := nodeRegistry(sim, idOther).getPeer(idOne).getCursorsCopy()
8486

85-
onesBins := nodeInitialBinIndexes(sim, idOne)
86-
othersBins := nodeInitialBinIndexes(sim, idOther)
87+
onesBins := nodeInitialBinIndexes(sim, idOne)
88+
othersBins := nodeInitialBinIndexes(sim, idOther)
8789

88-
if err := compareNodeBinsToStreams(t, onesCursors, othersBins); err != nil {
89-
return err
90-
}
91-
if err := compareNodeBinsToStreams(t, othersCursors, onesBins); err != nil {
92-
return err
90+
err1 := compareNodeBinsToStreams(t, onesCursors, othersBins)
91+
if err1 != nil {
92+
err = err1 // set the resulting error when the loop is done
93+
}
94+
err2 := compareNodeBinsToStreams(t, othersCursors, onesBins)
95+
if err2 != nil {
96+
err = err2 // set the resulting error when the loop is done
97+
}
98+
if err1 == nil && err2 == nil {
99+
return nil
100+
}
93101
}
94102

95-
return nil
103+
return err
96104
})
97105
if result.Error != nil {
98106
t.Fatal(result.Error)

0 commit comments

Comments
 (0)