@@ -24,8 +24,6 @@ import (
2424)
2525
2626const (
27- // Number of shards in the test
28- numOfShards = 1
2927 // Number of parties in the test
3028 numOfParties = 4
3129)
@@ -49,15 +47,15 @@ func TestPrimaryBatcherRestartRecover(t *testing.T) {
4947 require .NoError (t , err )
5048 require .NotNil (t , armaBinaryPath )
5149
52- t .Logf ("Running test with %d parties and %d shards" , numOfParties , numOfShards )
50+ t .Logf ("Running test with %d parties and %d shards" , numOfParties , 1 )
5351
5452 // Create a temporary directory for the test
5553 dir , err := os .MkdirTemp ("" , t .Name ())
5654 require .NoError (t , err )
5755 defer os .RemoveAll (dir )
5856
5957 configPath := filepath .Join (dir , "config.yaml" )
60- netInfo := testutil .CreateNetwork (t , configPath , numOfParties , numOfShards , "none" , "none" )
58+ netInfo := testutil .CreateNetwork (t , configPath , numOfParties , 1 , "none" , "none" )
6159 require .NoError (t , err )
6260 numOfArmaNodes := len (netInfo )
6361
@@ -111,24 +109,16 @@ func TestPrimaryBatcherRestartRecover(t *testing.T) {
111109 totalTxSent += totalTxNumber
112110
113111 // Pull from Assemblers
114- blockInfos := PullFromAssemblers (t , uc , parties , 0 , math .MaxUint64 , totalTxSent , - 1 , "cancelled pull from assembler: %d" )
112+ infos := PullFromAssemblers (t , uc , parties , 0 , math .MaxUint64 , totalTxSent , - 1 , "cancelled pull from assembler: %d" , 60 )
115113
116114 // Get the primary batcher
117- partyBlockInfos := blockInfos [types .PartyID (1 )]
118- primaryBatcherId := partyBlockInfos [len (partyBlockInfos )- 1 ].Primary ()
115+ primaryBatcherId := infos [types .PartyID (1 )].Primary [types .ShardID (1 )]
119116 primaryBatcher := armaNetwork .GeBatcher (t , primaryBatcherId , types .ShardID (1 ))
120- correctParties := []types.PartyID {}
121117
122118 // 3. Stop the primary batcher
123119 t .Logf ("Stopping primary batcher: party %d" , primaryBatcher .PartyId )
124120 primaryBatcher .StopArmaNode ()
125121
126- for partyID := 1 ; partyID <= numOfParties ; partyID ++ {
127- if primaryBatcherId != types .PartyID (partyID ) {
128- correctParties = append (correctParties , types .PartyID (partyID ))
129- }
130- }
131-
132122 stalled := false
133123 routerToStall := armaNetwork .GetRouter (t , primaryBatcher .PartyId )
134124
@@ -150,20 +140,25 @@ func TestPrimaryBatcherRestartRecover(t *testing.T) {
150140 }
151141 }
152142
153- // test that the router of party get stalled in the some point
143+ // make sure the router of the faulty party got stalled
154144 require .True (t , stalled , "expected router to stall but it did not" )
155145 broadcastClient .Stop ()
156146
157147 totalTxSent += totalTxNumber
158148
159149 // 5.
160- // make sure clients of correct parties continue to get transactions (expect 2000 TXs).
161- blockInfos = PullFromAssemblers (t , uc , correctParties , 0 , math .MaxUint64 , totalTxSent , - 1 , "cancelled pull from assembler: %d" )
162- partyBlockInfos = blockInfos [correctParties [0 ]]
163- newPrimaryBatcherId := partyBlockInfos [len (partyBlockInfos )- 1 ].Primary ()
150+ // make sure assemblers of correct parties continue to get transactions (expect 2000 TXs).
151+
152+ correctParties := []types.PartyID {}
153+ for partyID := 1 ; partyID <= numOfParties ; partyID ++ {
154+ if primaryBatcherId != types .PartyID (partyID ) {
155+ correctParties = append (correctParties , types .PartyID (partyID ))
156+ }
157+ }
158+ infos = PullFromAssemblers (t , uc , correctParties , 0 , math .MaxUint64 , totalTxSent , - 1 , "cancelled pull from assembler: %d" , 60 )
164159
165160 // check that the primary batcher has changed
166- require .NotEqual (t , primaryBatcherId , newPrimaryBatcherId , "expected primary batcher not to remain the same" )
161+ require .True (t , infos [ correctParties [ 0 ]]. TermChanged , "expected primary batcher not to remain the same" )
167162
168163 // 6.
169164 t .Logf ("Restarting Batcher: party %d" , primaryBatcher .PartyId )
@@ -172,7 +167,7 @@ func TestPrimaryBatcherRestartRecover(t *testing.T) {
172167
173168 testutil .WaitReady (t , readyChan , 1 , 10 )
174169
175- PullFromAssemblers (t , uc , []types.PartyID {primaryBatcher .PartyId }, 0 , math .MaxUint64 , totalTxSent , - 1 , "cancelled pull from assembler: %d" )
170+ PullFromAssemblers (t , uc , []types.PartyID {primaryBatcher .PartyId }, 0 , math .MaxUint64 , totalTxSent , - 1 , "cancelled pull from assembler: %d" , 60 )
176171
177172 // 7.
178173 broadcastClient = client .NewBroadCastTxClient (uc , 10 * time .Second )
@@ -196,8 +191,8 @@ func TestPrimaryBatcherRestartRecover(t *testing.T) {
196191 totalTxSent += totalTxNumber
197192
198193 // Pull from Assemblers
199- // make sure clients of all the parties get transactions (expect 3000 TXs).
200- PullFromAssemblers (t , uc , parties , 0 , math .MaxUint64 , totalTxSent , - 1 , "cancelled pull from assembler: %d" )
194+ // make sure assemblers of all the parties get transactions (expect 3000 TXs).
195+ PullFromAssemblers (t , uc , parties , 0 , math .MaxUint64 , totalTxSent , - 1 , "cancelled pull from assembler: %d" , 60 )
201196}
202197
203198// Simulates a scenario where a secondary batcher node is stopped and restarted.
@@ -219,15 +214,15 @@ func TestSecondaryBatcherRestartRecover(t *testing.T) {
219214 require .NoError (t , err )
220215 require .NotNil (t , armaBinaryPath )
221216
222- t .Logf ("Running test with %d parties and %d shards" , numOfParties , numOfShards )
217+ t .Logf ("Running test with %d parties and %d shards" , numOfParties , 1 )
223218
224219 // Create a temporary directory for the test
225220 dir , err := os .MkdirTemp ("" , t .Name ())
226221 require .NoError (t , err )
227222 defer os .RemoveAll (dir )
228223
229224 configPath := filepath .Join (dir , "config.yaml" )
230- netInfo := testutil .CreateNetwork (t , configPath , numOfParties , numOfShards , "none" , "none" )
225+ netInfo := testutil .CreateNetwork (t , configPath , numOfParties , 1 , "none" , "none" )
231226 require .NoError (t , err )
232227 numOfArmaNodes := len (netInfo )
233228
@@ -283,10 +278,8 @@ func TestSecondaryBatcherRestartRecover(t *testing.T) {
283278 totalTxSent += totalTxNumber
284279
285280 // Pull from Assemblers
286- blockInfos := PullFromAssemblers (t , uc , parties , 0 , math .MaxUint64 , totalTxSent , - 1 , "cancelled pull from assembler: %d" )
287-
288- partyBlockInfos := blockInfos [types .PartyID (1 )]
289- primaryBatcherId := partyBlockInfos [len (partyBlockInfos )- 1 ].Primary ()
281+ infos := PullFromAssemblers (t , uc , parties , 0 , math .MaxUint64 , totalTxSent , - 1 , "cancelled pull from assembler: %d" , 60 )
282+ primaryBatcherId := infos [types .PartyID (1 )].Primary [types .ShardID (1 )]
290283 correctParties := []types.PartyID {}
291284
292285 var secondaryBatcher * testutil.ArmaNodeInfo = nil
@@ -326,20 +319,18 @@ func TestSecondaryBatcherRestartRecover(t *testing.T) {
326319 }
327320 }
328321
329- // test that the router of party get stalled in the some point
322+ // make sure the router of the faulty party got stalled
330323 require .True (t , stalled , "expected router to stall but it did not" )
331324 broadcastClient .Stop ()
332325
333326 totalTxSent += totalTxNumber
334327
335328 // 5.
336- // make sure clients of correct parties continue to get transactions (expect 2000 TXs).
337- blockInfos = PullFromAssemblers (t , uc , correctParties , 0 , math .MaxUint64 , totalTxSent , - 1 , "cancelled pull from assembler: %d" )
338- partyBlockInfos = blockInfos [correctParties [0 ]]
339- newPrimaryBatcherId := partyBlockInfos [len (partyBlockInfos )- 1 ].Primary ()
329+ // make sure assemblers of correct parties continue to get transactions (expect 2000 TXs).
330+ infos = PullFromAssemblers (t , uc , correctParties , 0 , math .MaxUint64 , totalTxSent , - 1 , "cancelled pull from assembler: %d" , 60 )
340331
341332 // make sure the primary batcher did not change
342- require .Equal (t , primaryBatcherId , newPrimaryBatcherId , "expected primary batcher to remain the same" )
333+ require .False (t , infos [ correctParties [ 0 ]]. TermChanged , "expected primary batcher to remain the same" )
343334
344335 // 6.
345336 t .Logf ("Restarting Batcher %d of party %d" , secondaryBatcher .PartyId , secondaryBatcher .PartyId )
@@ -348,7 +339,7 @@ func TestSecondaryBatcherRestartRecover(t *testing.T) {
348339
349340 testutil .WaitReady (t , readyChan , 1 , 10 )
350341
351- PullFromAssemblers (t , uc , []types.PartyID {secondaryBatcher .PartyId }, 0 , math .MaxUint64 , totalTxSent , - 1 , "cancelled pull from assembler: %d" )
342+ PullFromAssemblers (t , uc , []types.PartyID {secondaryBatcher .PartyId }, 0 , math .MaxUint64 , totalTxSent , - 1 , "cancelled pull from assembler: %d" , 60 )
352343
353344 // 7.
354345 // make sure 2f+1 routers are receiving TXs w/o problems
@@ -373,6 +364,6 @@ func TestSecondaryBatcherRestartRecover(t *testing.T) {
373364 totalTxSent += totalTxNumber
374365
375366 // Pull from Assemblers
376- // make sure clients of all the parties get transactions (expect 3000 TXs).
377- PullFromAssemblers (t , uc , parties , 0 , math .MaxUint64 , totalTxSent , - 1 , "cancelled pull from assembler: %d" )
367+ // make sure assemblers of all the parties get transactions (expect 3000 TXs).
368+ PullFromAssemblers (t , uc , parties , 0 , math .MaxUint64 , totalTxSent , - 1 , "cancelled pull from assembler: %d" , 60 )
378369}
0 commit comments