@@ -344,22 +344,27 @@ func TestNode_RunCoordinationLayer(t *testing.T) {
344344 if signer .wallet .publicKey .Equal (walletPublicKey ) {
345345 result , ok := map [uint64 ]* coordinationResult {
346346 900 : {
347+ window : window ,
347348 proposal : & mockCoordinationProposal {ActionDepositSweep },
348349 },
349350 // Omit window at block 1800 to make sure the layer doesn't
350351 // crash if no result is produced.
351352 2700 : {
353+ window : window ,
352354 proposal : & mockCoordinationProposal {ActionRedemption },
353355 },
354356 // Put some trash value to make sure coordination windows
355357 // are distributed correctly.
356358 2705 : {
359+ window : window ,
357360 proposal : & mockCoordinationProposal {ActionMovingFunds },
358361 },
359362 3600 : {
363+ window : window ,
360364 proposal : & mockCoordinationProposal {ActionNoop },
361365 },
362366 4500 : {
367+ window : window ,
363368 proposal : & mockCoordinationProposal {ActionMovedFundsSweep },
364369 },
365370 }[window .coordinationBlock ]
@@ -405,6 +410,10 @@ loop:
405410 for {
406411 select {
407412 case result := <- processedResultsChan :
413+ if result == nil {
414+ continue
415+ }
416+
408417 processedResults = append (processedResults , result )
409418
410419 // Once the second-last coordination window is processed, stop the
@@ -425,24 +434,68 @@ loop:
425434 3 ,
426435 len (processedResults ),
427436 )
428- testutils .AssertStringsEqual (
437+
438+ resultActionsByWindow := make (map [uint64 ]WalletActionType , len (processedResults ))
439+ for _ , result := range processedResults {
440+ resultActionsByWindow [result .window .coordinationBlock ] =
441+ result .proposal .ActionType ()
442+ }
443+
444+ testutils .AssertIntsEqual (
429445 t ,
430- "first result " ,
431- ActionDepositSweep . String () ,
432- processedResults [ 0 ]. proposal . ActionType (). String ( ),
446+ "processed coordination windows count " ,
447+ 3 ,
448+ len ( resultActionsByWindow ),
433449 )
450+
451+ firstAction , ok := resultActionsByWindow [900 ]
452+ if ! ok {
453+ t .Fatal ("expected coordination result for window at block 900" )
454+ }
434455 testutils .AssertStringsEqual (
435456 t ,
436- "second result" ,
437- ActionRedemption .String (),
438- processedResults [ 1 ]. proposal . ActionType () .String (),
457+ "result for block 900 " ,
458+ ActionDepositSweep .String (),
459+ firstAction .String (),
439460 )
461+
462+ secondAction , ok := resultActionsByWindow [2700 ]
463+ if ! ok {
464+ t .Fatal ("expected coordination result for window at block 2700" )
465+ }
440466 testutils .AssertStringsEqual (
441467 t ,
442- "third result" ,
443- ActionNoop .String (),
444- processedResults [ 2 ]. proposal . ActionType () .String (),
468+ "result for block 2700 " ,
469+ ActionRedemption .String (),
470+ secondAction .String (),
445471 )
472+
473+ if _ , ok := resultActionsByWindow [2705 ]; ok {
474+ t .Fatal ("unexpected coordination result for non-window block 2705" )
475+ }
476+
477+ // Result processing is asynchronous, so by the time the test cancels the
478+ // coordination layer after the third processed result, either the 3600
479+ // window or the subsequent 4500 window may already be in flight.
480+ if thirdAction , ok := resultActionsByWindow [3600 ]; ok {
481+ testutils .AssertStringsEqual (
482+ t ,
483+ "result for block 3600" ,
484+ ActionNoop .String (),
485+ thirdAction .String (),
486+ )
487+ } else {
488+ fourthAction , ok := resultActionsByWindow [4500 ]
489+ if ! ok {
490+ t .Fatal ("expected coordination result for block 3600 or 4500" )
491+ }
492+ testutils .AssertStringsEqual (
493+ t ,
494+ "result for block 4500" ,
495+ ActionMovedFundsSweep .String (),
496+ fourthAction .String (),
497+ )
498+ }
446499}
447500
448501type mockCoordinationProposal struct {
0 commit comments