Cargo test passed locally, but failed on github actions side

Hi community ! I have some tests on my local and some of them uses TCP connection. All tests passed on local, but almost all of them (except last) are failed on github actions side.

For running cargo test I use git hooks configured by rusty-hook crate. Just for test (in case this will help) I replaced cargo test with pre-commit = "cargo test -- --test-threads=1 --nocapture" inside rusty-hook config

Tests that failed are next:

#[tokio::test]
async fn test_client_connect() {
	let mut client = Client::new();
	if let Some(listener) = TcpListener::bind(format!("{}:{}", HOST, PORT)).await.ok() {
		let local_addr = listener.local_addr().unwrap();
		client.connect(HOST, local_addr.port()).await.ok();

		let reader = &mut *client.reader.lock().await;
		assert!(reader.is_some());

		let writer = &mut *client.writer.lock().await;
		assert!(writer.is_some());
	}
}

#[tokio::test]
async fn test_client_read_incoming_data() {
	let mut client = Client::new();
	if let Some(listener) = TcpListener::bind(format!("{}:{}", HOST, PORT)).await.ok() {
		let local_addr = listener.local_addr().unwrap();
		client.connect(HOST, local_addr.port()).await.ok();

		if let Some((mut stream, _)) = listener.accept().await.ok() {
			stream.write(&PACKET).await.unwrap();
			stream.flush().await.unwrap();
			client.handle_read().await;

			loop {
				if let Some(packet) = client.input_queue.lock().await.pop_front() {
					assert_eq!(PACKET.to_vec(), packet[0]);
					break;
				}
			}
		}
	}
}

#[tokio::test]
async fn test_client_write_outcoming_data() {
	let mut client = Client::new();
	if let Some(listener) = TcpListener::bind(format!("{}:{}", HOST, PORT)).await.ok() {
		let local_addr = listener.local_addr().unwrap();
		client.connect(HOST, local_addr.port()).await.ok();
		client.output_queue.lock().await.push_back(PACKET.to_vec());

		if let Some((stream, _)) = listener.accept().await.ok() {
			let buffer_size = PACKET.to_vec().len();
			let mut buffer = Vec::with_capacity(buffer_size);

			client.handle_write().await;
			stream.take(buffer_size as u64).read_to_end(&mut buffer).await.unwrap();

			assert_eq!(PACKET.to_vec(), buffer);
		}
	}
}

for HOST I use "127.0.0.1", for PORT I use 0 (zero).

Could somebody help to find how to fix tests on github actions side ?

The tests fail at

according to the panic message. You have a Config.yml.dist file checked in, but it seems that you don't write a Config.yml file anywhere before running the tests.

1 Like

oh, my fail. Thank you very much !

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.