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

Commit

Permalink
fix: flaky provider query manager (#286)
Browse files Browse the repository at this point in the history
  • Loading branch information
dirkmc authored Mar 10, 2020
1 parent a441107 commit 964888c
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions internal/providerquerymanager/providerquerymanager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ type fakeProviderNetwork struct {
connectDelay time.Duration
queriesMadeMutex sync.RWMutex
queriesMade int
liveQueries int
}

func (fpn *fakeProviderNetwork) ConnectTo(context.Context, peer.ID) error {
Expand All @@ -31,6 +32,7 @@ func (fpn *fakeProviderNetwork) ConnectTo(context.Context, peer.ID) error {
func (fpn *fakeProviderNetwork) FindProvidersAsync(ctx context.Context, k cid.Cid, max int) <-chan peer.ID {
fpn.queriesMadeMutex.Lock()
fpn.queriesMade++
fpn.liveQueries++
fpn.queriesMadeMutex.Unlock()
incomingPeers := make(chan peer.ID)
go func() {
Expand All @@ -48,7 +50,11 @@ func (fpn *fakeProviderNetwork) FindProvidersAsync(ctx context.Context, k cid.Ci
return
}
}
fpn.queriesMadeMutex.Lock()
fpn.liveQueries--
fpn.queriesMadeMutex.Unlock()
}()

return incomingPeers
}

Expand Down Expand Up @@ -264,8 +270,8 @@ func TestRateLimitingRequests(t *testing.T) {
}
time.Sleep(9 * time.Millisecond)
fpn.queriesMadeMutex.Lock()
if fpn.queriesMade != maxInProcessRequests {
t.Logf("Queries made: %d\n", fpn.queriesMade)
if fpn.liveQueries != maxInProcessRequests {
t.Logf("Queries made: %d\n", fpn.liveQueries)
t.Fatal("Did not limit parallel requests to rate limit")
}
fpn.queriesMadeMutex.Unlock()
Expand Down

0 comments on commit 964888c

Please sign in to comment.