Skip to content

Commit

Permalink
Merge pull request #82 from palfrey/actual-async
Browse files Browse the repository at this point in the history
Actually properly support async
  • Loading branch information
palfrey authored Dec 14, 2022
2 parents cb516b9 + 177a4f3 commit 4330da4
Show file tree
Hide file tree
Showing 11 changed files with 192 additions and 160 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:
- stable
- beta
- nightly
- 1.51.0
- 1.56.0
steps:
- uses: actions/checkout@v2.3.4
- uses: actions-rs/toolchain@v1.0.7
Expand Down
216 changes: 119 additions & 97 deletions Cargo.lock

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

7 changes: 2 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
[![Docs](https://docs.rs/serial_test/badge.svg)](https://docs.rs/serial_test/)
[![MIT license](https://img.shields.io/crates/l/serial_test.svg)](./LICENSE)
[![Build Status](https://github.com/palfrey/serial_test/workflows/Continuous%20integration/badge.svg?branch=main)](https://github.com/palfrey/serial_test/actions)
[![MSRV: 1.51.0](https://flat.badgen.net/badge/MSRV/1.51.0/purple)](https://blog.rust-lang.org/2021/03/25/Rust-1.51.0.html)
[![MSRV: 1.56.0](https://flat.badgen.net/badge/MSRV/1.56.0/purple)](https://blog.rust-lang.org/2021/10/21/Rust-1.56.0.html)

`serial_test` allows for the creation of serialised Rust tests using the `serial` attribute
e.g.
Expand All @@ -29,15 +29,12 @@ async fn test_serial_another() {
```
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!

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
don't get an async function and things break. There's now an error for this case to improve debugging.

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

## Usage
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.
We require at least Rust 1.56. Upgrades to this will require at least a minor version bump (while in 0.x versions) and a major version bump post-1.0.

Add to your Cargo.toml
```toml
Expand Down
2 changes: 1 addition & 1 deletion serial_test/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ default = ["logging", "async"]
logging = ["log"]

## Enables async features (and requires the `futures` package)
async = ["futures"]
async = ["futures", "serial_test_derive/async"]

## The file_locks feature unlocks the `file_serial`/`file_parallel` macros (and requires the `fslock` package)
file_locks = ["fslock"]
Expand Down
4 changes: 0 additions & 4 deletions serial_test/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,6 @@
//! at the same time as each other, but not at the same time as a test with [serial](macro@serial). Tests with
//! neither attribute may run at any time and no guarantees are made about their timing!
//!
//! 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](macro@serial)/[parallel](macro@parallel), otherwise we don't get an
//! async function and things break. There's now an error for this case to improve debugging.
//!
//! For cases like doctests and integration tests where the tests are run as separate processes, we also support
//! [file_serial](macro@file_serial)/[file_parallel](macro@file_parallel), with similar properties but based off file locking. Note that there are no
//! guarantees about one test with [serial](macro@serial)/[parallel](macro@parallel) and another with [file_serial](macro@file_serial)/[file_parallel](macro@file_parallel)
Expand Down
6 changes: 3 additions & 3 deletions serial_test_derive/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ proc-macro = true
quote = "1.0"
syn = { version="1.0", features=["full"] }
proc-macro2 = "1.0"
proc-macro-error = { version = "1" }

[dev-dependencies]
env_logger = "0.9"
rustversion = "1.0"
trybuild = "1"

[features]
async = []
Loading

0 comments on commit 4330da4

Please sign in to comment.