mirror of
https://github.com/Xevion/banner.git
synced 2025-12-07 18:06:22 -06:00
Add comprehensive ESLint setup with React and TypeScript support, create basic integration tests for the shutdown utilities, and enhance the Justfile with a new check command that runs all validation steps (cargo check, clippy, tests, and linting).
34 lines
1.3 KiB
Rust
34 lines
1.3 KiB
Rust
use banner::utils::shutdown::join_tasks;
|
|
use tokio::task::JoinHandle;
|
|
|
|
#[tokio::test]
|
|
async fn test_join_tasks_success() {
|
|
// Create some tasks that complete successfully
|
|
let handles: Vec<JoinHandle<()>> = vec![
|
|
tokio::spawn(async { tokio::time::sleep(tokio::time::Duration::from_millis(10)).await }),
|
|
tokio::spawn(async { tokio::time::sleep(tokio::time::Duration::from_millis(20)).await }),
|
|
tokio::spawn(async { /* immediate completion */ }),
|
|
];
|
|
|
|
// All tasks should complete successfully
|
|
let result = join_tasks(handles).await;
|
|
assert!(result.is_ok(), "Expected all tasks to complete successfully");
|
|
}
|
|
|
|
#[tokio::test]
|
|
async fn test_join_tasks_with_panic() {
|
|
// Create some tasks, including one that panics
|
|
let handles: Vec<JoinHandle<()>> = vec![
|
|
tokio::spawn(async { tokio::time::sleep(tokio::time::Duration::from_millis(10)).await }),
|
|
tokio::spawn(async { panic!("intentional test panic") }),
|
|
tokio::spawn(async { /* immediate completion */ }),
|
|
];
|
|
|
|
// Should return an error because one task panicked
|
|
let result = join_tasks(handles).await;
|
|
assert!(result.is_err(), "Expected an error when a task panics");
|
|
|
|
let error_msg = result.unwrap_err().to_string();
|
|
assert!(error_msg.contains("1 task(s) panicked"), "Error message should mention panicked tasks");
|
|
}
|