-
Notifications
You must be signed in to change notification settings - Fork 722
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: add
tracing-test
crate for non-publishable test utils (#2466)
There has been interest around publishing tracing-mock to crates.io for some time. In order to make this possible, it needs to be cleaned up. There are some test utils in the `tracing-mock` crate which wouldn't make sense to publish. They provide test futures that are needed in multiple `tracing-*` crates, but would likely not be needed outside that context. This change moves that functionality into a separate `tracing-test` crate, which should never be published to crates.io. Refs: #539 Co-authored-by: David Barsky <[email protected]>
- Loading branch information
1 parent
00809ea
commit a87faa3
Showing
16 changed files
with
204 additions
and
77 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
## BIG SCARY NOTE | ||
# This crate is internal and to be used for testing only. It should not | ||
# be published to crates.io ever. If the functionality is needed outside | ||
# the tracing project, it should be moved back to tracing-mock. | ||
|
||
[package] | ||
name = "tracing-test" | ||
version = "0.1.0" | ||
authors = [ | ||
"Eliza Weisman <[email protected]>", | ||
"Tokio Contributors <[email protected]>", | ||
] | ||
license = "MIT" | ||
readme = "README.md" | ||
repository = "https://github.com/tokio-rs/tracing" | ||
homepage = "https://tokio.rs" | ||
edition = "2018" | ||
rust-version = "1.49.0" | ||
publish = false | ||
|
||
[dependencies] | ||
tokio-test = "0.4.2" | ||
|
||
[package.metadata.docs.rs] | ||
all-features = true | ||
rustdoc-args = ["--cfg", "docsrs"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
Copyright (c) 2019 Tokio Contributors | ||
|
||
Permission is hereby granted, free of charge, to any | ||
person obtaining a copy of this software and associated | ||
documentation files (the "Software"), to deal in the | ||
Software without restriction, including without | ||
limitation the rights to use, copy, modify, merge, | ||
publish, distribute, sublicense, and/or sell copies of | ||
the Software, and to permit persons to whom the Software | ||
is furnished to do so, subject to the following | ||
conditions: | ||
|
||
The above copyright notice and this permission notice | ||
shall be included in all copies or substantial portions | ||
of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF | ||
ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED | ||
TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A | ||
PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT | ||
SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY | ||
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION | ||
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR | ||
IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER | ||
DEALINGS IN THE SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
![Tracing — Structured, application-level diagnostics][splash] | ||
|
||
[splash]: https://raw.githubusercontent.com/tokio-rs/tracing/master/assets/splash.svg | ||
|
||
# tracing-test | ||
|
||
Utilities for testing [`tracing`][tracing] and crates that uses it. | ||
|
||
[![Documentation (master)][docs-master-badge]][docs-master-url] | ||
[![MIT licensed][mit-badge]][mit-url] | ||
[![Build Status][actions-badge]][actions-url] | ||
[![Discord chat][discord-badge]][discord-url] | ||
|
||
[Documentation][docs-master-url] | [Chat][discord-url] | ||
|
||
[docs-master-badge]: https://img.shields.io/badge/docs-master-blue | ||
[docs-master-url]: https://tracing-rs.netlify.com/tracing_mock | ||
[mit-badge]: https://img.shields.io/badge/license-MIT-blue.svg | ||
[mit-url]: https://github.com/tokio-rs/tracing/blob/master/tracing-test/LICENSE | ||
[actions-badge]: https://github.com/tokio-rs/tracing/workflows/CI/badge.svg | ||
[actions-url]:https://github.com/tokio-rs/tracing/actions?query=workflow%3ACI | ||
[discord-badge]: https://img.shields.io/discord/500028886025895936?logo=discord&label=discord&logoColor=white | ||
[discord-url]: https://discord.gg/EeF3cQw | ||
|
||
## Overview | ||
|
||
[`tracing`] is a framework for instrumenting Rust programs to collect | ||
structured, event-based diagnostic information. `tracing-test` provides | ||
some reusable tools to aid in testing, but that are only intended for | ||
internal use. For mocks and expectations, see [`tracing-mock`]. | ||
|
||
*Compiler support: [requires `rustc` 1.56+][msrv]* | ||
|
||
[msrv]: #supported-rust-versions | ||
|
||
## Supported Rust Versions | ||
|
||
Tracing is built against the latest stable release. The minimum supported | ||
version is 1.56. The current Tracing version is not guaranteed to build on Rust | ||
versions earlier than the minimum supported version. | ||
|
||
Tracing follows the same compiler support policies as the rest of the Tokio | ||
project. The current stable Rust compiler and the three most recent minor | ||
versions before it will always be supported. For example, if the current stable | ||
compiler version is 1.45, the minimum supported version will not be increased | ||
past 1.42, three minor versions prior. Increasing the minimum supported compiler | ||
version is not considered a semver breaking change as long as doing so complies | ||
with this policy. | ||
|
||
## License | ||
|
||
This project is licensed under the [MIT license][mit-url]. | ||
|
||
### Contribution | ||
|
||
Unless you explicitly state otherwise, any contribution intentionally submitted | ||
for inclusion in Tracing by you, shall be licensed as MIT, without any additional | ||
terms or conditions. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
use std::{ | ||
pin::Pin, | ||
task::{Context, Poll}, | ||
}; | ||
|
||
#[allow(missing_docs)] | ||
|
||
pub struct PollN<T, E> { | ||
and_return: Option<Result<T, E>>, | ||
finish_at: usize, | ||
polls: usize, | ||
} | ||
|
||
impl<T, E> std::future::Future for PollN<T, E> | ||
where | ||
T: Unpin, | ||
E: Unpin, | ||
{ | ||
type Output = Result<T, E>; | ||
fn poll(self: Pin<&mut Self>, cx: &mut Context) -> Poll<Self::Output> { | ||
let this = self.get_mut(); | ||
|
||
this.polls += 1; | ||
if this.polls == this.finish_at { | ||
let value = this.and_return.take().expect("polled after ready"); | ||
|
||
Poll::Ready(value) | ||
} else { | ||
cx.waker().wake_by_ref(); | ||
Poll::Pending | ||
} | ||
} | ||
} | ||
|
||
impl PollN<(), ()> { | ||
pub fn new_ok(finish_at: usize) -> Self { | ||
Self { | ||
and_return: Some(Ok(())), | ||
finish_at, | ||
polls: 0, | ||
} | ||
} | ||
|
||
pub fn new_err(finish_at: usize) -> Self { | ||
Self { | ||
and_return: Some(Err(())), | ||
finish_at, | ||
polls: 0, | ||
} | ||
} | ||
} | ||
|
||
pub fn block_on_future<F>(future: F) -> F::Output | ||
where | ||
F: std::future::Future, | ||
{ | ||
use tokio_test::task; | ||
|
||
let mut task = task::spawn(future); | ||
loop { | ||
if let Poll::Ready(v) = task.poll() { | ||
break v; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters