Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix flakiness TestCancellationViaCommand #243

Merged
merged 1 commit into from
Oct 7, 2021
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: 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
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

so this blocks and we won't increment blkCount until the close on line 121. but nothing checks blkCount directly so this is about blocking the blockHook processing?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yea
I can comment to be clear

}
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