Skip to content

Commit 28a7012

Browse files
committed
FAB-15939 Fix Raft flake
Makes a Raft UT more lenient to fix flake. The flake happens when leader initiate leadership transfer too fast, that follower hasn't applied reconfig yet. In this case, follower will eventually be able to claim leadership after election timeout. Instead of asserting intermediate procedures, we could simply assert the final result - after certainly amount of ticks, the only remaining node in cluster will be able to elect itself. Change-Id: I9d5d3927e8234fc9070b4b9b61fa31e144838e6f Signed-off-by: Jay Guo <guojiannan1101@gmail.com>
1 parent c6a39fa commit 28a7012

File tree

1 file changed

+5
-6
lines changed

1 file changed

+5
-6
lines changed

orderer/consensus/etcdraft/chain_test.go

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1347,16 +1347,15 @@ var _ = Describe("Chain", func() {
13471347
It("can remove leader by reconfiguring cluster", func() {
13481348
network.elect(1)
13491349

1350-
n := c1.clock.WatcherCount()
1351-
13521350
By("Configuring cluster to remove node")
13531351
Expect(c1.Configure(configEnv, 0)).To(Succeed())
13541352
Eventually(c2.support.WriteConfigBlockCallCount, LongEventualTimeout).Should(Equal(1))
1355-
Eventually(c2.configurator.ConfigureCallCount, LongEventualTimeout).Should(Equal(2))
1353+
c1.clock.WaitForNWatchersAndIncrement(ELECTION_TICK*interval, 2)
13561354

1357-
c1.clock.WaitForNWatchersAndIncrement(time.Duration(ELECTION_TICK)*interval, n+1)
1358-
Eventually(c1.Chain.Errored, LongEventualTimeout).Should(BeClosed())
1359-
close(c1.stopped) // mark c1 stopped in network
1355+
Eventually(func() <-chan raft.SoftState {
1356+
c2.clock.Increment(interval)
1357+
return c2.observe
1358+
}, LongEventualTimeout).Should(Receive(StateEqual(2, raft.StateLeader)))
13601359

13611360
By("Asserting leader can still serve requests as single-node cluster")
13621361
c2.cutter.CutNext = true

0 commit comments

Comments
 (0)