Skip to content

Commit

Permalink
Write a test for {import,write}_verifiable_stream
Browse files Browse the repository at this point in the history
  • Loading branch information
matheus23 committed Dec 12, 2024
1 parent 51f5707 commit f20b260
Showing 1 changed file with 34 additions and 2 deletions.
36 changes: 34 additions & 2 deletions src/store/fs/tests.rs
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
use std::io::Cursor;

use bao_tree::ChunkRanges;
use bytes::BytesMut;
use iroh_io::AsyncSliceReaderExt;

use crate::{
store::{
bao_file::test_support::{
decode_response_into_batch, make_wire_data, random_test_data, simulate_remote, validate,
},
Map as _, MapEntryMut, MapMut, ReadableStore, Store as _,
Map as _, MapEntry, MapEntryMut, MapMut, ReadableStore, Store as _, ValidateProgress,
},
util::raw_outboard,
util::{progress::AsyncChannelProgressSender, raw_outboard},
IROH_BLOCK_SIZE,
};

Expand Down Expand Up @@ -809,3 +810,34 @@ async fn actor_store_smoke() {
db.sync().await.unwrap();
db.dump().await.unwrap();
}

#[tokio::test]
async fn verifiable_stream_smoke() -> testresult::TestResult {
let db1 = crate::store::mem::Store::new();
let db2 = crate::store::mem::Store::new();

const SIZE: usize = 16 * 1024 * 1024;
let data = random_test_data(SIZE);
let tag = db1.import_bytes(Bytes::from(data), BlobFormat::Raw).await?;
let mut buffer = BytesMut::with_capacity(SIZE + 1024 * 1024);
let entry = db1.get(tag.hash()).await?.expect("We just wrote this hash");

entry.write_verifiable_stream(0, &mut buffer).await?;

db2.import_verifiable_stream(*tag.hash(), SIZE as u64, 0, buffer.freeze())
.await?;

let (tx, rx) = async_channel::bounded(128);
let handle = tokio::spawn(async move {
while let Ok(progress) = rx.recv().await {
if let ValidateProgress::Abort(err) = progress {
panic!("Got an error: {err}");
}
}
});
db2.validate(false, AsyncChannelProgressSender::new(tx).boxed())
.await?;
handle.await?;

Ok(())
}

0 comments on commit f20b260

Please sign in to comment.