Skip to content

Commit

Permalink
test(responsemanager): fix flaky TestCancellationQueryInProgress
Browse files Browse the repository at this point in the history
resolve possible failure from request finishing early -- simply to fix for
TestCancellationViaCommand
  • Loading branch information
hannahhoward committed Oct 7, 2021
1 parent 6aab775 commit f3e35d3
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions responsemanager/responsemanager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,15 @@ func TestCancellationQueryInProgress(t *testing.T) {
defer td.cancel()
responseManager := td.newResponseManager()
td.requestHooks.Register(selectorvalidator.SelectorValidator(100))
// This block hook is simply used to pause block hook processing after 1 block until the cancel command is sent
blkCount := 0
waitForCancel := make(chan struct{})
td.blockHooks.Register(func(p peer.ID, requestData graphsync.RequestData, blockData graphsync.BlockData, hookActions graphsync.OutgoingBlockHookActions) {
if blkCount == 1 {
<-waitForCancel
}
blkCount++
})
cancelledListenerCalled := make(chan struct{}, 1)
td.cancelledListeners.Register(func(p peer.ID, request graphsync.RequestData) {
td.connManager.RefuteProtected(t, td.p)
Expand All @@ -90,6 +99,7 @@ func TestCancellationQueryInProgress(t *testing.T) {
}
responseManager.ProcessRequests(td.ctx, td.p, cancelRequests)
responseManager.synchronize()
close(waitForCancel)

testutil.AssertDoesReceive(td.ctx, t, cancelledListenerCalled, "should call cancelled listener")

Expand Down

0 comments on commit f3e35d3

Please sign in to comment.