End-to-end unit test (#90)
* First implementation of create_torrent_file * Test harness for e2e preparing * Saving * Continuing test harness * Continuing test harness * Continuing test harness * All servers are running * Full e2e harness done * Test e2e harness working fine * Remove lints * injecting faults * The e2e test runs continuously * e2e test * Add a test for create_torrent * Nothing * Nothing, just tweaking the numberes * Update tokio, remove custom tempfile shim
This commit is contained in:
parent
5d6ecb8065
commit
2778d46bb3
13 changed files with 634 additions and 20 deletions
|
|
@ -181,7 +181,10 @@ impl<H: PeerConnectionHandler> PeerConnection<H> {
|
|||
.await
|
||||
.context("error reading handshake")?;
|
||||
let h_supports_extended = h.supports_extended();
|
||||
trace!("connected: id={:?}", try_decode_peer_id(Id20::new(h.peer_id)));
|
||||
trace!(
|
||||
"connected: id={:?}",
|
||||
try_decode_peer_id(Id20::new(h.peer_id))
|
||||
);
|
||||
if h.info_hash != self.info_hash.0 {
|
||||
anyhow::bail!("info hash does not match");
|
||||
}
|
||||
|
|
@ -269,6 +272,22 @@ impl<H: PeerConnectionHandler> PeerConnection<H> {
|
|||
.and_then(|e| e.ut_metadata())
|
||||
})?,
|
||||
WriterRequest::ReadChunkRequest(chunk) => {
|
||||
#[cfg(test)]
|
||||
{
|
||||
// This is poor-mans fault injection for running e2e tests.
|
||||
use crate::tests::test_util::TestPeerMetadata;
|
||||
let tpm = TestPeerMetadata::from_peer_id(self.peer_id);
|
||||
use rand::Rng;
|
||||
if rand::thread_rng().gen_bool(tpm.disconnect_probability()) {
|
||||
bail!("disconnecting, to simulate failure in tests");
|
||||
}
|
||||
|
||||
let sleep_ms = (rand::thread_rng().gen::<f64>()
|
||||
* (tpm.max_random_sleep_ms as f64))
|
||||
as u64;
|
||||
tokio::time::sleep(Duration::from_millis(sleep_ms)).await;
|
||||
}
|
||||
|
||||
// this whole section is an optimization
|
||||
write_buf.resize(PIECE_MESSAGE_DEFAULT_LEN, 0);
|
||||
let preamble_len = serialize_piece_preamble(chunk, &mut write_buf);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue