testkit_async/lib.rs
1//! # testkit-async 🧰
2//!
3//! > Practical testing tools for async Rust
4//!
5//! **testkit-async** provides time control, deterministic execution, and failure
6//! injection to make async testing fast, reliable, and easy.
7//!
8//! ## Quick Start
9//!
10//! ```rust,ignore
11//! use testkit_async::prelude::*;
12//!
13//! #[testkit_async::test]
14//! async fn test_with_timeout() {
15//! let clock = MockClock::new();
16//!
17//! let future = timeout(Duration::from_secs(30), operation());
18//! clock.advance(Duration::from_secs(31));
19//!
20//! assert!(future.await.is_err()); // Instant test!
21//! }
22//! ```
23//!
24//! ## Features
25//!
26//! - ⏱️ **Mock Clock** - Control time without waiting
27//! - 🎮 **Deterministic Executor** - Control task execution order
28//! - 💥 **Failure Injection** - Simulate errors and timeouts
29//! - 🔍 **Async Assertions** - Fluent testing API
30//! - 🎯 **Sync Points** - Coordinate multiple tasks
31
32#![warn(missing_docs)]
33#![warn(clippy::all)]
34#![warn(clippy::pedantic)]
35#![allow(clippy::module_name_repetitions)]
36
37/// Mock clock for time control in tests
38pub mod clock {
39 //! Virtual time control for async tests
40}
41
42/// Test executor with deterministic execution
43pub mod executor {
44 //! Controlled async task execution
45}
46
47/// Failure injection and chaos engineering
48pub mod chaos {
49 //! Simulate failures, timeouts, and errors
50}
51
52/// Async assertions and test helpers
53pub mod assertions {
54 //! Fluent assertions for async code
55}
56
57/// Synchronization primitives for tests
58pub mod sync {
59 //! Sync points and coordination helpers
60}
61
62/// Mock trait helpers
63pub mod mock {
64 //! Utilities for mocking async traits
65}
66
67/// Error types
68pub mod error {
69 //! Error definitions
70
71 use thiserror::Error;
72
73 /// Main error type for testkit-async
74 #[derive(Error, Debug)]
75 pub enum Error {
76 /// Timeout error
77 #[error("Operation timed out after {0:?}")]
78 Timeout(std::time::Duration),
79
80 /// Assertion failed
81 #[error("Assertion failed: {0}")]
82 AssertionFailed(String),
83
84 /// Mock error
85 #[error("Mock error: {0}")]
86 Mock(String),
87 }
88
89 /// Result type alias
90 pub type Result<T> = std::result::Result<T, Error>;
91}
92
93/// Prelude for convenient imports
94pub mod prelude {
95 //! Convenient re-exports
96 //!
97 //! ```rust
98 //! use testkit_async::prelude::*;
99 //! ```
100
101 pub use crate::clock::*;
102 pub use crate::executor::*;
103 pub use crate::chaos::*;
104 pub use crate::assertions::*;
105 pub use crate::sync::*;
106 pub use crate::error::{Error, Result};
107
108 // Re-export macros if available
109 #[cfg(feature = "macros")]
110 pub use testkit_async_macros::test;
111}
112
113// Re-exports
114pub use error::{Error, Result};
115
116#[cfg(test)]
117mod tests {
118 use super::*;
119
120 #[test]
121 fn test_placeholder() {
122 // Placeholder test
123 assert_eq!(2 + 2, 4);
124 }
125}