Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
ruanhaishen
Willemt Raft
Commits
1a30fff7
Commit
1a30fff7
authored
Jun 11, 2016
by
Willem Thiart
Browse files
Fix: don't start election without voting nodes
parent
6d4bbcc0
Changes
2
Hide whitespace changes
Inline
Side-by-side
src/raft_server.c
View file @
1a30fff7
...
...
@@ -185,7 +185,8 @@ int raft_periodic(raft_server_t* me_, int msec_since_last_period)
}
else
if
(
me
->
election_timeout
<=
me
->
timeout_elapsed
)
{
if
(
1
<
me
->
num_nodes
)
if
(
1
<
raft_get_num_voting_nodes
(
me_
)
&&
raft_node_is_voting
(
raft_get_my_node
(
me_
)))
raft_election_start
(
me_
);
}
...
...
tests/test_server.c
View file @
1a30fff7
...
...
@@ -403,6 +403,32 @@ void TestRaft_server_election_timeout_does_not_promote_us_to_leader_if_there_is_
CuAssertTrue
(
tc
,
0
==
raft_is_leader
(
r
));
}
void
TestRaft_server_election_timeout_does_not_promote_us_to_leader_if_we_are_not_voting_node
(
CuTest
*
tc
)
{
void
*
r
=
raft_new
();
raft_add_non_voting_node
(
r
,
NULL
,
1
,
1
);
raft_set_election_timeout
(
r
,
1000
);
/* clock over (ie. 1000 + 1), causing new election */
raft_periodic
(
r
,
1001
);
CuAssertTrue
(
tc
,
0
==
raft_is_leader
(
r
));
CuAssertTrue
(
tc
,
0
==
raft_get_current_term
(
r
));
}
void
TestRaft_server_election_timeout_does_not_start_election_if_there_are_no_voting_nodes
(
CuTest
*
tc
)
{
void
*
r
=
raft_new
();
raft_add_non_voting_node
(
r
,
NULL
,
1
,
1
);
raft_add_non_voting_node
(
r
,
NULL
,
2
,
0
);
raft_set_election_timeout
(
r
,
1000
);
/* clock over (ie. 1000 + 1), causing new election */
raft_periodic
(
r
,
1001
);
CuAssertTrue
(
tc
,
0
==
raft_get_current_term
(
r
));
}
void
TestRaft_server_election_timeout_does_promote_us_to_leader_if_there_is_only_1_node
(
CuTest
*
tc
)
{
void
*
r
=
raft_new
();
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment