Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,8 @@ members = [
"crates/apollo_task_executor",
"crates/apollo_test_utils",
"crates/apollo_time",
"crates/apollo_timed_tests",
"crates/apollo_timed_tests_macros",
"crates/bench_tools",
"crates/blockifier",
"crates/blockifier_reexecution",
Expand Down Expand Up @@ -200,6 +202,8 @@ apollo_storage.path = "crates/apollo_storage"
apollo_task_executor.path = "crates/apollo_task_executor"
apollo_test_utils.path = "crates/apollo_test_utils"
apollo_time.path = "crates/apollo_time"
apollo_timed_tests.path = "crates/apollo_timed_tests"
apollo_timed_tests_macros.path = "crates/apollo_timed_tests_macros"
ark-bls12-381 = "0.4.0"
ark-ec = "0.4.2"
ark-ff = "0.4.0-alpha.7"
Expand Down
18 changes: 18 additions & 0 deletions crates/apollo_timed_tests/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
[package]
name = "apollo_timed_tests"
version.workspace = true
edition.workspace = true
repository.workspace = true
license-file.workspace = true
description = "Timed test macros for the Apollo sequencer"

[dependencies]
apollo_timed_tests_macros.workspace = true
rstest.workspace = true

[dev-dependencies]
rstest.workspace = true
tokio = { workspace = true, features = ["macros", "rt", "time"] }

[lints]
workspace = true
31 changes: 31 additions & 0 deletions crates/apollo_timed_tests/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
//! Timed test macros for the Apollo sequencer.
//!
//! This crate provides procedural macros for creating tests that fail if they exceed a time limit.
//!
//! # Usage
//!
//! ```rust,ignore
//! use apollo_timed_tests::{timed_test, timed_tokio_test, timed_rstest, timed_rstest_tokio};
//!
//! #[timed_test]
//! fn my_test() {
//! // test code
//! }
//!
//! #[timed_tokio_test]
//! async fn my_async_test() {
//! // test code
//! }
//! ```

// Re-export rstest so users don't need to import it explicitly
// Note: Proc macros like rstest, case, and fixture must be imported from the crate:
// `use apollo_timed_tests::rstest;` then use `#[rstest::rstest]`, `#[rstest::case]`, etc.
// Or import directly: `use apollo_timed_tests::rstest::{rstest, case, fixture};`
pub use apollo_timed_tests_macros::{
timed_rstest,
timed_rstest_tokio,
timed_test,
timed_tokio_test,
};
pub use rstest;
120 changes: 120 additions & 0 deletions crates/apollo_timed_tests/tests/timed_test.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
use std::thread;
use std::time::Duration;

use apollo_timed_tests::{timed_rstest, timed_rstest_tokio, timed_test, timed_tokio_test};

// Test basic timed_test macro
#[timed_test]
fn test_fast_sync_test() {
assert_eq!(1 + 1, 2);
}

#[timed_test(50)]
fn test_custom_time_limit() {
thread::sleep(Duration::from_millis(10));
}

// Test timed_tokio_test macro
#[timed_tokio_test]
async fn test_fast_async_test() {
tokio::time::sleep(Duration::from_millis(10)).await;
assert_eq!(1 + 1, 2);
}

#[timed_tokio_test(100)]
async fn test_custom_async_time_limit() {
tokio::time::sleep(Duration::from_millis(20)).await;
}

// Test timed_rstest macro
#[timed_rstest]
#[case(1)]
#[case(2)]
fn test_rstest_sync(#[case] value: u32) {
assert!(value > 0);
}

#[timed_rstest(100)]
#[case(1)]
#[case(2)]
fn test_rstest_sync_custom_limit(#[case] value: u32) {
thread::sleep(Duration::from_millis(10));
assert!(value > 0);
}

// Test timed_rstest_tokio with async functions
#[timed_rstest_tokio]
#[case(1)]
#[case(2)]
async fn test_rstest_async(#[case] value: u32) {
tokio::time::sleep(Duration::from_millis(10)).await;
assert!(value > 0);
}

#[timed_rstest_tokio(150)]
#[case(1)]
#[case(2)]
async fn test_rstest_async_custom_limit(#[case] value: u32) {
tokio::time::sleep(Duration::from_millis(20)).await;
assert!(value > 0);
}

// Tests that are expected to fail on actual test content (not timeout)
#[timed_test]
#[should_panic(expected = "assertion")]
fn test_sync_fails_on_assertion() {
assert_eq!(1, 2); // This will fail, not the timeout
}

#[timed_tokio_test]
#[should_panic(expected = "assertion")]
async fn test_async_fails_on_assertion() {
tokio::time::sleep(Duration::from_millis(10)).await;
assert_eq!(1, 2); // This will fail, not the timeout
}

#[timed_rstest]
#[case(1)]
#[case(2)]
#[should_panic(expected = "assertion")]
fn test_rstest_sync_fails_on_assertion(#[case] value: u32) {
assert_eq!(value, 999); // This will fail, not the timeout
}

#[timed_rstest_tokio]
#[case(1)]
#[case(2)]
#[should_panic(expected = "assertion")]
async fn test_rstest_async_fails_on_assertion(#[case] value: u32) {
tokio::time::sleep(Duration::from_millis(10)).await;
assert_eq!(value, 999); // This will fail, not the timeout
}

// Tests that are expected to fail on timeout
#[timed_test(50)]
#[should_panic(expected = "exceeded time limit")]
fn test_sync_fails_on_timeout() {
thread::sleep(Duration::from_millis(100)); // This will exceed the 50ms limit
}

#[timed_tokio_test(50)]
#[should_panic(expected = "exceeded time limit")]
async fn test_async_fails_on_timeout() {
tokio::time::sleep(Duration::from_millis(100)).await; // This will exceed the 50ms limit
}

#[timed_rstest(50)]
#[case(1)]
#[case(2)]
#[should_panic(expected = "exceeded time limit")]
fn test_rstest_sync_fails_on_timeout(#[case] _value: u32) {
thread::sleep(Duration::from_millis(100)); // This will exceed the 50ms limit
}

#[timed_rstest_tokio(50)]
#[case(1)]
#[case(2)]
#[should_panic(expected = "exceeded time limit")]
async fn test_rstest_async_fails_on_timeout(#[case] _value: u32) {
tokio::time::sleep(Duration::from_millis(100)).await; // This will exceed the 50ms limit
}
18 changes: 18 additions & 0 deletions crates/apollo_timed_tests_macros/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
[package]
name = "apollo_timed_tests_macros"
version.workspace = true
edition.workspace = true
repository.workspace = true
license-file.workspace = true
description = "Procedural macros for timed tests"

[dependencies]
proc-macro2.workspace = true
quote.workspace = true
syn = { workspace = true, features = ["full"] }

[lib]
proc-macro = true

[lints]
workspace = true
Loading
Loading