Skip to content

Commit

Permalink
redownload_expired_blocks test: make reader replica blind
Browse files Browse the repository at this point in the history
The tests is faster that way and more focused.
  • Loading branch information
inetic committed Sep 5, 2023
1 parent cdf6f01 commit 45a36c9
Showing 1 changed file with 14 additions and 12 deletions.
26 changes: 14 additions & 12 deletions lib/tests/sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -986,14 +986,21 @@ fn redownload_expired_blocks() {

let test_content = Arc::new(common::random_content(2 * 1024 * 1024));

async fn wait_for_block_count(repo: &Repository, block_count: u64) {
common::eventually(&repo, || {
async { repo.count_blocks().await.unwrap() == block_count }
.instrument(tracing::Span::current())
})
.await;
}

env.actor("origin", {
let test_content = test_content.clone();
async move {
let (_network, repo, _reg) = actor::setup().await;

// Create a file
let mut file = repo.create_file("test.txt").await.unwrap();
//file.write_all(b"test content").await.unwrap();
file.write_all(&test_content).await.unwrap();
file.flush().await.unwrap();

Expand All @@ -1013,16 +1020,11 @@ fn redownload_expired_blocks() {
let block_count = origin_has_it_rx.recv().await.unwrap();

let start = SystemTime::now();

network.add_user_provided_peer(&actor::lookup_addr("origin").await);

// Wait to have the blocks, this is a blind replica, so we can't check the file exists and
// has the required content.
common::eventually(&repo, || {
async { repo.count_blocks().await.unwrap() == block_count }
.instrument(tracing::Span::current())
})
.await;
wait_for_block_count(&repo, block_count).await;

let normal_sync_duration = SystemTime::now().duration_since(start).unwrap();

Expand All @@ -1037,7 +1039,7 @@ fn redownload_expired_blocks() {
sleep(3 * expiration_duration).await;

cache_had_it_tx
.send((normal_sync_duration, SystemTime::now()))
.send((block_count, normal_sync_duration))
.await
.unwrap();

Expand All @@ -1046,16 +1048,16 @@ fn redownload_expired_blocks() {

env.actor("reader", async move {
let network = actor::create_network(Proto::Tcp).await;
let repo = actor::create_repo_with_mode(DEFAULT_REPO, AccessMode::Read).await;
let repo = actor::create_repo_with_mode(DEFAULT_REPO, AccessMode::Blind).await;
let _reg = network.register(repo.handle()).await;

// Use `start` to measure how long it took to sync the data from the expired cache.
let (normal_sync_duration, start) = cache_had_it_rx.recv().await.unwrap();
let (block_count, normal_sync_duration) = cache_had_it_rx.recv().await.unwrap();

let start = SystemTime::now();
network.add_user_provided_peer(&actor::lookup_addr("cache").await);

common::expect_entry_exists(&repo, "test.txt", EntryType::File).await;
common::expect_file_content(&repo, "test.txt", &test_content).await;
wait_for_block_count(&repo, block_count).await;

let expired_sync_duration = SystemTime::now().duration_since(start).unwrap();

Expand Down

0 comments on commit 45a36c9

Please sign in to comment.