@@ -41,6 +41,7 @@ func init() {
4141type routerTestSetup struct {
4242 ca tlsgen.CA
4343 batchers []* stubBatcher
44+ consenter * router.StubConsenter
4445 clientConn * grpc.ClientConn
4546 router * router.Router
4647}
@@ -57,6 +58,8 @@ func (r *routerTestSetup) Close() {
5758 for _ , batcher := range r .batchers {
5859 batcher .server .Stop ()
5960 }
61+
62+ r .consenter .Stop ()
6063}
6164
6265func (r * routerTestSetup ) isReconnectComplete () bool {
@@ -83,14 +86,18 @@ func createRouterTestSetup(t *testing.T, partyID types.PartyID, numOfShards int,
8386 for _ , batcher := range batchers {
8487 batcher .Start ()
8588 }
89+ // create and start stub-consenter
90+ stubConsenter := router .NewStubConsenter (t , ca , partyID )
91+ stubConsenter .Start ()
8692
8793 // create and start router
88- router := createAndStartRouter (t , partyID , ca , batchers , useTLS , clientAuthRequired )
94+ router := createAndStartRouter (t , partyID , ca , batchers , & stubConsenter , useTLS , clientAuthRequired )
8995
9096 return & routerTestSetup {
91- ca : ca ,
92- batchers : batchers ,
93- router : router ,
97+ ca : ca ,
98+ batchers : batchers ,
99+ consenter : & stubConsenter ,
100+ router : router ,
94101 }
95102}
96103
@@ -428,6 +435,87 @@ func TestRequestFilters(t *testing.T) {
428435 // 5) send request with invalid signature. Not implemented
429436}
430437
438+ // Scenario:
439+ // 1) Start a client, router and stub consenter
440+ // 2) Send valid config request, expect response from stub consenter
441+ func TestConfigSubmitter (t * testing.T ) {
442+ testSetup := createRouterTestSetup (t , types .PartyID (1 ), 1 , true , false )
443+ err := createServerTLSClientConnection (testSetup , testSetup .ca )
444+ require .NoError (t , err )
445+ require .NotNil (t , testSetup .clientConn )
446+
447+ defer testSetup .Close ()
448+
449+ err = submitConfigRequest (t , testSetup .clientConn )
450+ require .NoError (t , err )
451+
452+ require .Eventually (t , func () bool {
453+ return testSetup .consenter .ReceivedMessageCount () == uint32 (1 )
454+ }, 10 * time .Second , 10 * time .Millisecond )
455+ }
456+
457+ func TestConfigSubmitterConsenterDown (t * testing.T ) {
458+ testSetup := createRouterTestSetup (t , types .PartyID (1 ), 1 , true , false )
459+ err := createServerTLSClientConnection (testSetup , testSetup .ca )
460+ require .NoError (t , err )
461+ require .NotNil (t , testSetup .clientConn )
462+
463+ defer testSetup .Close ()
464+
465+ // submit one request, and wait for the response
466+ err = submitConfigRequest (t , testSetup .clientConn )
467+ require .NoError (t , err )
468+
469+ require .Eventually (t , func () bool {
470+ return testSetup .consenter .ReceivedMessageCount () == uint32 (1 )
471+ }, 10 * time .Second , 10 * time .Millisecond )
472+
473+ // stop the consenter and wait until it is down
474+ testSetup .consenter .Stop ()
475+ time .Sleep (250 * time .Millisecond )
476+
477+ // wait and restart the consenter
478+ go func () {
479+ time .Sleep (250 * time .Millisecond )
480+ testSetup .consenter .Restart ()
481+ }()
482+
483+ // meanwhile, forward another request
484+ err = submitConfigRequest (t , testSetup .clientConn )
485+ require .NoError (t , err )
486+
487+ require .Eventually (t , func () bool {
488+ return testSetup .consenter .ReceivedMessageCount () == uint32 (2 )
489+ }, 10 * time .Second , 10 * time .Millisecond )
490+ }
491+
492+ func submitConfigRequest (t * testing.T , conn * grpc.ClientConn ) error {
493+ cl := ab .NewAtomicBroadcastClient (conn )
494+
495+ ctx , cancel := context .WithTimeout (context .Background (), 30 * time .Second )
496+ defer cancel ()
497+
498+ stream , err := cl .Broadcast (ctx )
499+ require .NoError (t , err )
500+ var wg sync.WaitGroup
501+ wg .Add (1 )
502+
503+ go func () {
504+ defer wg .Done ()
505+ env := tx .CreateStructuredConfigEnvelope ([]byte ("123" ))
506+ err := stream .Send (env )
507+ require .NoError (t , err )
508+ }()
509+
510+ resp , err := stream .Recv ()
511+ require .NoError (t , err )
512+ require .Equal (t , common .Status_INTERNAL_SERVER_ERROR , resp .Status )
513+ require .Equal (t , "dummy submit config" , resp .Info )
514+ wg .Wait ()
515+
516+ return nil
517+ }
518+
431519func createServerTLSClientConnection (testSetup * routerTestSetup , ca tlsgen.CA ) error {
432520 cc := comm.ClientConfig {
433521 SecOpts : comm.SecureOptions {
@@ -585,7 +673,7 @@ func submitRequest(conn *grpc.ClientConn) error {
585673 return nil
586674}
587675
588- func createAndStartRouter (t * testing.T , partyID types.PartyID , ca tlsgen.CA , batchers []* stubBatcher , useTLS bool , clientAuthRequired bool ) * router.Router {
676+ func createAndStartRouter (t * testing.T , partyID types.PartyID , ca tlsgen.CA , batchers []* stubBatcher , consenter * router. StubConsenter , useTLS bool , clientAuthRequired bool ) * router.Router {
589677 ckp , err := ca .NewServerCertKeyPair ("127.0.0.1" )
590678 require .NoError (t , err )
591679
@@ -602,6 +690,8 @@ func createAndStartRouter(t *testing.T, partyID types.PartyID, ca tlsgen.CA, bat
602690 configtxValidator .ChannelIDReturns ("arma" )
603691 bundle .ConfigtxValidatorReturns (configtxValidator )
604692
693+ stubConsenterInfo := config.ConsenterInfo {PartyID : partyID , Endpoint : consenter .GetConsenterEndpoint (), TLSCACerts : []config.RawBytes {ca .CertBytes ()}}
694+
605695 conf := & config.RouterNodeConfig {
606696 PartyID : partyID ,
607697 TLSCertificateFile : ckp .Cert ,
@@ -611,6 +701,7 @@ func createAndStartRouter(t *testing.T, partyID types.PartyID, ca tlsgen.CA, bat
611701 ConfigStorePath : t .TempDir (),
612702 ClientAuthRequired : clientAuthRequired ,
613703 Shards : shards ,
704+ Consenter : stubConsenterInfo ,
614705 RequestMaxBytes : 1 << 10 ,
615706 ClientSignatureVerificationRequired : false ,
616707 Bundle : bundle ,
0 commit comments