Skip to content

Commit

Permalink
Test less random.
Browse files Browse the repository at this point in the history
  • Loading branch information
John-LittleBearLabs committed Aug 8, 2023
1 parent 10b7f79 commit 75d2f39
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 6 deletions.
1 change: 1 addition & 0 deletions .idea/space.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 5 additions & 5 deletions myceli/tests/utils/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use assert_fs::{fixture::FileWriteBin, fixture::PathChild, TempDir};
use blake2::{Blake2s256, Digest};
use file_hashing::get_hash_file;
use myceli::listener::Listener;
use rand::{thread_rng, Rng, RngCore};
use rand::{rngs::StdRng, thread_rng, Rng, RngCore, SeedableRng};
use std::net::{SocketAddr, ToSocketAddrs};
use std::path::PathBuf;
use std::sync::Arc;
Expand Down Expand Up @@ -38,7 +38,7 @@ pub fn wait_receiving_done(receiver: &TestListener, controller: &mut TestControl
}
num_retries += 1;
}
sleep(Duration::from_millis(10));
sleep(Duration::from_millis(num_retries * num_retries + 1));
}
}

Expand All @@ -50,8 +50,7 @@ pub struct TestListener {
impl TestListener {
pub fn new() -> TestListener {
let test_dir = TempDir::new().unwrap();
let mut rng = thread_rng();
let port_num = rng.gen_range(6000..9000);
let port_num = thread_rng().gen_range(6000..9000);
let listen_addr = format!("127.0.0.1:{port_num}");

TestListener {
Expand Down Expand Up @@ -79,7 +78,8 @@ impl TestListener {
pub fn generate_file(&self) -> Result<String> {
let mut data = Vec::<u8>::new();
data.resize(256 * 50, 1);
thread_rng().fill_bytes(&mut data);
let mut rng = StdRng::seed_from_u64(2);
rng.fill_bytes(&mut data);

let tmp_file = self.test_dir.child("test.file");
tmp_file.write_binary(&data)?;
Expand Down
3 changes: 2 additions & 1 deletion transports/src/udp_transport.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::udp_chunking::SimpleChunker;
use crate::{Transport, MAX_MTU};
use anyhow::{anyhow, bail, Result};
use log::debug;
use log::{debug, info};
use messages::Message;
use std::net::{ToSocketAddrs, UdpSocket};
use std::sync::{Arc, Mutex};
Expand All @@ -17,6 +17,7 @@ pub struct UdpTransport {

impl UdpTransport {
pub fn new(listen_addr: &str, mtu: u16, chunk_transmit_throttle: Option<u32>) -> Result<Self> {
info!("Will listen on {}", &listen_addr);
let socket = UdpSocket::bind(listen_addr)?;
Ok(UdpTransport {
socket,
Expand Down

0 comments on commit 75d2f39

Please sign in to comment.