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

Commit 462f628

Browse files
authored
Merge pull request #534 from ipfs/fix/flaky-test-rate-limiting-requests
Fix ProviderQueryManager test timings
2 parents 958b163 + e002540 commit 462f628

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

internal/providerquerymanager/providerquerymanager_test.go

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ func TestNormalSimultaneousFetch(t *testing.T) {
6969
providerQueryManager.Startup()
7070
keys := testutil.GenerateCids(2)
7171

72-
sessionCtx, cancel := context.WithTimeout(ctx, 100*time.Millisecond)
72+
sessionCtx, cancel := context.WithTimeout(ctx, 5*time.Second)
7373
defer cancel()
7474
firstRequestChan := providerQueryManager.FindProvidersAsync(sessionCtx, keys[0])
7575
secondRequestChan := providerQueryManager.FindProvidersAsync(sessionCtx, keys[1])
@@ -107,7 +107,7 @@ func TestDedupingProviderRequests(t *testing.T) {
107107
providerQueryManager.Startup()
108108
key := testutil.GenerateCids(1)[0]
109109

110-
sessionCtx, cancel := context.WithTimeout(ctx, 100*time.Millisecond)
110+
sessionCtx, cancel := context.WithTimeout(ctx, 5*time.Second)
111111
defer cancel()
112112
firstRequestChan := providerQueryManager.FindProvidersAsync(sessionCtx, key)
113113
secondRequestChan := providerQueryManager.FindProvidersAsync(sessionCtx, key)
@@ -152,7 +152,7 @@ func TestCancelOneRequestDoesNotTerminateAnother(t *testing.T) {
152152
firstSessionCtx, firstCancel := context.WithTimeout(ctx, 3*time.Millisecond)
153153
defer firstCancel()
154154
firstRequestChan := providerQueryManager.FindProvidersAsync(firstSessionCtx, key)
155-
secondSessionCtx, secondCancel := context.WithTimeout(ctx, 100*time.Millisecond)
155+
secondSessionCtx, secondCancel := context.WithTimeout(ctx, 5*time.Second)
156156
defer secondCancel()
157157
secondRequestChan := providerQueryManager.FindProvidersAsync(secondSessionCtx, key)
158158

@@ -262,7 +262,7 @@ func TestRateLimitingRequests(t *testing.T) {
262262
providerQueryManager.Startup()
263263

264264
keys := testutil.GenerateCids(maxInProcessRequests + 1)
265-
sessionCtx, cancel := context.WithTimeout(ctx, 100*time.Millisecond)
265+
sessionCtx, cancel := context.WithTimeout(ctx, 5*time.Second)
266266
defer cancel()
267267
var requestChannels []<-chan peer.ID
268268
for i := 0; i < maxInProcessRequests+1; i++ {
@@ -283,6 +283,7 @@ func TestRateLimitingRequests(t *testing.T) {
283283
fpn.queriesMadeMutex.Lock()
284284
defer fpn.queriesMadeMutex.Unlock()
285285
if fpn.queriesMade != maxInProcessRequests+1 {
286+
t.Logf("Queries made: %d\n", fpn.queriesMade)
286287
t.Fatal("Did not make all seperate requests")
287288
}
288289
}
@@ -291,15 +292,15 @@ func TestFindProviderTimeout(t *testing.T) {
291292
peers := testutil.GeneratePeers(10)
292293
fpn := &fakeProviderNetwork{
293294
peersFound: peers,
294-
delay: 1 * time.Millisecond,
295+
delay: 10 * time.Millisecond,
295296
}
296297
ctx := context.Background()
297298
providerQueryManager := New(ctx, fpn)
298299
providerQueryManager.Startup()
299300
providerQueryManager.SetFindProviderTimeout(2 * time.Millisecond)
300301
keys := testutil.GenerateCids(1)
301302

302-
sessionCtx, cancel := context.WithTimeout(ctx, 100*time.Millisecond)
303+
sessionCtx, cancel := context.WithTimeout(ctx, 5*time.Second)
303304
defer cancel()
304305
firstRequestChan := providerQueryManager.FindProvidersAsync(sessionCtx, keys[0])
305306
var firstPeersReceived []peer.ID

0 commit comments

Comments
 (0)