From 6284ce16a0e00c9dcb99237c3b9f6bb4c51432f2 Mon Sep 17 00:00:00 2001 From: hannahhoward Date: Mon, 20 Apr 2020 02:33:22 -0700 Subject: [PATCH] fix(tests): cleanup races & lint --- impl/graphsync_test.go | 11 ++++++++--- requestmanager/requestmanager.go | 3 --- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/impl/graphsync_test.go b/impl/graphsync_test.go index 7bc894a5..016ff947 100644 --- a/impl/graphsync_test.go +++ b/impl/graphsync_test.go @@ -239,11 +239,14 @@ func TestPauseResume(t *testing.T) { stopPoint := 50 blocksSent := 0 - var requestID graphsync.RequestID + requestIDChan := make(chan graphsync.RequestID, 1) responder.RegisterOutgoingBlockHook(func(p peer.ID, requestData graphsync.RequestData, blockData graphsync.BlockData, hookActions graphsync.OutgoingBlockHookActions) { _, has := requestData.Extension(td.extensionName) if has { - requestID = requestData.ID() + select { + case requestIDChan <- requestData.ID(): + default: + } blocksSent++ if blocksSent == stopPoint { hookActions.PauseResponse() @@ -259,7 +262,9 @@ func TestPauseResume(t *testing.T) { timer := time.NewTimer(100 * time.Millisecond) testutil.AssertDoesReceiveFirst(t, timer.C, "should pause request", progressChan) - responder.UnpauseResponse(td.host1.ID(), requestID) + requestID := <-requestIDChan + err := responder.UnpauseResponse(td.host1.ID(), requestID) + require.NoError(t, err) blockChain.VerifyRemainder(ctx, progressChan, stopPoint) testutil.VerifyEmptyErrors(ctx, t, errChan) diff --git a/requestmanager/requestmanager.go b/requestmanager/requestmanager.go index be2d686e..4bb82b83 100644 --- a/requestmanager/requestmanager.go +++ b/requestmanager/requestmanager.go @@ -3,7 +3,6 @@ package requestmanager import ( "context" "fmt" - "math" blocks "github.com/ipfs/go-block-format" "github.com/ipfs/go-graphsync" @@ -23,8 +22,6 @@ import ( var log = logging.Logger("graphsync") const ( - // maxPriority is the max priority as defined by the graphsync protocol - maxPriority = graphsync.Priority(math.MaxInt32) // defaultPriority is the default priority for requests sent by graphsync defaultPriority = graphsync.Priority(0) )