Skip to content
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

Update e2e test to test deletion #202

Merged
merged 1 commit into from
Aug 19, 2024
Merged
Changes from all commits
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
40 changes: 34 additions & 6 deletions crates/librqbit/src/tests/e2e.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ use crate::{
tests::test_util::{
create_default_random_dir_with_torrents, spawn_debug_server, TestPeerMetadata,
},
AddTorrentOptions, AddTorrentResponse, Session, SessionOptions,
AddTorrentOptions, AddTorrentResponse, Session, SessionOptions, SessionPersistenceConfig,
};

#[tokio::test(flavor = "multi_thread", worker_threads = 64)]
Expand Down Expand Up @@ -86,7 +86,6 @@ async fn _test_e2e_download() {
disable_dht: true,
disable_dht_persistence: true,
dht_config: None,
persistence: None,
peer_id: Some(peer_id),
peer_opts: None,
listen_port_range: Some(listen_range),
Expand Down Expand Up @@ -176,14 +175,18 @@ async fn _test_e2e_download() {

// 3. Start a client with the initial peers, and download the file.
for _ in 0..client_iters {
let outdir = tempfile::TempDir::with_prefix("rqbit_e2e_client").unwrap();
let root = tempfile::TempDir::with_prefix("rqbit_e2e_client").unwrap();
let outdir = root.path().join("out");
let session_persistence = root.path().join("session");
let session = Session::new_with_opts(
outdir.path().to_owned(),
outdir.to_owned(),
SessionOptions {
disable_dht: true,
disable_dht_persistence: true,
dht_config: None,
persistence: None,
persistence: Some(SessionPersistenceConfig::Json {
folder: Some(session_persistence),
}),
listen_port_range: None,
enable_upnp_port_forwarding: false,
root_span: Some(error_span!("client")),
Expand Down Expand Up @@ -263,7 +266,12 @@ async fn _test_e2e_download() {
}

info!("handle is completed");
session.delete(id.into(), false).await.unwrap();
tokio::time::timeout(Duration::from_secs(5), session.delete(id.into(), false))
.await
.context("timeout deleting torrent")
.unwrap()
.context("error deleting")
.unwrap();

info!("deleted handle");

Expand Down Expand Up @@ -306,6 +314,26 @@ async fn _test_e2e_download() {
.await
.unwrap();

tokio::time::timeout(
Duration::from_secs(5),
session.delete(handle.id().into(), true),
)
.await
.context("timeout")
.unwrap()
.context("error deleting")
.unwrap();

// Ensure the files were deleted from the filesystem.
let d = std::fs::read_dir(&outdir)
.context("read_dir outdir")
.unwrap();
assert_eq!(
d.into_iter().count(),
0,
"{outdir:?} was not empty after deletion"
);

info!("all good");
}
}