Skip to content

feat: import_verifiable_stream and write_verifiable_stream in Store #10

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 4 commits into from
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Write a test for {import,write}_verifiable_stream
  • Loading branch information
matheus23 committed Dec 12, 2024
commit f20b260ff326eadf6a581673e8624142ac01326e
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(())
}
Loading