Browse Source

test: deflake TestAddAndRemoveListenerConcurrency and TestSyncer_SyncAny (#5101)

Fixes #5094.
pull/5099/head
Erik Grinaker 5 years ago
committed by GitHub
parent
commit
bf3c87c864
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 7 additions and 4 deletions
  1. +5
    -4
      libs/events/events_test.go
  2. +2
    -0
      statesync/syncer_test.go

+ 5
- 4
libs/events/events_test.go View File

@ -193,24 +193,25 @@ func TestAddAndRemoveListenerConcurrency(t *testing.T) {
// Must be executed concurrently to uncover the data race.
// 1. RemoveListener
go func() {
defer close(done1)
for i := 0; i < roundCount; i++ {
evsw.RemoveListener("listener")
}
close(done1)
}()
// 2. AddListenerForEvent
go func() {
defer close(done2)
for i := 0; i < roundCount; i++ {
index := i
err = evsw.AddListenerForEvent("listener", fmt.Sprintf("event%d", index),
// we explicitly ignore errors here, since the listener will sometimes be removed
// (that's what we're testing)
_ = evsw.AddListenerForEvent("listener", fmt.Sprintf("event%d", index),
func(data EventData) {
t.Errorf("should not run callback for %d.\n", index)
stopInputEvent = true
})
require.NoError(t, err)
}
close(done2)
}()
<-done1


+ 2
- 0
statesync/syncer_test.go View File

@ -189,6 +189,8 @@ func TestSyncer_SyncAny(t *testing.T) {
newState, lastCommit, err := syncer.SyncAny(0)
require.NoError(t, err)
time.Sleep(50 * time.Millisecond) // wait for peers to receive requests
chunkRequestsMtx.Lock()
assert.Equal(t, map[uint32]int{0: 1, 1: 2, 2: 1}, chunkRequests)
chunkRequestsMtx.Unlock()


Loading…
Cancel
Save