Skip to content

Commit

Permalink
fix clippy error (#482)
Browse files Browse the repository at this point in the history
Signed-off-by: Jay Lee <[email protected]>
  • Loading branch information
BusyJay authored Jul 28, 2022
1 parent a9d37b7 commit 7293f8a
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 22 deletions.
10 changes: 7 additions & 3 deletions src/confchange/datadriven_test.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use std::fmt::Write;

use crate::{default_logger, Changer, ProgressTracker};
use datadriven::{run_test, walk};
use itertools::Itertools;
Expand Down Expand Up @@ -58,16 +60,18 @@ fn test_conf_change_data_driven() -> anyhow::Result<()> {
let mut buffer = String::new();

let conf = tr.conf();
buffer.push_str(&format!("{}\n", conf));
writeln!(buffer, "{}", conf).unwrap();

let prs = tr.progress();

// output with peer_id sorted
for (k, v) in prs.iter().sorted_by(|&(k1, _), &(k2, _)| k1.cmp(k2)) {
buffer.push_str(&format!(
write!(
buffer,
"{}: {} match={} next={}",
k, v.state, v.matched, v.next_idx
));
)
.unwrap();
if conf.learners.contains(k) {
buffer.push_str(" learner");
}
Expand Down
42 changes: 23 additions & 19 deletions src/quorum/datadriven_test.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use crate::quorum::{AckIndexer, AckedIndexer, Index};
use crate::{default_logger, HashMap, HashSet, JointConfig, MajorityConfig};
use datadriven::{run_test, TestData};
use std::fmt::Write;

fn test_quorum(data: &TestData) -> String {
// Two majority configs. The first one is always used (though it may
Expand Down Expand Up @@ -177,7 +178,7 @@ fn test_quorum(data: &TestData) -> String {
let a_idx = JointConfig::new_joint_from_majorities(cj, c)
.committed_index(use_group_commit, &l);
if a_idx != idx {
buf.push_str(&format!("{} <-- via symmetry\n", a_idx.0));
writeln!(buf, "{} <-- via symmetry", a_idx.0).unwrap();
}
} else {
idx = c.committed_index(use_group_commit, &l);
Expand All @@ -188,14 +189,14 @@ fn test_quorum(data: &TestData) -> String {
JointConfig::new_joint_from_majorities(c.clone(), MajorityConfig::default())
.committed_index(use_group_commit, &l);
if a_idx != idx {
buf.push_str(&format!("{} <-- via zero-joint quorum\n", a_idx.0));
writeln!(buf, "{} <-- via zero-joint quorum", a_idx.0).unwrap();
}

// Joining a majority with itself should give same result.
let a_idx = JointConfig::new_joint_from_majorities(c.clone(), c.clone())
.committed_index(use_group_commit, &l);
if a_idx != idx {
buf.push_str(&format!("{} <-- via self-joint quorum\n", a_idx.0));
writeln!(buf, "{} <-- via self-joint quorum", a_idx.0).unwrap();
}

// test overlaying
Expand All @@ -215,12 +216,14 @@ fn test_quorum(data: &TestData) -> String {

let a_idx = c.committed_index(use_group_commit, &l);
if a_idx != idx {
buf.push_str(&format!(
"{} <-- overlaying {}->{}\n",
writeln!(
buf,
"{} <-- overlaying {}->{}",
a_idx.0,
id,
iidx.index - 1
));
)
.unwrap();
}
// try 0
l.insert(
Expand All @@ -233,24 +236,23 @@ fn test_quorum(data: &TestData) -> String {

let a_idx = c.committed_index(use_group_commit, &l);
if a_idx != idx {
buf.push_str(&format!(
"{} <-- overlaying {}->{}\n",
a_idx.0, id, 0
));
writeln!(buf, "{} <-- overlaying {}->{}", a_idx.0, id, 0).unwrap();
}
// recovery
l.insert(id, iidx);
}
}
}
}
buf.push_str(&format!(
"{}\n",
writeln!(
buf,
"{}",
Index {
index: idx.0,
group_id: 0
}
));
)
.unwrap();
}
"group_committed" => {
let use_group_commit = true;
Expand All @@ -268,18 +270,20 @@ fn test_quorum(data: &TestData) -> String {
let a_idx = JointConfig::new_joint_from_majorities(cj, c)
.committed_index(use_group_commit, &l);
if a_idx != idx {
buf.push_str(&format!("{} <-- via symmetry\n", a_idx.0));
writeln!(buf, "{} <-- via symmetry", a_idx.0).unwrap();
}
} else {
// TODO: majority group commit
}
buf.push_str(&format!(
"{}\n",
writeln!(
buf,
"{}",
Index {
index: idx.0,
group_id: 0
}
));
)
.unwrap();
}
"vote" => {
let ll = make_lookuper(&votes, &ids, &idsj);
Expand All @@ -297,12 +301,12 @@ fn test_quorum(data: &TestData) -> String {
let ar = JointConfig::new_joint_from_majorities(cj, c)
.vote_result(|id| l.get(&id).cloned());
if ar != r {
buf.push_str(&format!("{} <-- via symmetry\n", ar));
writeln!(buf, "{} <-- via symmetry", ar).unwrap();
}
} else {
r = c.vote_result(|id| l.get(&id).cloned());
}
buf.push_str(&format!("{}\n", r));
writeln!(buf, "{}", r).unwrap();
}
_ => {
panic!("unknown command: {}", data.cmd);
Expand Down

0 comments on commit 7293f8a

Please sign in to comment.