diff --git a/crates/librqbit/src/tests/e2e_stream.rs b/crates/librqbit/src/tests/e2e_stream.rs index 770f4d1..a2ab08e 100644 --- a/crates/librqbit/src/tests/e2e_stream.rs +++ b/crates/librqbit/src/tests/e2e_stream.rs @@ -5,7 +5,9 @@ use tempfile::TempDir; use tokio::{io::AsyncReadExt, time::timeout}; use tracing::info; -use crate::{create_torrent, AddTorrent, CreateTorrentOptions, Session}; +use crate::{ + create_torrent, tests::test_util::TestPeerMetadata, AddTorrent, CreateTorrentOptions, Session, +}; use super::test_util::create_default_random_dir_with_torrents; @@ -21,11 +23,11 @@ async fn e2e_stream() -> anyhow::Result<()> { .await?; let orig_content = std::fs::read(files.path().join("0.data")).unwrap(); - let server_session = Session::new_with_opts( files.path().into(), crate::SessionOptions { disable_dht: true, + peer_id: Some(TestPeerMetadata::good().as_peer_id()), persistence: false, listen_port_range: Some(16001..16100), enable_upnp_port_forwarding: false, @@ -71,6 +73,7 @@ async fn e2e_stream() -> anyhow::Result<()> { crate::SessionOptions { disable_dht: true, persistence: false, + peer_id: Some(TestPeerMetadata::good().as_peer_id()), listen_port_range: None, enable_upnp_port_forwarding: false, ..Default::default() diff --git a/crates/librqbit/src/tests/test_util.rs b/crates/librqbit/src/tests/test_util.rs index 4eba7a5..965658a 100644 --- a/crates/librqbit/src/tests/test_util.rs +++ b/crates/librqbit/src/tests/test_util.rs @@ -1,7 +1,7 @@ use std::{io::Write, path::Path}; use librqbit_core::Id20; -use rand::{RngCore, SeedableRng}; +use rand::{thread_rng, Rng, RngCore, SeedableRng}; use tempfile::TempDir; pub fn create_new_file_with_random_content(path: &Path, mut size: usize) { @@ -43,8 +43,16 @@ pub struct TestPeerMetadata { } impl TestPeerMetadata { + pub fn good() -> Self { + Self { + server_id: 0, + max_random_sleep_ms: 0, + } + } + pub fn as_peer_id(&self) -> Id20 { let mut peer_id = Id20::default(); + thread_rng().fill(&mut peer_id.0); peer_id.0[0] = self.server_id; peer_id.0[1] = self.max_random_sleep_ms; peer_id