Commit 04e47665 authored by Steven Allen's avatar Steven Allen

test(prq): test canceling FindProviders context after completion

parent 21ccf0c7
...@@ -329,3 +329,35 @@ func TestFindProviderPreCanceled(t *testing.T) { ...@@ -329,3 +329,35 @@ func TestFindProviderPreCanceled(t *testing.T) {
t.Fatal("shouldn't have blocked waiting on a closed context") t.Fatal("shouldn't have blocked waiting on a closed context")
} }
} }
func TestCancelFindProvidersAfterCompletion(t *testing.T) {
peers := testutil.GeneratePeers(2)
fpn := &fakeProviderNetwork{
peersFound: peers,
delay: 1 * time.Millisecond,
}
ctx := context.Background()
providerQueryManager := New(ctx, fpn)
providerQueryManager.Startup()
providerQueryManager.SetFindProviderTimeout(100 * time.Millisecond)
keys := testutil.GenerateCids(1)
sessionCtx, cancel := context.WithCancel(ctx)
firstRequestChan := providerQueryManager.FindProvidersAsync(sessionCtx, keys[0])
<-firstRequestChan // wait for everything to start.
time.Sleep(10 * time.Millisecond) // wait for the incoming providres to stop.
cancel() // cancel the context.
timer := time.NewTimer(10 * time.Millisecond)
defer timer.Stop()
for {
select {
case _, ok := <-firstRequestChan:
if !ok {
return
}
case <-timer.C:
t.Fatal("should have finished receiving responses within timeout")
}
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment