Skip to content

Commit

Permalink
test: avoid file system
Browse files Browse the repository at this point in the history
  • Loading branch information
dignifiedquire committed Jan 18, 2023
1 parent 1dd46e9 commit dc2fe24
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,27 +40,28 @@ mod tests {
async fn multiple_clients() -> Result<()> {
let dir: PathBuf = testdir!();
let path = dir.join("hello_world");
tokio::fs::write(&path, "hello world!").await?;
let content = b"hello world!";

tokio::fs::write(&path, content).await?;
let db = server::create_db(vec![&path]).await?;
let hash = *db.iter().next().unwrap().0;
tokio::task::spawn(async move {
server::run(db, Default::default()).await.unwrap();
});

async fn run_client(hash: bao::Hash, path: PathBuf) -> Result<()> {
async fn run_client(hash: bao::Hash, content: Vec<u8>) -> Result<()> {
let opts = client::Options::default();
let (mut source, sink) = tokio::io::duplex(1024);
client::run(hash, opts, sink).await?;
let expect = tokio::fs::read(path).await?;
let mut got = Vec::new();
source.read_to_end(&mut got).await?;
assert_eq!(expect, got);
assert_eq!(content, got);
Ok(())
}

let mut tasks = Vec::new();
for _i in 0..3 {
tasks.push(tokio::task::spawn(run_client(hash, path.clone())));
tasks.push(tokio::task::spawn(run_client(hash, content.to_vec())));
}

for task in tasks {
Expand Down

0 comments on commit dc2fe24

Please sign in to comment.