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
1546be28
Commit
1546be28
authored
Nov 18, 2015
by
Willem Thiart
Browse files
Add timeout when receiving requestvote
parent
271f0809
Changes
2
Hide whitespace changes
Inline
Side-by-side
src/raft_server.c
View file @
1546be28
...
...
@@ -412,6 +412,8 @@ int raft_recv_requestvote(raft_server_t* me_,
/* there must be in an election. */
me
->
current_leader
=
-
1
;
me
->
timeout_elapsed
=
0
;
}
else
r
->
vote_granted
=
0
;
...
...
tests/test_server.c
View file @
1546be28
...
...
@@ -520,6 +520,29 @@ void TestRaft_server_recv_requestvote_reply_true_if_term_greater_than_or_equal_t
CuAssertTrue
(
tc
,
1
==
rvr
.
vote_granted
);
}
void
TestRaft_server_recv_requestvote_reset_timeout
(
CuTest
*
tc
)
{
msg_requestvote_t
rv
;
msg_requestvote_response_t
rvr
;
void
*
r
=
raft_new
();
raft_add_node
(
r
,
(
void
*
)
1
,
1
);
raft_add_node
(
r
,
(
void
*
)
2
,
0
);
raft_set_current_term
(
r
,
1
);
raft_set_election_timeout
(
r
,
1000
);
raft_periodic
(
r
,
900
);
memset
(
&
rv
,
0
,
sizeof
(
msg_requestvote_t
));
rv
.
term
=
2
;
rv
.
last_log_idx
=
1
;
raft_recv_requestvote
(
r
,
1
,
&
rv
,
&
rvr
);
CuAssertTrue
(
tc
,
1
==
rvr
.
vote_granted
);
CuAssertIntEquals
(
tc
,
0
,
raft_get_timeout_elapsed
(
r
));
}
void
TestRaft_server_recv_requestvote_candidate_step_down_if_term_is_higher_than_current_term
(
CuTest
*
tc
)
...
...
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