Skip to content
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

Merged
merged 4 commits into from
Mar 6, 2019
Merged

Add test cases for Loader #21

merged 4 commits into from
Mar 6, 2019

Conversation

shinnya
Copy link
Contributor

@shinnya shinnya commented Mar 5, 2019

テスト用の Io 実装とそれを使ったテストを追加。

@shinnya shinnya mentioned this pull request Mar 5, 2019
@shinnya shinnya marked this pull request as ready for review March 5, 2019 06:20

#[derive(Debug)]
/// Note: Give desired implementations if needed.
struct NullIo(ClusterConfig);
Copy link
Contributor Author

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 {
Copy link
Contributor Author

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()
Copy link
Contributor Author

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 {
Copy link
Contributor Author

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>>>,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

あらかじめ Log や Ballot を仕込んでおき、それらを run_once で上手くロードさせるようにコントロールしながらテストしていく方針。

Copy link
Member

@yuezato yuezato left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

テストコードの追加が主であることと、既存部分の変更についても問題がないと思うのでマージします。

@yuezato yuezato merged commit 3ebb628 into frugalos:master Mar 6, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants