Skip to content

Commit 9c90183

Browse files
committed
Document parallel
1 parent 5be34ee commit 9c90183

File tree

4 files changed

+50
-10
lines changed

4 files changed

+50
-10
lines changed

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,14 @@ async fn test_serial_another() {
2727
// Do things asynchronously
2828
}
2929
```
30-
Multiple tests with the `serial` attribute are guaranteed to be executed in serial. Ordering of the tests is not guaranteed however.
31-
Tests without the `serial` attribute may run at any time, including in parallel to tests marked as `serial`. Note that if you're using
32-
an async test reactor attribute (e.g. `tokio::test` or `actix_rt::test`) then they should be listed *before* `serial`, otherwise we
30+
Multiple tests with the `serial` attribute are guaranteed to be executed in serial. Ordering of the tests is not guaranteed however. Other tests with the `parallel` attribute may run at the same time as each other, but not at the same time as a test with `serial`. Tests with neither attribute may run at any time and no guarantees are made about their timing!
31+
32+
Note that if you're using an async test reactor attribute (e.g. `tokio::test` or `actix_rt::test`) then they should be listed *before* `serial`, otherwise we
3333
don't get an async function and things break. There's now an error for this case to improve debugging.
3434

3535
For cases like doctests and integration tests where the tests are run as separate processes, we also support `file_serial`, with
3636
similar properties but based off file locking. Note that there are no guarantees about one test with `serial` and another with
37-
`file_serial` as they lock using different methods.
37+
`file_serial` as they lock using different methods, and `parallel` doesn't support `file_serial` yet (patches welcomed!).
3838

3939
## Usage
4040
We require at least Rust 1.51. Upgrades to this will require at least a minor version bump (while in 0.x versions) and a major version bump post-1.0.

serial_test/src/code_lock.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,8 @@ impl Default for UniqueReentrantMutex {
4949
}
5050
}
5151

52-
/// Sets the maximum amount of time the serial locks will wait to unlock
53-
/// By default, this is set to 60 seconds, which is almost always much longer than is needed
52+
/// Sets the maximum amount of time the serial locks will wait to unlock.
53+
/// By default, this is set to 60 seconds, which is almost always much longer than is needed.
5454
/// This is deliberately set high to try and avoid situations where we accidentally hit the limits
5555
/// but is set at all so we can timeout rather than hanging forever.
5656
///

serial_test/src/lib.rs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,19 @@
1515
//! fn test_serial_another() {
1616
//! // Do things
1717
//! }
18+
//!
19+
//! #[test]
20+
//! #[parallel]
21+
//! fn test_parallel_another() {
22+
//! // Do parallel things
23+
//! }
1824
//! ````
1925
//! Multiple tests with the [serial](macro@serial) attribute are guaranteed to be executed in serial. Ordering
20-
//! of the tests is not guaranteed however. Tests without the `serial` attribute may run at any time, including
21-
//! in parallel to tests marked as `serial`. Note that if you're using an async test reactor attribute (e.g.
26+
//! of the tests is not guaranteed however. Other tests with the [parallel](macro@parallel) attribute may run
27+
//! at the same time as each other, but not at the same time as a test with [serial](macro@serial). Tests with
28+
//! neither attribute may run at any time and no guarantees are made about their timing!
29+
//!
30+
//! Note that if you're using an async test reactor attribute (e.g.
2231
//! `tokio::test` or `actix_rt::test`) then they should be listed *before* `serial`, otherwise we don't get an
2332
//! async function and things break. There's now an error for this case to improve debugging.
2433
//!

serial_test_derive/src/lib.rs

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,10 @@ use std::ops::Deref;
2626
/// }
2727
/// ````
2828
/// Multiple tests with the [serial](macro@serial) attribute are guaranteed to be executed in serial. Ordering
29-
/// of the tests is not guaranteed however. If you want different subsets of tests to be serialised with each
29+
/// of the tests is not guaranteed however. If you have other tests that can be run in parallel, but would clash
30+
/// if run at the same time as the [serial](macro@serial) tests, you can use the [parallel](macro@parallel) attribute.
31+
///
32+
/// If you want different subsets of tests to be serialised with each
3033
/// other, but not depend on other subsets, you can add an argument to [serial](macro@serial), and all calls
3134
/// with identical arguments will be called in serial. e.g.
3235
/// ````
@@ -57,13 +60,41 @@ use std::ops::Deref;
5760
/// `test_serial_one` and `test_serial_another` will be executed in serial, as will `test_serial_third` and `test_serial_fourth`
5861
/// but neither sequence will be blocked by the other
5962
///
60-
/// Nested serialised tests (i.e. a [serial](macro@serial) tagged test calling another) is supported
63+
/// Nested serialised tests (i.e. a [serial](macro@serial) tagged test calling another) are supported
6164
#[proc_macro_attribute]
6265
#[proc_macro_error]
6366
pub fn serial(attr: TokenStream, input: TokenStream) -> TokenStream {
6467
local_serial_core(attr.into(), input.into()).into()
6568
}
6669

70+
/// Allows for the creation of parallel Rust tests that won't clash with serial tests
71+
/// ````
72+
/// #[test]
73+
/// #[serial]
74+
/// fn test_serial_one() {
75+
/// // Do things
76+
/// }
77+
///
78+
/// #[test]
79+
/// #[parallel]
80+
/// fn test_parallel_one() {
81+
/// // Do things
82+
/// }
83+
///
84+
/// #[test]
85+
/// #[parallel]
86+
/// fn test_parallel_two() {
87+
/// // Do things
88+
/// }
89+
/// ````
90+
/// Multiple tests with the [parallel](macro@parallel) attribute may run in parallel, but not at the
91+
/// same time as [serial](macro@serial) tests. e.g. in the example code above, `test_parallel_one`
92+
/// and `test_parallel_two` may run at the same time, but `test_serial_one` is guaranteed not to run
93+
/// at the same time as either of them. [parallel](macro@parallel) also takes key arguments for groups
94+
/// of tests as per [serial](macro@serial).
95+
///
96+
/// Note that this has zero effect on [file_serial](macro@file_serial) tests, as that uses a different
97+
/// serialisation mechanism.
6798
#[proc_macro_attribute]
6899
#[proc_macro_error]
69100
pub fn parallel(attr: TokenStream, input: TokenStream) -> TokenStream {

0 commit comments

Comments
 (0)