Skip to content

Commit

Permalink
Merge pull request ipfs/go-bitswap#534 from ipfs/fix/flaky-test-rate-…
Browse files Browse the repository at this point in the history
…limiting-requests

Fix ProviderQueryManager test timings

This commit was moved from ipfs/go-bitswap@462f628
  • Loading branch information
Stebalien committed Oct 14, 2021
2 parents 3a26de9 + b73686f commit 868c9e0
Showing 1 changed file with 7 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ func TestNormalSimultaneousFetch(t *testing.T) {
providerQueryManager.Startup()
keys := testutil.GenerateCids(2)

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

sessionCtx, cancel := context.WithTimeout(ctx, 100*time.Millisecond)
sessionCtx, cancel := context.WithTimeout(ctx, 5*time.Second)
defer cancel()
firstRequestChan := providerQueryManager.FindProvidersAsync(sessionCtx, key)
secondRequestChan := providerQueryManager.FindProvidersAsync(sessionCtx, key)
Expand Down Expand Up @@ -152,7 +152,7 @@ func TestCancelOneRequestDoesNotTerminateAnother(t *testing.T) {
firstSessionCtx, firstCancel := context.WithTimeout(ctx, 3*time.Millisecond)
defer firstCancel()
firstRequestChan := providerQueryManager.FindProvidersAsync(firstSessionCtx, key)
secondSessionCtx, secondCancel := context.WithTimeout(ctx, 100*time.Millisecond)
secondSessionCtx, secondCancel := context.WithTimeout(ctx, 5*time.Second)
defer secondCancel()
secondRequestChan := providerQueryManager.FindProvidersAsync(secondSessionCtx, key)

Expand Down Expand Up @@ -262,7 +262,7 @@ func TestRateLimitingRequests(t *testing.T) {
providerQueryManager.Startup()

keys := testutil.GenerateCids(maxInProcessRequests + 1)
sessionCtx, cancel := context.WithTimeout(ctx, 100*time.Millisecond)
sessionCtx, cancel := context.WithTimeout(ctx, 5*time.Second)
defer cancel()
var requestChannels []<-chan peer.ID
for i := 0; i < maxInProcessRequests+1; i++ {
Expand All @@ -283,6 +283,7 @@ func TestRateLimitingRequests(t *testing.T) {
fpn.queriesMadeMutex.Lock()
defer fpn.queriesMadeMutex.Unlock()
if fpn.queriesMade != maxInProcessRequests+1 {
t.Logf("Queries made: %d\n", fpn.queriesMade)
t.Fatal("Did not make all seperate requests")
}
}
Expand All @@ -291,15 +292,15 @@ func TestFindProviderTimeout(t *testing.T) {
peers := testutil.GeneratePeers(10)
fpn := &fakeProviderNetwork{
peersFound: peers,
delay: 1 * time.Millisecond,
delay: 10 * time.Millisecond,
}
ctx := context.Background()
providerQueryManager := New(ctx, fpn)
providerQueryManager.Startup()
providerQueryManager.SetFindProviderTimeout(2 * time.Millisecond)
keys := testutil.GenerateCids(1)

sessionCtx, cancel := context.WithTimeout(ctx, 100*time.Millisecond)
sessionCtx, cancel := context.WithTimeout(ctx, 5*time.Second)
defer cancel()
firstRequestChan := providerQueryManager.FindProvidersAsync(sessionCtx, keys[0])
var firstPeersReceived []peer.ID
Expand Down

0 comments on commit 868c9e0

Please sign in to comment.