Skip to content

Commit

Permalink
test(providerquerymanager): fix timings
Browse files Browse the repository at this point in the history
Fix several sensitive timings on ProviderQueryManager tests
that could lead to intermittent failures in CI


This commit was moved from ipfs/go-bitswap@e002540
  • Loading branch information
hannahhoward committed Oct 8, 2021
1 parent 3a26de9 commit b73686f
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 b73686f

Please sign in to comment.