Skip to content

Commit

Permalink
test(responsemanager): fix flakiness TestCancellationViaCommand
Browse files Browse the repository at this point in the history
Resolve issue that caused TestCancellationViaCommand to sometimes fail as the request was already
finished
  • Loading branch information
hannahhoward committed Oct 7, 2021
1 parent a15abd7 commit dcccffc
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 @@ -101,6 +101,15 @@ func TestCancellationViaCommand(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++
})
responseManager.Startup()
responseManager.ProcessRequests(td.ctx, td.p, td.requests)

Expand All @@ -110,6 +119,7 @@ func TestCancellationViaCommand(t *testing.T) {
// send a cancellation
err := responseManager.CancelResponse(td.p, td.requestID)
require.NoError(t, err)
close(waitForCancel)

td.assertCompleteRequestWith(graphsync.RequestCancelled)
td.connManager.RefuteProtected(t, td.p)
Expand Down

0 comments on commit dcccffc

Please sign in to comment.