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

Fix flaky provider query manager test #286

Merged
merged 1 commit into from
Mar 10, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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