@@ -99,6 +99,19 @@ func makeJob() *queryJob {
9999 m .requests <- req .Message ()
100100 return nil
101101 },
102+ CloneReq : func (req ReqMessage ) ReqMessage {
103+ oldReq := req .(* mockQueryEncoded )
104+
105+ newMsg := & wire.MsgGetData {
106+ InvList : oldReq .message .InvList ,
107+ }
108+
109+ clone := & mockQueryEncoded {
110+ message : newMsg ,
111+ }
112+
113+ return clone
114+ },
102115 }
103116
104117 return & queryJob {
@@ -209,9 +222,15 @@ func TestWorkerIgnoreMsgs(t *testing.T) {
209222 t .Fatalf ("response error: %v" , result .err )
210223 }
211224
212- // Make sure the result was given for the intended job.
213- if result .job != task {
214- t .Fatalf ("got result for unexpected job" )
225+ // Make sure the QueryJob instance in the result is different from the initial one
226+ // supplied to the worker
227+ if result .job == task {
228+ t .Fatalf ("result's job should be different from the task's" )
229+ }
230+
231+ // Make sure we are receiving the corresponding result for the given task.
232+ if result .job .Index () != task .Index () {
233+ t .Fatalf ("result's job index should not be different from task's" )
215234 }
216235
217236 // And the correct peer.
@@ -264,9 +283,15 @@ func TestWorkerTimeout(t *testing.T) {
264283 t .Fatalf ("expected timeout, got: %v" , result .err )
265284 }
266285
267- // Make sure the result was given for the intended job.
268- if result .job != task {
269- t .Fatalf ("got result for unexpected job" )
286+ // Make sure the QueryJob instance in the result is different from the initial one
287+ // supplied to the worker
288+ if result .job == task {
289+ t .Fatalf ("result's job should be different from the task's" )
290+ }
291+
292+ // Make sure we are receiving the corresponding result for the given task.
293+ if result .job .Index () != task .Index () {
294+ t .Fatalf ("result's job index should not be different from task's" )
270295 }
271296
272297 // And the correct peer.
@@ -323,9 +348,15 @@ func TestWorkerDisconnect(t *testing.T) {
323348 t .Fatalf ("expected peer disconnect, got: %v" , result .err )
324349 }
325350
326- // Make sure the result was given for the intended job.
327- if result .job != task {
328- t .Fatalf ("got result for unexpected job" )
351+ // Make sure the QueryJob instance in the result is different from the initial one
352+ // supplied to the worker
353+ if result .job == task {
354+ t .Fatalf ("result's job should be different from the task's" )
355+ }
356+
357+ // Make sure we are receiving the corresponding result for the given task.
358+ if result .job .Index () != task .Index () {
359+ t .Fatalf ("result's job index should not be different from task's" )
329360 }
330361
331362 // And the correct peer.
@@ -411,9 +442,15 @@ func TestWorkerProgress(t *testing.T) {
411442 t .Fatalf ("expected no error, got: %v" , result .err )
412443 }
413444
414- // Make sure the result was given for the intended task.
415- if result .job != task {
416- t .Fatalf ("got result for unexpected job" )
445+ // Make sure the QueryJob instance in the result is different from the initial one
446+ // supplied to the worker
447+ if result .job == task {
448+ t .Fatalf ("result's job should be different from the task's" )
449+ }
450+
451+ // Make sure we are receiving the corresponding result for the given task.
452+ if result .job .Index () != task .Index () {
453+ t .Fatalf ("result's job index should not be different from task's" )
417454 }
418455
419456 // And the correct peer.
@@ -484,9 +521,15 @@ func TestWorkerJobCanceled(t *testing.T) {
484521 t .Fatalf ("expected job canceled, got: %v" , result .err )
485522 }
486523
487- // Make sure the result was given for the intended task.
488- if result .job != task {
489- t .Fatalf ("got result for unexpected job" )
524+ // Make sure the QueryJob instance in the result is different from the initial one
525+ // supplied to the worker
526+ if result .job == task {
527+ t .Fatalf ("result's job should be different from the task's" )
528+ }
529+
530+ // Make sure we are receiving the corresponding result for the given task.
531+ if result .job .Index () != task .Index () {
532+ t .Fatalf ("result's job index should not be different from task's" )
490533 }
491534
492535 // And the correct peer.
@@ -540,9 +583,9 @@ func TestWorkerSendQueryErr(t *testing.T) {
540583 ctx .peer .err , result .err )
541584 }
542585
543- // Make sure the result was given for the intended task .
586+ // Make sure the QueryJob instance in the result is same as the initial one .
544587 if result .job != taskJob {
545- t .Fatalf ("got result for unexpected job " )
588+ t .Fatalf ("result's job should be same as the task's " )
546589 }
547590
548591 // And the correct peer.
0 commit comments