@@ -10,6 +10,7 @@ import (
1010 "context"
1111 "os"
1212 "path/filepath"
13+ "strconv"
1314 "sync"
1415 "testing"
1516 "time"
@@ -415,10 +416,8 @@ func TestOrdererDeliverBFT(t *testing.T) {
415416 // Verify suspicion metrics for party 2
416417 suspicionCount2 := test .GetIntMetricValue (t , m .SuspicionRaisedTotal .WithLabelValues ("2" ))
417418 require .GreaterOrEqual (t , suspicionCount2 , 1 , "suspicion should be raised for party 2" )
418-
419- // Verify target arrival deadline was set when suspicion was raised
420- targetDeadline := test .GetMetricValue (t , m .TargetArrivalDeadline .WithLabelValues ("2" ))
421- require .Greater (t , targetDeadline , float64 (0 ), "target arrival deadline should be set" )
419+ suspicionConfirmCount2 := test .GetIntMetricValue (t , m .SuspicionConfirmedTotal .WithLabelValues ("2" ))
420+ require .GreaterOrEqual (t , suspicionConfirmCount2 , 1 , "suspicion should be confirmed for party 2" )
422421
423422 currentSource = test .GetIntMetricValue (t , m .CurrentDataSourceID )
424423 require .Equal (t , 1 , currentSource , "current data source should be party 1" )
@@ -478,7 +477,7 @@ func TestOrdererDeliverBFT(t *testing.T) {
478477 stopDelivery ()
479478
480479 p1 .HoldFromBlock .Store (0 )
481- e .startDelivery (t )
480+ stopDelivery = e .startDelivery (t )
482481 b = e .submit (t )
483482 require .EqualValues (t , 1 , b .SourceID )
484483
@@ -499,6 +498,66 @@ func TestOrdererDeliverBFT(t *testing.T) {
499498
500499 finalBlockNum := test .GetIntMetricValue (t , m .StreamBlockNumber .WithLabelValues ("data" ))
501500 require .GreaterOrEqual (t , finalBlockNum , 5 , "should have delivered multiple blocks" )
501+
502+ t .Log ("Restart stream with longer suspecion deadline" )
503+ stopDelivery ()
504+ p0 .HoldFromBlock .Store (0 )
505+ p0 .ReplaceBlock .Clear ()
506+ p1 .HoldFromBlock .Store (0 )
507+ p1 .ReplaceBlock .Clear ()
508+ p2 .HoldFromBlock .Store (0 )
509+ p2 .ReplaceBlock .Clear ()
510+ e .deliveryParams .SuspicionGracePeriodPerBlock = time .Hour
511+
512+ stopDelivery = e .startDelivery (t )
513+ b = e .submit (t )
514+ curSource := b .SourceID
515+ curSourceLabel := strconv .FormatUint (uint64 (curSource ), 10 )
516+
517+ t .Logf ("Hold blocks from current source: %s" , curSourceLabel )
518+ e .PartyStates [curSource ].HoldFromBlock .Store (b .Block .Header .Number )
519+
520+ curSusCount := test .GetIntMetricValue (t , m .SuspicionRaisedTotal .WithLabelValues (curSourceLabel ))
521+ curConfirmedSusCount := test .GetIntMetricValue (t , m .SuspicionConfirmedTotal .WithLabelValues (curSourceLabel ))
522+ curClearedSusCount := test .GetIntMetricValue (t , m .SuspicionClearedTotal .WithLabelValues (curSourceLabel ))
523+
524+ expectedDeadline := float64 (time .Now ().Add (time .Hour - time .Millisecond ).UnixMilli ())
525+ t .Log ("Submit another block without receiving it" )
526+ txs := workload .GenerateTransactions (t , nil , 10 )
527+ block := workload .MapToOrdererBlock (0 , txs )
528+ err := e .Orderer .SubmitBlock (t .Context (), block )
529+ require .NoError (t , err )
530+ b , ok := channel .NewReader (t .Context (), e .outputWithSource ).ReadWithTimeout (3 * time .Second )
531+ require .False (t , ok )
532+ require .Nil (t , b )
533+
534+ suspecions := test .GetIntMetricValue (t , m .SuspicionRaisedTotal .WithLabelValues (curSourceLabel ))
535+ require .Greater (t , suspecions , curSusCount )
536+ suspicionConfirmed := test .GetIntMetricValue (t , m .SuspicionConfirmedTotal .WithLabelValues (curSourceLabel ))
537+ require .Equal (t , curConfirmedSusCount , suspicionConfirmed )
538+ suspicionCleared := test .GetIntMetricValue (t , m .SuspicionClearedTotal .WithLabelValues (curSourceLabel ))
539+ require .Equal (t , curClearedSusCount , suspicionCleared )
540+
541+ // Verify target arrival deadline was set when suspicion was raised.
542+ targetDeadline := test .GetMetricValue (t , m .TargetArrivalDeadline .WithLabelValues (curSourceLabel ))
543+ require .Greater (t , targetDeadline , expectedDeadline )
544+
545+ // Verify gap.
546+ gap := test .GetIntMetricValue (t , m .BlockGapGauge .WithLabelValues (curSourceLabel ))
547+ require .Equal (t , gap , - 1 )
548+
549+ t .Log ("Release data block" )
550+ e .PartyStates [curSource ].HoldFromBlock .Store (0 )
551+ blk := e .WaitForBlock (t , e .output )
552+ require .NotNil (t , blk )
553+
554+ // Suspecion cleared.
555+ suspicionCleared = test .GetIntMetricValue (t , m .SuspicionClearedTotal .WithLabelValues (curSourceLabel ))
556+ require .Greater (t , suspicionCleared , curClearedSusCount )
557+ targetDeadline = test .GetMetricValue (t , m .TargetArrivalDeadline .WithLabelValues (curSourceLabel ))
558+ require .Zero (t , targetDeadline )
559+
560+ stopDelivery ()
502561 })
503562 }
504563}
0 commit comments