Skip to content

Commit

Permalink
Bump to v0.4.3 (tikv#231)
Browse files Browse the repository at this point in the history
* raft: leader respond to learner read index message (tikv#220)

Signed-off-by: nolouch <nolouch@gmail.com>

* Bump to v0.4.3

Signed-off-by: Neil Shen <overvenus@gmail.com>
  • Loading branch information
overvenus authored and hicqu committed Jul 17, 2019
1 parent c4d0710 commit 0f59e7f
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -366,6 +366,7 @@ before taking old, removed peers offline.
*/

#![cfg_attr(not(feature = "cargo-clippy"), allow(unknown_lints))]
#![deny(clippy::all)]
#![deny(missing_docs)]
#![recursion_limit = "128"]
Expand Down
73 changes: 73 additions & 0 deletions tests/integration_cases/test_raft.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2265,6 +2265,79 @@ fn test_read_only_with_learner() {
}
}

#[test]
fn test_read_only_with_learner() {
setup_for_test();
let a = new_test_learner_raft(1, vec![1], vec![2], 10, 1, new_storage());
let b = new_test_learner_raft(2, vec![1], vec![2], 10, 1, new_storage());

let mut nt = Network::new(vec![Some(a), Some(b)]);

// we can not let system choose the value of randomizedElectionTimeout
// otherwise it will introduce some uncertainty into this test case
// we need to ensure randomizedElectionTimeout > electionTimeout here
let b_election_timeout = nt.peers[&2].get_election_timeout();
nt.peers
.get_mut(&2)
.unwrap()
.set_randomized_election_timeout(b_election_timeout + 1);

for _ in 0..b_election_timeout {
nt.peers.get_mut(&2).unwrap().tick();
}
nt.send(vec![new_message(1, 1, MessageType::MsgHup, 0)]);

assert_eq!(nt.peers[&1].state, StateRole::Leader);
assert_eq!(nt.peers[&2].state, StateRole::Follower);

let mut tests = vec![
(1, 10, 11, "ctx1"),
(2, 10, 21, "ctx2"),
(1, 10, 31, "ctx3"),
(2, 10, 41, "ctx4"),
];

for (i, (id, proposals, wri, wctx)) in tests.drain(..).enumerate() {
for _ in 0..proposals {
nt.send(vec![new_message(1, 1, MessageType::MsgPropose, 1)]);
}

let e = new_entry(0, 0, Some(wctx));
nt.send(vec![new_message_with_entries(
id,
id,
MessageType::MsgReadIndex,
vec![e],
)]);

let read_states: Vec<ReadState> = nt
.peers
.get_mut(&id)
.unwrap()
.read_states
.drain(..)
.collect();
assert_eq!(
read_states.is_empty(),
false,
"#{}: read_states is empty, want non-empty",
i
);
let rs = &read_states[0];
assert_eq!(
rs.index, wri,
"#{}: read_index = {}, want {}",
i, rs.index, wri
);
let vec_wctx = wctx.as_bytes().to_vec();
assert_eq!(
rs.request_ctx, vec_wctx,
"#{}: request_ctx = {:?}, want {:?}",
i, rs.request_ctx, vec_wctx
);
}
}

#[test]
fn test_read_only_option_lease() {
let l = testing_logger().new(o!("test" => "read_only_option_lease"));
Expand Down

0 comments on commit 0f59e7f

Please sign in to comment.