Skip to content
This repository has been archived by the owner on Feb 1, 2023. It is now read-only.

Commit

Permalink
fix: message queue test races on Windows
Browse files Browse the repository at this point in the history
  • Loading branch information
guseggert committed Aug 13, 2022
1 parent 1fed963 commit 0efd31d
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 15 deletions.
6 changes: 3 additions & 3 deletions client/internal/messagequeue/donthavetimeoutmgr_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -375,10 +375,10 @@ func TestDontHaveTimeoutMgrUsesDefaultTimeoutIfPingError(t *testing.T) {

func TestDontHaveTimeoutMgrUsesDefaultTimeoutIfLatencyLonger(t *testing.T) {
ks := testutil.GenerateCids(2)
latency := time.Millisecond * 20
latency := time.Millisecond * 200
latMultiplier := 1
expProcessTime := time.Duration(0)
defaultTimeout := 10 * time.Millisecond
defaultTimeout := 100 * time.Millisecond
clock := clock.NewMock()
pinged := make(chan struct{})
pc := &mockPeerConn{latency: latency, clock: clock, pinged: pinged}
Expand All @@ -395,7 +395,7 @@ func TestDontHaveTimeoutMgrUsesDefaultTimeoutIfLatencyLonger(t *testing.T) {
dhtm.AddPending(ks)

// Sleep for less than the default timeout
clock.Add(defaultTimeout - 5*time.Millisecond)
clock.Add(defaultTimeout - 50*time.Millisecond)

// At this stage no timeout should have happened yet
if tr.timedOutCount() > 0 {
Expand Down
24 changes: 12 additions & 12 deletions client/internal/messagequeue/messagequeue_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ func TestStartupAndShutdown(t *testing.T) {

messageQueue.Startup()
messageQueue.AddBroadcastWantHaves(bcstwh)
messages := collectMessages(ctx, t, messagesSent, 10*time.Millisecond)
messages := collectMessages(ctx, t, messagesSent, 100*time.Millisecond)
if len(messages) != 1 {
t.Fatal("wrong number of messages were sent for broadcast want-haves")
}
Expand All @@ -184,7 +184,7 @@ func TestStartupAndShutdown(t *testing.T) {

messageQueue.Shutdown()

timeoutctx, cancel := context.WithTimeout(ctx, 10*time.Millisecond)
timeoutctx, cancel := context.WithTimeout(ctx, 100*time.Millisecond)
defer cancel()
select {
case <-resetChan:
Expand All @@ -207,7 +207,7 @@ func TestSendingMessagesDeduped(t *testing.T) {
messageQueue.Startup()
messageQueue.AddWants(wantBlocks, wantHaves)
messageQueue.AddWants(wantBlocks, wantHaves)
messages := collectMessages(ctx, t, messagesSent, 10*time.Millisecond)
messages := collectMessages(ctx, t, messagesSent, 100*time.Millisecond)

if totalEntriesLength(messages) != len(wantHaves)+len(wantBlocks) {
t.Fatal("Messages were not deduped")
Expand Down Expand Up @@ -318,7 +318,7 @@ func TestCancelOverridesPendingWants(t *testing.T) {
messageQueue.Startup()
messageQueue.AddWants(wantBlocks, wantHaves)
messageQueue.AddCancels(cancels)
messages := collectMessages(ctx, t, messagesSent, 10*time.Millisecond)
messages := collectMessages(ctx, t, messagesSent, 100*time.Millisecond)

if totalEntriesLength(messages) != len(wantHaves)+len(wantBlocks)-len(cancels) {
t.Fatal("Wrong message count")
Expand All @@ -342,7 +342,7 @@ func TestCancelOverridesPendingWants(t *testing.T) {
// Cancel the remaining want-blocks and want-haves
cancels = append(wantHaves, wantBlocks...)
messageQueue.AddCancels(cancels)
messages = collectMessages(ctx, t, messagesSent, 10*time.Millisecond)
messages = collectMessages(ctx, t, messagesSent, 100*time.Millisecond)

// The remaining 2 cancels should be sent to the network as they are for
// wants that were sent to the network
Expand Down Expand Up @@ -370,7 +370,7 @@ func TestWantOverridesPendingCancels(t *testing.T) {
// Add 1 want-block and 2 want-haves
messageQueue.AddWants(wantBlocks, wantHaves)

messages := collectMessages(ctx, t, messagesSent, 10*time.Millisecond)
messages := collectMessages(ctx, t, messagesSent, 100*time.Millisecond)
if totalEntriesLength(messages) != len(wantBlocks)+len(wantHaves) {
t.Fatal("Wrong message count", totalEntriesLength(messages))
}
Expand All @@ -380,7 +380,7 @@ func TestWantOverridesPendingCancels(t *testing.T) {
// Override one cancel with a want-block (before cancel is sent to network)
messageQueue.AddWants(cids[:1], []cid.Cid{})

messages = collectMessages(ctx, t, messagesSent, 10*time.Millisecond)
messages = collectMessages(ctx, t, messagesSent, 100*time.Millisecond)
if totalEntriesLength(messages) != 3 {
t.Fatal("Wrong message count", totalEntriesLength(messages))
}
Expand Down Expand Up @@ -554,7 +554,7 @@ func TestSendToPeerThatDoesntSupportHave(t *testing.T) {
// Check broadcast want-haves
bcwh := testutil.GenerateCids(10)
messageQueue.AddBroadcastWantHaves(bcwh)
messages := collectMessages(ctx, t, messagesSent, 10*time.Millisecond)
messages := collectMessages(ctx, t, messagesSent, 100*time.Millisecond)

if len(messages) != 1 {
t.Fatal("wrong number of messages were sent", len(messages))
Expand All @@ -573,7 +573,7 @@ func TestSendToPeerThatDoesntSupportHave(t *testing.T) {
wbs := testutil.GenerateCids(10)
whs := testutil.GenerateCids(10)
messageQueue.AddWants(wbs, whs)
messages = collectMessages(ctx, t, messagesSent, 10*time.Millisecond)
messages = collectMessages(ctx, t, messagesSent, 100*time.Millisecond)

if len(messages) != 1 {
t.Fatal("wrong number of messages were sent", len(messages))
Expand Down Expand Up @@ -603,7 +603,7 @@ func TestSendToPeerThatDoesntSupportHaveMonitorsTimeouts(t *testing.T) {

wbs := testutil.GenerateCids(10)
messageQueue.AddWants(wbs, nil)
collectMessages(ctx, t, messagesSent, 10*time.Millisecond)
collectMessages(ctx, t, messagesSent, 100*time.Millisecond)

// Check want-blocks are added to DontHaveTimeoutMgr
if dhtm.pendingCount() != len(wbs) {
Expand All @@ -612,7 +612,7 @@ func TestSendToPeerThatDoesntSupportHaveMonitorsTimeouts(t *testing.T) {

cancelCount := 2
messageQueue.AddCancels(wbs[:cancelCount])
collectMessages(ctx, t, messagesSent, 10*time.Millisecond)
collectMessages(ctx, t, messagesSent, 100*time.Millisecond)

// Check want-blocks are removed from DontHaveTimeoutMgr
if dhtm.pendingCount() != len(wbs)-cancelCount {
Expand Down Expand Up @@ -685,7 +685,7 @@ func TestResponseReceivedAppliesForFirstResponseOnly(t *testing.T) {

// Add some wants and wait 10ms
messageQueue.AddWants(cids, nil)
collectMessages(ctx, t, messagesSent, 10*time.Millisecond)
collectMessages(ctx, t, messagesSent, 100*time.Millisecond)

// Receive a response for the wants
messageQueue.ResponseReceived(cids)
Expand Down

0 comments on commit 0efd31d

Please sign in to comment.