mirror of
https://github.com/nukesor/pueue
synced 2024-10-03 06:23:55 +00:00
Fix all tests
This commit is contained in:
parent
484bbf7b15
commit
c3e0fd59e4
|
@ -43,18 +43,26 @@ pub fn default_pueue_path() -> Result<String> {
|
|||
mod tests {
|
||||
use super::*;
|
||||
|
||||
use std::fs::File;
|
||||
use std::fs::{remove_file, File};
|
||||
use std::io::prelude::*;
|
||||
|
||||
use anyhow::Result;
|
||||
|
||||
#[test]
|
||||
fn test_spawn_command() -> Result<()> {
|
||||
// Path can be found
|
||||
fn test_create_unix_socket() -> Result<()> {
|
||||
let path = get_unix_socket_path()?;
|
||||
|
||||
let mut file = File::create(path)?;
|
||||
file.write_all(b"Hello, world!")?;
|
||||
// If pueue is currently running on the system,
|
||||
// simply accept that we found the correct path
|
||||
if PathBuf::from(&path).exists() {
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
// Otherwise try to create it and write to it
|
||||
let mut file = File::create(&path)?;
|
||||
assert!(file.write_all(b"Hello, world!").is_ok());
|
||||
|
||||
remove_file(&path)?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
|
|
@ -13,7 +13,7 @@ use log::debug;
|
|||
use crate::message::*;
|
||||
|
||||
#[async_trait]
|
||||
pub trait GenericListener {
|
||||
pub trait GenericListener: Sync + Send {
|
||||
async fn accept<'a>(&'a self) -> Result<Box<dyn GenericSocket>>;
|
||||
}
|
||||
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
use anyhow::Result;
|
||||
use async_std::net::{TcpListener, TcpStream};
|
||||
use async_std::prelude::*;
|
||||
use async_std::task;
|
||||
|
||||
use pueue::message::{create_success_message, Message};
|
||||
|
@ -16,13 +15,14 @@ async fn test_single_huge_payload() -> Result<()> {
|
|||
let message = create_success_message(payload);
|
||||
let original_bytes = bincode::serialize(&message).expect("Failed to serialize message.");
|
||||
|
||||
let listener: Box<dyn GenericListener> = Box::new(listener);
|
||||
|
||||
// Spawn a sub thread that:
|
||||
// 1. Accepts a new connection
|
||||
// 2. Reads a message
|
||||
// 3. Sends the same message back
|
||||
task::spawn(async move {
|
||||
let mut incoming = listener.incoming();
|
||||
let mut socket = incoming.next().await.unwrap().unwrap();
|
||||
let mut socket = listener.accept().await.unwrap();
|
||||
let message_bytes = receive_bytes(&mut socket).await.unwrap();
|
||||
|
||||
let message: Message = bincode::deserialize(&message_bytes).unwrap();
|
||||
|
@ -30,7 +30,8 @@ async fn test_single_huge_payload() -> Result<()> {
|
|||
send_message(message, &mut socket).await.unwrap();
|
||||
});
|
||||
|
||||
let mut client = TcpStream::connect(&addr).await?;
|
||||
let mut client: Box<dyn GenericSocket> = Box::new(TcpStream::connect(&addr).await?);
|
||||
|
||||
// Create a client that sends a message and instantly receives it
|
||||
send_message(message, &mut client).await?;
|
||||
let response_bytes = receive_bytes(&mut client).await?;
|
||||
|
|
Loading…
Reference in a new issue