Skip to content

Commit

Permalink
[Safety rules] Use rusty fork to avoid metrics collision.
Browse files Browse the repository at this point in the history
  • Loading branch information
JoshLind authored and aptos-bot committed Apr 30, 2022
1 parent a58a871 commit c68e565
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 15 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions consensus/safety-rules/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ thiserror = "1.0.24"
criterion = "0.3.4"
tempfile = "3.2.0"
proptest = "1.0.0"
rusty-fork = "0.3.0"

consensus-types = { path = "../consensus-types", features = ["fuzzing"] }
aptos-config = { path = "../../config", features = ["fuzzing"] }
Expand Down
35 changes: 20 additions & 15 deletions consensus/safety-rules/src/persistent_safety_storage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -201,22 +201,27 @@ mod tests {
block_info::BlockInfo, epoch_state::EpochState, ledger_info::LedgerInfo,
transaction::Version, validator_signer::ValidatorSigner, waypoint::Waypoint,
};
use rusty_fork::rusty_fork_test;

#[test]
fn test_counters() {
let consensus_private_key = ValidatorSigner::from_int(0).private_key().clone();
let storage = Storage::from(InMemoryStorage::new());
let mut safety_storage = PersistentSafetyStorage::initialize(
storage,
Author::random(),
consensus_private_key,
Ed25519PrivateKey::generate_for_testing(),
Waypoint::default(),
true,
);
// they both touch the global counters, running it serially to prevent race condition.
test_safety_data_counters(&mut safety_storage);
test_waypoint_counters(&mut safety_storage);
// Metrics are globally instantiated. We use rusty_fork to prevent concurrent tests
// from interfering with the metrics while we run this test.
rusty_fork_test! {
#[test]
fn test_counters() {
let consensus_private_key = ValidatorSigner::from_int(0).private_key().clone();
let storage = Storage::from(InMemoryStorage::new());
let mut safety_storage = PersistentSafetyStorage::initialize(
storage,
Author::random(),
consensus_private_key,
Ed25519PrivateKey::generate_for_testing(),
Waypoint::default(),
true,
);
// they both touch the global counters, running it serially to prevent race condition.
test_safety_data_counters(&mut safety_storage);
test_waypoint_counters(&mut safety_storage);
}
}

fn test_safety_data_counters(safety_storage: &mut PersistentSafetyStorage) {
Expand Down

0 comments on commit c68e565

Please sign in to comment.