@@ -30,8 +30,12 @@ import (
3030 "github.com/hyperledger/fabric-x-committer/utils/test"
3131)
3232
33- // We expect at least 3 blocks for a valid test run.
34- const defaultExpectedTXs = defaultBlockSize * 3
33+ const (
34+ // We expect at least 3 blocks for a valid test run.
35+ defaultExpectedTXs = defaultBlockSize * 3
36+ // Each server's SAN is localhost.
37+ defaultServerSAN = "localhost"
38+ )
3539
3640// We can enforce exact limits only for the sidecar and the coordinator.
3741// The other adapters runs concurrent workers that might overshoot.
@@ -42,64 +46,93 @@ var defaultLimits = []*adapters.GenerateLimit{
4246
4347func TestLoadGenForLoadGen (t * testing.T ) {
4448 t .Parallel ()
45-
46- for _ , limit := range defaultLimits {
47- clientConf := DefaultClientConf ()
48- clientConf .Limit = limit
49- // Ensure the client doesn't generate load, but only receives it from the sub client.
50- clientConf .LoadProfile .Workers = 0
51- t .Run (limitToString (limit ), func (t * testing.T ) {
49+ for _ , mode := range test .ServerModes {
50+ mode := mode
51+ t .Run (fmt .Sprintf ("tls-mode:%s" , mode ), func (t * testing.T ) {
5252 t .Parallel ()
53- clientConf .Adapter .VerifierClient = startVerifiers (t )
54- _ , err := clientConf .Server .PreAllocateListener ()
55- require .NoError (t , err )
56-
57- subClientConf := DefaultClientConf ()
58- subClientConf .Adapter .LoadGenClient = test .NewInsecureClientConfig (& clientConf .Server .Endpoint )
59- subClient , err := NewLoadGenClient (subClientConf )
60- require .NoError (t , err )
61-
62- t .Log ("Start distributed loadgen" )
63- test .RunServiceAndGrpcForTest (t .Context (), t , subClient , subClientConf .Server )
64- testLoadGenerator (t , clientConf )
53+ serverCreds , clientCreds := createServerAndClientTLSCerts (t , mode )
54+ for _ , limit := range defaultLimits {
55+ limit := limit
56+ t .Run (limitToString (limit ), func (t * testing.T ) {
57+ t .Parallel ()
58+ clientConf := DefaultClientConf ()
59+ clientConf .Server .TLS = serverCreds
60+ clientConf .Limit = limit
61+ // Ensure the client doesn't generate load, but only receives it from the sub client.
62+ clientConf .LoadProfile .Workers = 0
63+
64+ clientConf .Adapter .VerifierClient = startVerifiers (t ,
65+ test .InsecureTLSConfig , test .InsecureTLSConfig ,
66+ )
67+ _ , err := clientConf .Server .PreAllocateListener ()
68+ require .NoError (t , err )
69+
70+ subClientConf := DefaultClientConf ()
71+ subClientConf .Adapter .LoadGenClient = test .NewTLSClientConfig (
72+ clientCreds , & clientConf .Server .Endpoint ,
73+ )
74+ subClient , err := NewLoadGenClient (subClientConf )
75+ require .NoError (t , err )
76+
77+ t .Log ("Start distributed loadgen" )
78+ test .RunServiceAndGrpcForTest (t .Context (), t , subClient , subClientConf .Server )
79+ testLoadGenerator (t , clientConf )
80+ })
81+ }
6582 })
6683 }
6784}
6885
6986func TestLoadGenForVCService (t * testing.T ) {
7087 t .Parallel ()
71- for _ , limit := range defaultLimits {
72- clientConf := DefaultClientConf ()
73- clientConf .Limit = limit
74- t .Run (limitToString (limit ), func (t * testing.T ) {
88+ for _ , mode := range test .ServerModes {
89+ mode := mode
90+ t .Run (fmt .Sprintf ("tls-mode:%s" , mode ), func (t * testing.T ) {
7591 t .Parallel ()
76- env := vc .NewValidatorAndCommitServiceTestEnvWithTLS (t , 2 , test .InsecureTLSConfig )
77- clientConf .Adapter .VCClient = test .NewInsecureMultiClientConfig (env .Endpoints ... )
78- testLoadGenerator (t , clientConf )
92+ serverCreds , clientCreds := createServerAndClientTLSCerts (t , mode )
93+ for _ , limit := range defaultLimits {
94+ limit := limit
95+ t .Run (limitToString (limit ), func (t * testing.T ) {
96+ t .Parallel ()
97+ clientConf := DefaultClientConf ()
98+ clientConf .Limit = limit
99+ env := vc .NewValidatorAndCommitServiceTestEnvWithTLS (t , 2 , serverCreds )
100+ clientConf .Adapter .VCClient = test .NewTLSMultiClientConfig (clientCreds , env .Endpoints ... )
101+ testLoadGenerator (t , clientConf )
102+ })
103+ }
79104 })
80105 }
81106}
82107
83108func TestLoadGenForSigVerifier (t * testing.T ) {
84109 t .Parallel ()
85- for _ , limit := range defaultLimits {
86- clientConf := DefaultClientConf ()
87- clientConf .Limit = limit
88- t .Run (limitToString (limit ), func (t * testing.T ) {
110+ for _ , mode := range test .ServerModes {
111+ mode := mode
112+ t .Run (fmt .Sprintf ("tls-mode:%s" , mode ), func (t * testing.T ) {
89113 t .Parallel ()
90- clientConf .Adapter .VerifierClient = startVerifiers (t )
91- // Start client
92- testLoadGenerator (t , clientConf )
114+ serverCreds , clientCreds := createServerAndClientTLSCerts (t , mode )
115+ for _ , limit := range defaultLimits {
116+ limit := limit
117+ t .Run (limitToString (limit ), func (t * testing.T ) {
118+ t .Parallel ()
119+ clientConf := DefaultClientConf ()
120+ clientConf .Limit = limit
121+ clientConf .Adapter .VerifierClient = startVerifiers (t , serverCreds , clientCreds )
122+ // Start client
123+ testLoadGenerator (t , clientConf )
124+ })
125+ }
93126 })
94127 }
95128}
96129
97- func startVerifiers (t * testing.T ) * connection.MultiClientConfig {
130+ func startVerifiers (t * testing.T , serverCreds , clientCreds connection. TLSConfig ) * connection.MultiClientConfig {
98131 t .Helper ()
99132 endpoints := make ([]* connection.Endpoint , 2 )
100133 for i := range endpoints {
101134 sConf := & verifier.Config {
102- Server : connection .NewLocalHostServerWithTLS (test . InsecureTLSConfig ),
135+ Server : connection .NewLocalHostServerWithTLS (serverCreds ),
103136 ParallelExecutor : verifier.ExecutorConfig {
104137 BatchSizeCutoff : 50 ,
105138 BatchTimeCutoff : 10 * time .Millisecond ,
@@ -112,111 +145,130 @@ func startVerifiers(t *testing.T) *connection.MultiClientConfig {
112145 test .RunGrpcServerForTest (t .Context (), t , sConf .Server , service .RegisterService )
113146 endpoints [i ] = & sConf .Server .Endpoint
114147 }
115- return test .NewInsecureMultiClientConfig ( endpoints ... )
148+ return test .NewTLSMultiClientConfig ( clientCreds , endpoints ... )
116149}
117150
118151func TestLoadGenForCoordinator (t * testing.T ) {
119152 t .Parallel ()
120- for _ , limit := range append (
121- defaultLimits ,
122- & adapters.GenerateLimit {Blocks : 5 },
123- & adapters.GenerateLimit {Transactions : 5 * defaultBlockSize + 2 }, // +2 for the config and meta namespace TXs.
124- ) {
125- clientConf := DefaultClientConf ()
126- clientConf .Limit = limit
127- t .Run (limitToString (limit ), func (t * testing.T ) {
153+ for _ , mode := range test .ServerModes {
154+ mode := mode
155+ t .Run (fmt .Sprintf ("tls-mode:%s" , mode ), func (t * testing.T ) {
128156 t .Parallel ()
129- _ , sigVerServer := mock .StartMockSVService (t , 1 )
130- _ , vcServer := mock .StartMockVCService (t , 1 )
131-
132- cConf := & coordinator.Config {
133- Server : connection .NewLocalHostServerWithTLS (test .InsecureTLSConfig ),
134- Monitoring : defaultMonitoring (),
135- Verifier : * test .ServerToMultiClientConfig (sigVerServer .Configs ... ),
136- ValidatorCommitter : * test .ServerToMultiClientConfig (vcServer .Configs ... ),
137- DependencyGraph : & coordinator.DependencyGraphConfig {
138- NumOfLocalDepConstructors : 1 ,
139- WaitingTxsLimit : 100_000 ,
157+ serverCreds , clientCreds := createServerAndClientTLSCerts (t , mode )
158+ for _ , limit := range append (
159+ defaultLimits ,
160+ & adapters.GenerateLimit {Blocks : 5 },
161+ & adapters.GenerateLimit {
162+ Transactions : 5 * defaultBlockSize + 2 , // +2 for the config and meta namespace TXs.
140163 },
141- ChannelBufferSizePerGoroutine : 10 ,
164+ ) {
165+ limit := limit
166+ t .Run (limitToString (limit ), func (t * testing.T ) {
167+ t .Parallel ()
168+ clientConf := DefaultClientConf ()
169+ clientConf .Limit = limit
170+ _ , sigVerServer := mock .StartMockSVService (t , 1 )
171+ _ , vcServer := mock .StartMockVCService (t , 1 )
172+
173+ cConf := & coordinator.Config {
174+ Server : connection .NewLocalHostServerWithTLS (serverCreds ),
175+ Monitoring : defaultMonitoring (),
176+ Verifier : * test .ServerToMultiClientConfig (sigVerServer .Configs ... ),
177+ ValidatorCommitter : * test .ServerToMultiClientConfig (vcServer .Configs ... ),
178+ DependencyGraph : & coordinator.DependencyGraphConfig {
179+ NumOfLocalDepConstructors : 1 ,
180+ WaitingTxsLimit : 100_000 ,
181+ },
182+ ChannelBufferSizePerGoroutine : 10 ,
183+ }
184+
185+ service := coordinator .NewCoordinatorService (cConf )
186+ test .RunServiceAndGrpcForTest (t .Context (), t , service , cConf .Server )
187+
188+ // Start client
189+ clientConf .Adapter .CoordinatorClient = test .NewTLSClientConfig (clientCreds , & cConf .Server .Endpoint )
190+ testLoadGenerator (t , clientConf )
191+ })
142192 }
143-
144- service := coordinator .NewCoordinatorService (cConf )
145- test .RunServiceAndGrpcForTest (t .Context (), t , service , cConf .Server )
146-
147- // Start client
148- clientConf .Adapter .CoordinatorClient = test .NewInsecureClientConfig (& cConf .Server .Endpoint )
149- testLoadGenerator (t , clientConf )
150193 })
151194 }
152195}
153196
154197func TestLoadGenForSidecar (t * testing.T ) {
155198 t .Parallel ()
156-
157- for _ , limit := range append (
158- defaultLimits ,
159- & adapters.GenerateLimit {Blocks : 5 },
160- & adapters.GenerateLimit {Transactions : 5 * defaultBlockSize + 1 }, // +1 for the meta namespace TX.
161- ) {
162- clientConf := DefaultClientConf ()
163- clientConf .Limit = limit
164- t .Run (limitToString (limit ), func (t * testing.T ) {
199+ for _ , mode := range test .ServerModes {
200+ mode := mode
201+ t .Run (fmt .Sprintf ("tls-mode:%s" , mode ), func (t * testing.T ) {
165202 t .Parallel ()
166- _ , coordinatorServer := mock .StartMockCoordinatorService (t )
167-
168- // When using the sidecar adapter, the load generator and the sidecar
169- // should have each other's endpoints.
170- // To avoid manually pre-choosing ports that might conflict with other tests,
171- // we pre allocate them by starting a listener that picks a port automatically and bind to it.
172- // In real evaluation scenario, the ports will be selected by the deployment infrastructure.
173- sidecarServerConf := preAllocatePorts (t )
174- ordererServers := make ([]* connection.ServerConfig , 3 )
175- for i := range ordererServers {
176- ordererServers [i ] = preAllocatePorts (t )
177- }
178-
179- // Start server under test
180- sidecarConf := & sidecar.Config {
181- Server : sidecarServerConf ,
182- Orderer : ordererconn.Config {
183- Connection : ordererconn.ConnectionConfig {
184- Endpoints : ordererconn .NewEndpoints (0 , "org" , ordererServers ... ),
185- },
186- ChannelID : clientConf .LoadProfile .Transaction .Policy .ChannelID ,
187- Identity : clientConf .LoadProfile .Transaction .Policy .Identity ,
188- ConsensusType : ordererconn .Bft ,
189- },
190- LastCommittedBlockSetInterval : 100 * time .Millisecond ,
191- WaitingTxsLimit : 5000 ,
192- Committer : test .NewInsecureClientConfig (& coordinatorServer .Configs [0 ].Endpoint ),
193- Monitoring : defaultMonitoring (),
194- Ledger : sidecar.LedgerConfig {
195- Path : t .TempDir (),
196- },
203+ serverCreds , clientCreds := createServerAndClientTLSCerts (t , mode )
204+ for _ , limit := range append (
205+ defaultLimits ,
206+ & adapters.GenerateLimit {Blocks : 5 },
207+ & adapters.GenerateLimit {Transactions : 5 * defaultBlockSize + 1 }, // +1 for the meta namespace TX.
208+ ) {
209+ limit := limit
210+ t .Run (limitToString (limit ), func (t * testing.T ) {
211+ t .Parallel ()
212+ clientConf := DefaultClientConf ()
213+ clientConf .Limit = limit
214+ _ , coordinatorServer := mock .StartMockCoordinatorService (t )
215+
216+ // When using the sidecar adapter, the load generator and the sidecar
217+ // should have each other's endpoints.
218+ // To avoid manually pre-choosing ports that might conflict with other tests,
219+ // we pre allocate them by starting a listener that picks a port automatically and bind to it.
220+ // In real evaluation scenario, the ports will be selected by the deployment infrastructure.
221+ sidecarServerConf := preAllocatePorts (t )
222+ ordererServers := make ([]* connection.ServerConfig , 3 )
223+ for i := range ordererServers {
224+ ordererServers [i ] = preAllocatePorts (t )
225+ }
226+ sidecarServerConf .TLS = serverCreds
227+ // Start server under test
228+ sidecarConf := & sidecar.Config {
229+ Server : sidecarServerConf ,
230+ Orderer : ordererconn.Config {
231+ Connection : ordererconn.ConnectionConfig {
232+ Endpoints : ordererconn .NewEndpoints (0 , "org" , ordererServers ... ),
233+ },
234+ ChannelID : clientConf .LoadProfile .Transaction .Policy .ChannelID ,
235+ Identity : clientConf .LoadProfile .Transaction .Policy .Identity ,
236+ ConsensusType : ordererconn .Bft ,
237+ },
238+ LastCommittedBlockSetInterval : 100 * time .Millisecond ,
239+ WaitingTxsLimit : 5000 ,
240+ Committer : test .NewInsecureClientConfig (
241+ & coordinatorServer .Configs [0 ].Endpoint ,
242+ ),
243+ Monitoring : defaultMonitoring (),
244+ Ledger : sidecar.LedgerConfig {
245+ Path : t .TempDir (),
246+ },
247+ }
248+ service , err := sidecar .New (sidecarConf )
249+ require .NoError (t , err )
250+ t .Cleanup (service .Close )
251+ test .RunServiceAndGrpcForTest (t .Context (), t , service , sidecarConf .Server )
252+ // Start client
253+ clientConf .Adapter .SidecarClient = & adapters.SidecarClientConfig {
254+ OrdererServers : ordererServers ,
255+ SidecarClient : test .NewTLSClientConfig (clientCreds , & sidecarServerConf .Endpoint ),
256+ }
257+ testLoadGenerator (t , clientConf )
258+ })
197259 }
198- service , err := sidecar .New (sidecarConf )
199- require .NoError (t , err )
200- t .Cleanup (service .Close )
201- test .RunServiceAndGrpcForTest (t .Context (), t , service , sidecarConf .Server )
202-
203- // Start client
204- clientConf .Adapter .SidecarClient = & adapters.SidecarClientConfig {
205- OrdererServers : ordererServers ,
206- SidecarClient : test .NewInsecureClientConfig (& sidecarServerConf .Endpoint ),
207- }
208- testLoadGenerator (t , clientConf )
209260 })
210261 }
211262}
212263
213264func TestLoadGenForOrderer (t * testing.T ) {
214265 t .Parallel ()
215266 for _ , limit := range defaultLimits {
216- clientConf := DefaultClientConf ()
217- clientConf .Limit = limit
267+ limit := limit
218268 t .Run (limitToString (limit ), func (t * testing.T ) {
219269 t .Parallel ()
270+ clientConf := DefaultClientConf ()
271+ clientConf .Limit = limit
220272 // Start dependencies
221273 orderer , ordererServer := mock .StartMockOrderingServices (
222274 t , & mock.OrdererConfig {NumService : 3 , BlockSize : 100 },
@@ -404,3 +456,13 @@ func limitToString(m *adapters.GenerateLimit) string {
404456 }
405457 return strings .Join (out , "," )
406458}
459+
460+ // createServerAndClientTLSCerts creates a tls configuration using the credential factory.
461+ func createServerAndClientTLSCerts (t * testing.T , tlsMode string ) (
462+ serverCreds , clientCreds connection.TLSConfig ,
463+ ) {
464+ t .Helper ()
465+ credsFactory := test .NewCredentialsFactory (t )
466+ return credsFactory .CreateServerCredentials (t , tlsMode , defaultServerSAN ),
467+ credsFactory .CreateClientCredentials (t , tlsMode )
468+ }
0 commit comments