Skip to content

Commit

Permalink
Add test_long_chain_with_restart_from_snapshot (#10193)
Browse files Browse the repository at this point in the history
The main motivation for the test is to see how garbage collection will
behave without caches if we restart from the middle of an epoch.
  • Loading branch information
posvyatokum authored Nov 20, 2023
1 parent 956add9 commit d0a771d
Showing 1 changed file with 48 additions and 0 deletions.
48 changes: 48 additions & 0 deletions integration-tests/src/tests/client/process_blocks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3431,6 +3431,54 @@ fn test_catchup_no_sharding_change() {
}
}

/// Run `gc_num_epochs_to_keep` epochs + several blocks.
/// Start a second env from the "snapshot" of the first.
/// Run one more epoch.
/// "Restart from the snapshot" is to ensure that we can continue producing blocks without relying on caches.
#[test]
fn test_long_chain_with_restart_from_snapshot() {
init_test_logger();

let epoch_length = 25;

let mut genesis = Genesis::test(vec!["test0".parse().unwrap()], 1);

genesis.config.epoch_length = epoch_length;
let mut chain_genesis = ChainGenesis::test();
chain_genesis.epoch_length = epoch_length;
let mut env1 = TestEnv::builder(chain_genesis.clone())
.real_epoch_managers(&genesis.config)
.nightshade_runtimes(&genesis)
.archive(false)
.build();

// In TestEnv `gc_blocks_limit` defaults to 100.
// That means that whole epoch will be garbage collected in one block.
// We want this test to have "more realistic" snapshot setup, where last kept epoch is only partially garbage collected.
//
// `gc_blocks_limit = 2` is the default setup in production.
env1.clients[0].config.gc.gc_blocks_limit = 2;

let max_height = epoch_length * env1.clients[0].config.gc.gc_num_epochs_to_keep + 3;

for h in 1..max_height {
let block = env1.clients[0].produce_block(h).unwrap().unwrap();
env1.process_block(0, block.clone(), Provenance::PRODUCED);
}

let mut env2 = TestEnv::builder(chain_genesis)
.stores(vec![env1.clients[0].chain.store().store().clone()])
.real_epoch_managers(&genesis.config)
.nightshade_runtimes(&genesis)
.archive(false)
.build();

for h in max_height..(max_height + epoch_length) {
let block = env2.clients[0].produce_block(h).unwrap().unwrap();
env2.process_block(0, block.clone(), Provenance::PRODUCED);
}
}

/// These tests fail on aarch because the WasmtimeVM::precompile method doesn't populate the cache.
mod contract_precompilation_tests {
use super::*;
Expand Down

0 comments on commit d0a771d

Please sign in to comment.