Skip to content

Commit

Permalink
add bulk test
Browse files Browse the repository at this point in the history
  • Loading branch information
Frando committed Oct 11, 2023
1 parent b6de02b commit fd0320d
Showing 1 changed file with 88 additions and 0 deletions.
88 changes: 88 additions & 0 deletions iroh/tests/sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,94 @@ async fn sync_subscribe_no_sync() -> Result<()> {
Ok(())
}

#[tokio::test]
async fn sync_gossip_bulk() -> Result<()> {
let n_entries: usize = std::env::var("N_ENTRIES")
.map(|x| x.parse().expect("N_ENTRIES must be a number"))
.unwrap_or(1000);
let mut rng = test_rng(b"sync_gossip_bulk");
setup_logging();

let rt = test_runtime();
let nodes = spawn_nodes(rt.clone(), 2, &mut rng).await?;
let clients = nodes.iter().map(|node| node.client()).collect::<Vec<_>>();

let peer0 = nodes[0].peer_id();
let author0 = clients[0].authors.create().await?;
let doc0 = clients[0].docs.create().await?;
let ticket = doc0.share(ShareMode::Write).await?;
doc0.stop_sync().await?;

let doc1 = clients[1].docs.import(ticket).await?;
let mut events = doc1.subscribe().await?;
doc1.stop_sync().await?;

// create entries for initial sync.
let now = Instant::now();
let value = b"foo";
for i in 0..n_entries {
let key = format!("init/{i}");
doc0.set_bytes(author0, key.as_bytes().to_vec(), value.to_vec())
.await?;
}
let elapsed = now.elapsed();
info!(
"insert took {elapsed:?} for {n_entries} ({:?} per entry)",
elapsed / n_entries as u32
);

let now = Instant::now();
let mut count = 0;
let _ticket = doc0.share(ShareMode::Write).await?;
doc1.start_sync(vec![PeerAddr::new(peer0)]).await?;
while let Some(event) = events.next().await {
let event = event?;
if matches!(event, LiveEvent::InsertRemote { .. }) {
count += 1;
}
if count == n_entries {
break;
}
}
let elapsed = now.elapsed();
info!(
"initial sync took {elapsed:?} for {n_entries} ({:?} per entry)",
elapsed / n_entries as u32
);

// publish another 1000 entries
let mut count = 0;
let value = b"foo";
let now = Instant::now();
for i in 0..n_entries {
let key = format!("gossip/{i}");
doc0.set_bytes(author0, key.as_bytes().to_vec(), value.to_vec())
.await?;
}
let elapsed = now.elapsed();
info!(
"insert took {elapsed:?} for {n_entries} ({:?} per entry)",
elapsed / n_entries as u32
);

while let Some(event) = events.next().await {
let event = event?;
if matches!(event, LiveEvent::InsertRemote { .. }) {
count += 1;
}
if count == n_entries {
break;
}
}
let elapsed = now.elapsed();
info!(
"gossip recv took {elapsed:?} for {n_entries} ({:?} per entry)",
elapsed / n_entries as u32
);

Ok(())
}

/// This tests basic sync and gossip with 3 peers.
#[tokio::test]
async fn sync_full_basic() -> Result<()> {
Expand Down

0 comments on commit fd0320d

Please sign in to comment.