@@ -2443,48 +2443,41 @@ var _ = Describe("Chain", func() {
2443
2443
2444
2444
It ("lagged node can catch up using snapshot" , func () {
2445
2445
network .disconnect (2 )
2446
-
2447
2446
c1 .cutter .CutNext = true
2448
2447
2449
- var lasti uint64
2450
- var indices []uint64
2451
- // Only produce 4 blocks here, so that snapshot pruning does not occur.
2452
- // Otherwise, a slow garbage collection may prevent snapshotting from
2453
- // being triggered on next block, and assertion on number of snapshots
2454
- // would fail nondeterministically.
2455
- for i := 1 ; i <= 4 ; i ++ {
2456
- err := c1 .Order (env , 0 )
2457
- Expect (err ).NotTo (HaveOccurred ())
2458
- Eventually (c1 .support .WriteBlockCallCount , LongEventualTimeout ).Should (Equal (i ))
2459
- Eventually (c3 .support .WriteBlockCallCount , LongEventualTimeout ).Should (Equal (i ))
2460
- Eventually (func () uint64 {
2461
- indices = etcdraft .ListSnapshots (logger , c1 .opts .SnapDir )
2462
- if len (indices ) == 0 {
2463
- return 0
2464
- }
2465
- return indices [len (indices )- 1 ]
2466
- }, LongEventualTimeout ).Should (BeNumerically (">" , lasti ))
2467
- lasti = indices [len (indices )- 1 ]
2468
- }
2448
+ c2Lasti , _ := c2 .opts .MemoryStorage .LastIndex ()
2449
+ var blockCnt int
2450
+ // Order blocks until first index of c1 memory is greater than last index of c2,
2451
+ // so a snapshot will be sent to c2 when it rejoins network
2452
+ Eventually (func () bool {
2453
+ c1Firsti , _ := c1 .opts .MemoryStorage .FirstIndex ()
2454
+ if c1Firsti > c2Lasti + 1 {
2455
+ return true
2456
+ }
2457
+
2458
+ Expect (c1 .Order (env , 0 )).To (Succeed ())
2459
+ blockCnt ++
2460
+ Eventually (c1 .support .WriteBlockCallCount , LongEventualTimeout ).Should (Equal (blockCnt ))
2461
+ Eventually (c3 .support .WriteBlockCallCount , LongEventualTimeout ).Should (Equal (blockCnt ))
2462
+ return false
2463
+ }, LongEventualTimeout ).Should (BeTrue ())
2469
2464
2470
2465
Eventually (c2 .support .WriteBlockCallCount , LongEventualTimeout ).Should (Equal (0 ))
2471
2466
2472
2467
network .join (2 , false )
2473
2468
2474
- Eventually (c2 .puller .PullBlockCallCount , LongEventualTimeout ).Should (Equal (4 ))
2475
- Eventually (c2 .support .WriteBlockCallCount , LongEventualTimeout ).Should (Equal (4 ))
2476
-
2477
- files , err := ioutil .ReadDir (c2 .opts .SnapDir )
2478
- Expect (err ).NotTo (HaveOccurred ())
2479
- Expect (files ).To (HaveLen (1 )) // expect to store exact 1 snapshot
2469
+ Eventually (c2 .support .WriteBlockCallCount , LongEventualTimeout ).Should (Equal (blockCnt ))
2470
+ indices := etcdraft .ListSnapshots (logger , c2 .opts .SnapDir )
2471
+ Expect (indices ).To (HaveLen (1 ))
2472
+ gap := indices [0 ] - c2Lasti
2473
+ Expect (c2 .puller .PullBlockCallCount ()).To (Equal (int (gap )))
2480
2474
2481
2475
// chain should keeps functioning
2482
- err = c1 .Order (env , 0 )
2483
- Expect (err ).NotTo (HaveOccurred ())
2476
+ Expect (c2 .Order (env , 0 )).To (Succeed ())
2484
2477
2485
2478
network .exec (
2486
2479
func (c * chain ) {
2487
- Eventually (func () int { return c .support .WriteBlockCallCount () }, LongEventualTimeout ).Should (Equal (5 ))
2480
+ Eventually (func () int { return c .support .WriteBlockCallCount () }, LongEventualTimeout ).Should (Equal (blockCnt + 1 ))
2488
2481
})
2489
2482
})
2490
2483
})
0 commit comments