@@ -100,6 +100,7 @@ type FakeGraphSync struct {
100100 pauseResponses chan PauseResponse
101101 resumeResponses chan ResumeResponse
102102 cancelResponses chan CancelResponse
103+ cancelRequests chan graphsync.RequestID
103104 persistenceOptionsLk sync.RWMutex
104105 persistenceOptions map [string ]PersistenceOption
105106 leaveRequestsOpen bool
@@ -126,6 +127,7 @@ func NewFakeGraphSync() *FakeGraphSync {
126127 pauseResponses : make (chan PauseResponse , 1 ),
127128 resumeResponses : make (chan ResumeResponse , 1 ),
128129 cancelResponses : make (chan CancelResponse , 1 ),
130+ cancelRequests : make (chan graphsync.RequestID , 1 ),
129131 persistenceOptions : make (map [string ]PersistenceOption ),
130132 }
131133}
@@ -230,6 +232,17 @@ func (fgs *FakeGraphSync) AssertCancelResponseReceived(ctx context.Context, t *t
230232 return cancelResponseReceived
231233}
232234
235+ // AssertCancelRequestReceived asserts a request was cancelled
236+ func (fgs * FakeGraphSync ) AssertCancelRequestReceived (ctx context.Context , t * testing.T ) graphsync.RequestID {
237+ select {
238+ case <- ctx .Done ():
239+ t .Fatal ("did not receive message sent" )
240+ return 0
241+ case requestID := <- fgs .cancelRequests :
242+ return requestID
243+ }
244+ }
245+
233246// AssertHasPersistenceOption verifies that a persistence option was registered
234247func (fgs * FakeGraphSync ) AssertHasPersistenceOption (t * testing.T , name string ) PersistenceOption {
235248 fgs .persistenceOptionsLk .RLock ()
@@ -367,6 +380,11 @@ func (fgs *FakeGraphSync) PauseRequest(requestID graphsync.RequestID) error {
367380 return nil
368381}
369382
383+ func (fgs * FakeGraphSync ) CancelRequest (ctx context.Context , requestID graphsync.RequestID ) error {
384+ fgs .cancelRequests <- requestID
385+ return nil
386+ }
387+
370388// CancelResponse cancels a response in progress
371389func (fgs * FakeGraphSync ) CancelResponse (p peer.ID , requestID graphsync.RequestID ) error {
372390 fgs .cancelResponses <- CancelResponse {p , requestID }
0 commit comments