Skip to content

Commit

Permalink
feat(requestmanager): run response hooks on completed requests (#77)
Browse files Browse the repository at this point in the history
We should run response hooks even on requests that are alerady completed
  • Loading branch information
hannahhoward authored Jul 15, 2020
1 parent fb8f4bb commit ef06b3d
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
9 changes: 6 additions & 3 deletions requestmanager/requestmanager.go
Original file line number Diff line number Diff line change
Expand Up @@ -382,8 +382,8 @@ func (crm *cancelRequestMessage) handle(rm *RequestManager) {
}

func (prm *processResponseMessage) handle(rm *RequestManager) {
filteredResponses := rm.filterResponsesForPeer(prm.responses, prm.p)
filteredResponses = rm.processExtensions(filteredResponses, prm.p)
filteredResponses := rm.processExtensions(prm.responses, prm.p)
filteredResponses = rm.filterResponsesForPeer(filteredResponses, prm.p)
rm.updateLastResponses(filteredResponses)
responseMetadata := metadataForResponses(filteredResponses)
rm.asyncLoader.ProcessResponse(responseMetadata, prm.blks)
Expand Down Expand Up @@ -426,7 +426,10 @@ func (rm *RequestManager) processExtensionsForResponse(p peer.ID, response gsmsg
rm.peerHandler.SendRequest(p, updateRequest)
}
if result.Err != nil {
requestStatus := rm.inProgressRequestStatuses[response.RequestID()]
requestStatus, ok := rm.inProgressRequestStatuses[response.RequestID()]
if !ok {
return false
}
responseError := rm.generateResponseErrorFromStatus(graphsync.RequestFailedUnknown)
select {
case requestStatus.networkError <- responseError:
Expand Down
5 changes: 5 additions & 0 deletions requestmanager/requestmanager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,10 @@ func TestLocallyFulfilledFirstRequestSucceedsLater(t *testing.T) {
defer cancel()
peers := testutil.GeneratePeers(1)

called := make(chan struct{})
td.responseHooks.Register(func(p peer.ID, response graphsync.ResponseData, hookActions graphsync.IncomingResponseHookActions) {
close(called)
})
returnedResponseChan, returnedErrorChan := td.requestManager.SendRequest(requestCtx, peers[0], td.blockChain.TipLink, td.blockChain.Selector())

rr := readNNetworkRequests(requestCtx, t, td.requestRecordChan, 1)[0]
Expand All @@ -310,6 +314,7 @@ func TestLocallyFulfilledFirstRequestSucceedsLater(t *testing.T) {

td.fal.VerifyNoRemainingData(t, rr.gsr.ID())
testutil.VerifyEmptyErrors(ctx, t, returnedErrorChan)
testutil.AssertDoesReceive(requestCtx, t, called, "response hooks called for response")
}

func TestRequestReturnsMissingBlocks(t *testing.T) {
Expand Down

0 comments on commit ef06b3d

Please sign in to comment.