Commit 21ccf0c7 authored by Steven Allen's avatar Steven Allen

test(prq): test finding providers with a pre-canceled context

parent f6e05274
......@@ -304,3 +304,28 @@ func TestFindProviderTimeout(t *testing.T) {
t.Fatal("Find provider request should have timed out, did not")
}
}
func TestFindProviderPreCanceled(t *testing.T) {
peers := testutil.GeneratePeers(10)
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)
cancel()
firstRequestChan := providerQueryManager.FindProvidersAsync(sessionCtx, keys[0])
if firstRequestChan == nil {
t.Fatal("expected non-nil channel")
}
select {
case <-firstRequestChan:
case <-time.After(10 * time.Millisecond):
t.Fatal("shouldn't have blocked waiting on a closed context")
}
}
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