@@ -36,13 +36,14 @@ func atxSeqResult(atxs []types.ATXID) rangesync.SeqResult {
36
36
}
37
37
}
38
38
39
+ var testCfg = sync2.Config {
40
+ BatchSize : 4 ,
41
+ MaxAttempts : 3 ,
42
+ MaxBatchRetries : 2 ,
43
+ FailedBatchDelay : 10 * time .Second ,
44
+ }
45
+
39
46
func TestAtxHandler_Success (t * testing.T ) {
40
- const (
41
- batchSize = 4
42
- maxAttempts = 3
43
- maxBatchRetries = 2
44
- batchRetryDelay = 10 * time .Second
45
- )
46
47
ctrl := gomock .NewController (t )
47
48
allAtxs := make ([]types.ATXID , 10 )
48
49
logger := zaptest .NewLogger (t )
@@ -52,7 +53,7 @@ func TestAtxHandler_Success(t *testing.T) {
52
53
}
53
54
f := NewMockFetcher (ctrl )
54
55
clock := clockwork .NewFakeClock ()
55
- h := sync2 .NewATXHandler (logger , f , batchSize , maxAttempts , maxBatchRetries , batchRetryDelay , clock )
56
+ h := sync2 .NewATXHandler (logger , f , testCfg , clock )
56
57
baseSet := mocks .NewMockOrderedSet (ctrl )
57
58
for _ , id := range allAtxs {
58
59
baseSet .EXPECT ().Has (rangesync .KeyBytes (id .Bytes ()))
@@ -84,12 +85,6 @@ func TestAtxHandler_Success(t *testing.T) {
84
85
}
85
86
86
87
func TestAtxHandler_Retry (t * testing.T ) {
87
- const (
88
- batchSize = 4
89
- maxAttempts = 3
90
- maxBatchRetries = 2
91
- batchRetryDelay = 10 * time .Second
92
- )
93
88
ctrl := gomock .NewController (t )
94
89
allAtxs := make ([]types.ATXID , 10 )
95
90
logger := zaptest .NewLogger (t )
@@ -99,7 +94,7 @@ func TestAtxHandler_Retry(t *testing.T) {
99
94
}
100
95
f := NewMockFetcher (ctrl )
101
96
clock := clockwork .NewFakeClock ()
102
- h := sync2 .NewATXHandler (logger , f , batchSize , maxAttempts , maxBatchRetries , batchRetryDelay , clock )
97
+ h := sync2 .NewATXHandler (logger , f , testCfg , clock )
103
98
baseSet := mocks .NewMockOrderedSet (ctrl )
104
99
for _ , id := range allAtxs {
105
100
baseSet .EXPECT ().Has (rangesync .KeyBytes (id .Bytes ()))
@@ -159,7 +154,7 @@ func TestAtxHandler_Retry(t *testing.T) {
159
154
if ctx .Err () != nil {
160
155
return nil
161
156
}
162
- clock .Advance (batchRetryDelay )
157
+ clock .Advance (testCfg . FailedBatchDelay )
163
158
}
164
159
})
165
160
@@ -170,19 +165,13 @@ func TestAtxHandler_Retry(t *testing.T) {
170
165
}
171
166
172
167
func TestAtxHandler_Cancel (t * testing.T ) {
173
- const (
174
- batchSize = 4
175
- maxAttempts = 3
176
- maxBatchRetries = 2
177
- batchRetryDelay = 10 * time .Second
178
- )
179
168
atxID := types .RandomATXID ()
180
169
ctrl := gomock .NewController (t )
181
170
logger := zaptest .NewLogger (t )
182
171
peer := p2p .Peer ("foobar" )
183
172
f := NewMockFetcher (ctrl )
184
173
clock := clockwork .NewFakeClock ()
185
- h := sync2 .NewATXHandler (logger , f , batchSize , maxAttempts , maxBatchRetries , batchRetryDelay , clock )
174
+ h := sync2 .NewATXHandler (logger , f , testCfg , clock )
186
175
baseSet := mocks .NewMockOrderedSet (ctrl )
187
176
baseSet .EXPECT ().Has (rangesync .KeyBytes (atxID .Bytes ())).Return (false , nil )
188
177
f .EXPECT ().RegisterPeerHashes (peer , []types.Hash32 {atxID .Hash32 ()})
@@ -200,12 +189,6 @@ func TestAtxHandler_Cancel(t *testing.T) {
200
189
}
201
190
202
191
func TestAtxHandler_BatchRetry (t * testing.T ) {
203
- const (
204
- batchSize = 4
205
- maxAttempts = 3
206
- maxBatchRetries = 2
207
- batchRetryDelay = 10 * time .Second
208
- )
209
192
ctrl := gomock .NewController (t )
210
193
allAtxs := make ([]types.ATXID , 10 )
211
194
logger := zaptest .NewLogger (t )
@@ -215,7 +198,7 @@ func TestAtxHandler_BatchRetry(t *testing.T) {
215
198
}
216
199
clock := clockwork .NewFakeClock ()
217
200
f := NewMockFetcher (ctrl )
218
- h := sync2 .NewATXHandler (logger , f , batchSize , maxAttempts , maxBatchRetries , batchRetryDelay , clock )
201
+ h := sync2 .NewATXHandler (logger , f , testCfg , clock )
219
202
baseSet := mocks .NewMockOrderedSet (ctrl )
220
203
for _ , id := range allAtxs {
221
204
baseSet .EXPECT ().Has (rangesync .KeyBytes (id .Bytes ()))
@@ -249,18 +232,12 @@ func TestAtxHandler_BatchRetry(t *testing.T) {
249
232
}
250
233
return nil
251
234
}).Times (3 )
252
- clock .Advance (batchRetryDelay )
235
+ clock .Advance (testCfg . FailedBatchDelay )
253
236
require .NoError (t , eg .Wait ())
254
237
require .Empty (t , toFetch )
255
238
}
256
239
257
240
func TestAtxHandler_BatchRetry_Fail (t * testing.T ) {
258
- const (
259
- batchSize = 4
260
- maxAttempts = 3
261
- maxBatchRetries = 2
262
- batchRetryDelay = 10 * time .Second
263
- )
264
241
ctrl := gomock .NewController (t )
265
242
allAtxs := make ([]types.ATXID , 10 )
266
243
logger := zaptest .NewLogger (t )
@@ -270,7 +247,7 @@ func TestAtxHandler_BatchRetry_Fail(t *testing.T) {
270
247
}
271
248
clock := clockwork .NewFakeClock ()
272
249
f := NewMockFetcher (ctrl )
273
- h := sync2 .NewATXHandler (logger , f , batchSize , maxAttempts , maxBatchRetries , batchRetryDelay , clock )
250
+ h := sync2 .NewATXHandler (logger , f , testCfg , clock )
274
251
baseSet := mocks .NewMockOrderedSet (ctrl )
275
252
for _ , id := range allAtxs {
276
253
baseSet .EXPECT ().Has (rangesync .KeyBytes (id .Bytes ()))
@@ -296,7 +273,7 @@ func TestAtxHandler_BatchRetry_Fail(t *testing.T) {
296
273
})
297
274
for range 2 {
298
275
clock .BlockUntil (1 )
299
- clock .Advance (batchRetryDelay )
276
+ clock .Advance (testCfg . FailedBatchDelay )
300
277
}
301
278
require .Error (t , eg .Wait ())
302
279
}
@@ -309,7 +286,8 @@ func TestMultiEpochATXSyncer(t *testing.T) {
309
286
newCfg := sync2 .DefaultConfig ()
310
287
newCfg .MaxDepth = 24
311
288
hss := NewMockHashSyncSource (ctrl )
312
- mhs := sync2 .NewMultiEpochATXSyncer (logger , hss , oldCfg , newCfg , 1 )
289
+ mhs , err := sync2 .NewMultiEpochATXSyncer (logger , hss , oldCfg , newCfg , 1 )
290
+ require .NoError (t , err )
313
291
ctx := context .Background ()
314
292
315
293
lastSynced , err := mhs .EnsureSync (ctx , 0 , 0 )
@@ -319,7 +297,7 @@ func TestMultiEpochATXSyncer(t *testing.T) {
319
297
var syncActions []string
320
298
curIdx := 0
321
299
hss .EXPECT ().CreateHashSync (gomock .Any (), gomock .Any (), gomock .Any ()).DoAndReturn (
322
- func (name string , cfg sync2.Config , epoch types.EpochID ) sync2.HashSync {
300
+ func (name string , cfg sync2.Config , epoch types.EpochID ) ( sync2.HashSync , error ) {
323
301
idx := curIdx
324
302
curIdx ++
325
303
syncActions = append (syncActions ,
@@ -339,7 +317,7 @@ func TestMultiEpochATXSyncer(t *testing.T) {
339
317
hs .EXPECT ().Stop ().DoAndReturn (func () {
340
318
syncActions = append (syncActions , fmt .Sprintf ("stop %d %s" , idx , name ))
341
319
}).AnyTimes ()
342
- return hs
320
+ return hs , nil
343
321
}).AnyTimes ()
344
322
345
323
// Last wait epoch 3, new epoch 3
0 commit comments