-
Notifications
You must be signed in to change notification settings - Fork 6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add test cases for Loader #21
Conversation
|
||
#[derive(Debug)] | ||
/// Note: Give desired implementations if needed. | ||
struct NullIo(ClusterConfig); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
NullIo
は削除して、まともにテストで使えるように TestIo
として再実装。
} | ||
|
||
#[test] | ||
fn it_fails_if_log_suffix_contains_older_term() -> TestResult { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
#18 を再現させるテストコード。
} else { | ||
false | ||
} | ||
self.role.is_loader() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
コードを整理して、触ったコードに関わる箇所はテストを追加。
logs: Arc<Mutex<HashMap<(LogIndex, Option<LogIndex>), Log>>>, | ||
} | ||
|
||
impl TestIoHandle { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
何がテストに必要なのか分かっていない部分が多いので、ブラッシュアップしていく前提で一旦あると便利な機能を追加。Io
の所有権を放棄した上で細かくテストシナリオを操作できるように Handle を実装してます。
/// `LoadBallot` でロードされる。 | ||
pub ballots: Arc<Mutex<Vec<Ballot>>>, | ||
/// `LoadLog` でロードされる。 | ||
pub logs: Arc<Mutex<HashMap<(LogIndex, Option<LogIndex>), Log>>>, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
あらかじめ Log や Ballot を仕込んでおき、それらを run_once
で上手くロードさせるようにコントロールしながらテストしていく方針。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
テストコードの追加が主であることと、既存部分の変更についても問題がないと思うのでマージします。
テスト用の Io 実装とそれを使ったテストを追加。