each test needs a unique socket to not error
This commit is contained in:
parent
2d3d27fbfb
commit
ebbc4ff5f9
1 changed files with 7 additions and 8 deletions
|
@ -5,20 +5,18 @@ use std::time::Duration;
|
|||
|
||||
use crate::{SERVER_ADDRESS, modules::socket_handler::Socket};
|
||||
|
||||
|
||||
|
||||
#[test]
|
||||
fn can_make_socket_listener(){
|
||||
let listener = Socket::make_listener(SERVER_ADDRESS);
|
||||
let listener = Socket::make_listener("localhost:5001");
|
||||
drop(listener);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn create_and_connect_to_listener() {
|
||||
let listener = Socket::make_listener(SERVER_ADDRESS);
|
||||
let listener = Socket::make_listener("localhost:5002");
|
||||
|
||||
let join_handle = std::thread::spawn(move || {
|
||||
let _outgoing = std::net::TcpStream::connect(SERVER_ADDRESS).unwrap();
|
||||
let _outgoing = std::net::TcpStream::connect("localhost:5002").unwrap();
|
||||
});
|
||||
join_handle.join().unwrap();
|
||||
drop(listener);
|
||||
|
@ -27,19 +25,20 @@ fn create_and_connect_to_listener() {
|
|||
#[test]
|
||||
#[should_panic]
|
||||
fn panic_no_listener() {
|
||||
let _outgoing = std::net::TcpStream::connect("localhost").unwrap();
|
||||
let _outgoing = std::net::TcpStream::connect("localhost:5003").unwrap();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn can_handle_messages() {
|
||||
let listener = Socket::make_listener(SERVER_ADDRESS);
|
||||
let listener = Socket::make_listener("localhost:5004");
|
||||
let (tx_1, rx_1) = mpsc::channel::<String>();
|
||||
|
||||
let (mut flag, connection_handle) = Socket::handle_connections(listener, tx_1);
|
||||
|
||||
let join_handle = std::thread::spawn(move || {
|
||||
let mut outgoing = std::net::TcpStream::connect(SERVER_ADDRESS).unwrap();
|
||||
let mut outgoing = std::net::TcpStream::connect("localhost:5004").unwrap();
|
||||
outgoing.write("this is a test".as_bytes()).unwrap();
|
||||
drop(outgoing);
|
||||
});
|
||||
join_handle.join().unwrap();
|
||||
thread::sleep(Duration::from_millis(1000));
|
||||
|
|
Loading…
Reference in a new issue