MCPcopy
hub / github.com/chaozh/MIT-6.824 / TestReElection2A

Function TestReElection2A

src/raft/test_test.go:53–87  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

51}
52
53func TestReElection2A(t *testing.T) {
54 servers := 3
55 cfg := make_config(t, servers, false, false)
56 defer cfg.cleanup()
57
58 cfg.begin("Test (2A): election after network failure")
59
60 leader1 := cfg.checkOneLeader()
61
62 // if the leader disconnects, a new one should be elected.
63 cfg.disconnect(leader1)
64 cfg.checkOneLeader()
65
66 // if the old leader rejoins, that shouldn't
67 // disturb the new leader.
68 cfg.connect(leader1)
69 leader2 := cfg.checkOneLeader()
70
71 // if there's no quorum, no leader should
72 // be elected.
73 cfg.disconnect(leader2)
74 cfg.disconnect((leader2 + 1) % servers)
75 time.Sleep(2 * RaftElectionTimeout)
76 cfg.checkNoLeader()
77
78 // if a quorum arises, it should elect a leader.
79 cfg.connect((leader2 + 1) % servers)
80 cfg.checkOneLeader()
81
82 // re-join of last node shouldn't prevent leader from existing.
83 cfg.connect(leader2)
84 cfg.checkOneLeader()
85
86 cfg.end()
87}
88
89func TestManyElections2A(t *testing.T) {
90 servers := 7

Callers

nothing calls this directly

Calls 8

checkOneLeaderMethod · 0.80
checkNoLeaderMethod · 0.80
make_configFunction · 0.70
cleanupMethod · 0.45
beginMethod · 0.45
disconnectMethod · 0.45
connectMethod · 0.45
endMethod · 0.45

Tested by

no test coverage detected