Skip to content

Commit d21ef29

Browse files
committed
futures: move futures-01 tests to submodule
1 parent 94a128c commit d21ef29

File tree

1 file changed

+114
-114
lines changed

1 file changed

+114
-114
lines changed

tracing-futures/src/lib.rs

Lines changed: 114 additions & 114 deletions
Original file line numberDiff line numberDiff line change
@@ -188,38 +188,14 @@ pub mod support;
188188

189189
#[cfg(test)]
190190
mod tests {
191-
extern crate tokio;
192-
193191
use super::{test_support::*, *};
194192

195-
#[cfg(feature = "futures-01")]
196-
use futures::{future, stream, task, Async, Future};
197-
use tracing::{subscriber::with_default, Level};
198-
199193
struct PollN<T, E> {
200194
and_return: Option<Result<T, E>>,
201195
finish_at: usize,
202196
polls: usize,
203197
}
204198

205-
#[cfg(feature = "futures-01")]
206-
impl<T, E> futures::Future for PollN<T, E> {
207-
type Item = T;
208-
type Error = E;
209-
fn poll(&mut self) -> futures::Poll<Self::Item, Self::Error> {
210-
self.polls += 1;
211-
if self.polls == self.finish_at {
212-
self.and_return
213-
.take()
214-
.expect("polled after ready")
215-
.map(Async::Ready)
216-
} else {
217-
task::current().notify();
218-
Ok(Async::NotReady)
219-
}
220-
}
221-
}
222-
223199
impl PollN<(), ()> {
224200
fn new_ok(finish_at: usize) -> Self {
225201
Self {
@@ -239,98 +215,122 @@ mod tests {
239215
}
240216

241217
#[cfg(feature = "futures-01")]
242-
#[test]
243-
fn future_enter_exit_is_reasonable() {
244-
let (subscriber, handle) = subscriber::mock()
245-
.enter(span::mock().named("foo"))
246-
.exit(span::mock().named("foo"))
247-
.enter(span::mock().named("foo"))
248-
.exit(span::mock().named("foo"))
249-
.drop_span(span::mock().named("foo"))
250-
.done()
251-
.run_with_handle();
252-
with_default(subscriber, || {
253-
PollN::new_ok(2)
254-
.instrument(span!(Level::TRACE, "foo"))
255-
.wait()
256-
.unwrap();
257-
});
258-
handle.assert_finished();
259-
}
218+
mod futures_tests {
219+
extern crate tokio;
220+
221+
use futures::{future, stream, task, Async, Future};
222+
use tracing::{subscriber::with_default, Level};
223+
224+
use super::*;
225+
226+
impl<T, E> futures::Future for PollN<T, E> {
227+
type Item = T;
228+
type Error = E;
229+
fn poll(&mut self) -> futures::Poll<Self::Item, Self::Error> {
230+
self.polls += 1;
231+
if self.polls == self.finish_at {
232+
self.and_return
233+
.take()
234+
.expect("polled after ready")
235+
.map(Async::Ready)
236+
} else {
237+
task::current().notify();
238+
Ok(Async::NotReady)
239+
}
240+
}
241+
}
260242

261-
#[cfg(feature = "futures-01")]
262-
#[test]
263-
fn future_error_ends_span() {
264-
let (subscriber, handle) = subscriber::mock()
265-
.enter(span::mock().named("foo"))
266-
.exit(span::mock().named("foo"))
267-
.enter(span::mock().named("foo"))
268-
.exit(span::mock().named("foo"))
269-
.drop_span(span::mock().named("foo"))
270-
.done()
271-
.run_with_handle();
272-
with_default(subscriber, || {
273-
PollN::new_err(2)
274-
.instrument(span!(Level::TRACE, "foo"))
275-
.wait()
276-
.unwrap_err();
277-
});
278-
279-
handle.assert_finished();
280-
}
243+
#[test]
244+
fn future_enter_exit_is_reasonable() {
245+
let (subscriber, handle) = subscriber::mock()
246+
.enter(span::mock().named("foo"))
247+
.exit(span::mock().named("foo"))
248+
.enter(span::mock().named("foo"))
249+
.exit(span::mock().named("foo"))
250+
.drop_span(span::mock().named("foo"))
251+
.done()
252+
.run_with_handle();
253+
with_default(subscriber, || {
254+
PollN::new_ok(2)
255+
.instrument(span!(Level::TRACE, "foo"))
256+
.wait()
257+
.unwrap();
258+
});
259+
handle.assert_finished();
260+
}
281261

282-
#[cfg(feature = "futures-01")]
283-
#[test]
284-
fn stream_enter_exit_is_reasonable() {
285-
let (subscriber, handle) = subscriber::mock()
286-
.enter(span::mock().named("foo"))
287-
.exit(span::mock().named("foo"))
288-
.enter(span::mock().named("foo"))
289-
.exit(span::mock().named("foo"))
290-
.enter(span::mock().named("foo"))
291-
.exit(span::mock().named("foo"))
292-
.enter(span::mock().named("foo"))
293-
.exit(span::mock().named("foo"))
294-
.drop_span(span::mock().named("foo"))
295-
.run_with_handle();
296-
with_default(subscriber, || {
297-
stream::iter_ok::<_, ()>(&[1, 2, 3])
298-
.instrument(span!(Level::TRACE, "foo"))
299-
.for_each(|_| future::ok(()))
300-
.wait()
301-
.unwrap();
302-
});
303-
handle.assert_finished();
304-
}
262+
#[cfg(feature = "futures-01")]
263+
#[test]
264+
fn future_error_ends_span() {
265+
let (subscriber, handle) = subscriber::mock()
266+
.enter(span::mock().named("foo"))
267+
.exit(span::mock().named("foo"))
268+
.enter(span::mock().named("foo"))
269+
.exit(span::mock().named("foo"))
270+
.drop_span(span::mock().named("foo"))
271+
.done()
272+
.run_with_handle();
273+
with_default(subscriber, || {
274+
PollN::new_err(2)
275+
.instrument(span!(Level::TRACE, "foo"))
276+
.wait()
277+
.unwrap_err();
278+
});
279+
280+
handle.assert_finished();
281+
}
305282

306-
#[cfg(feature = "futures-01")]
307-
#[test]
308-
fn span_follows_future_onto_threadpool() {
309-
let (subscriber, handle) = subscriber::mock()
310-
.enter(span::mock().named("a"))
311-
.enter(span::mock().named("b"))
312-
.exit(span::mock().named("b"))
313-
.enter(span::mock().named("b"))
314-
.exit(span::mock().named("b"))
315-
.drop_span(span::mock().named("b"))
316-
.exit(span::mock().named("a"))
317-
.drop_span(span::mock().named("a"))
318-
.done()
319-
.run_with_handle();
320-
let mut runtime = tokio::runtime::Runtime::new().unwrap();
321-
with_default(subscriber, || {
322-
span!(Level::TRACE, "a").in_scope(|| {
323-
let future = PollN::new_ok(2)
324-
.instrument(span!(Level::TRACE, "b"))
325-
.map(|_| {
326-
span!(Level::TRACE, "c").in_scope(|| {
327-
// "c" happens _outside_ of the instrumented future's
328-
// span, so we don't expect it.
329-
})
330-
});
331-
runtime.block_on(Box::new(future)).unwrap();
332-
})
333-
});
334-
handle.assert_finished();
283+
#[test]
284+
fn stream_enter_exit_is_reasonable() {
285+
let (subscriber, handle) = subscriber::mock()
286+
.enter(span::mock().named("foo"))
287+
.exit(span::mock().named("foo"))
288+
.enter(span::mock().named("foo"))
289+
.exit(span::mock().named("foo"))
290+
.enter(span::mock().named("foo"))
291+
.exit(span::mock().named("foo"))
292+
.enter(span::mock().named("foo"))
293+
.exit(span::mock().named("foo"))
294+
.drop_span(span::mock().named("foo"))
295+
.run_with_handle();
296+
with_default(subscriber, || {
297+
stream::iter_ok::<_, ()>(&[1, 2, 3])
298+
.instrument(span!(Level::TRACE, "foo"))
299+
.for_each(|_| future::ok(()))
300+
.wait()
301+
.unwrap();
302+
});
303+
handle.assert_finished();
304+
}
305+
306+
#[test]
307+
fn span_follows_future_onto_threadpool() {
308+
let (subscriber, handle) = subscriber::mock()
309+
.enter(span::mock().named("a"))
310+
.enter(span::mock().named("b"))
311+
.exit(span::mock().named("b"))
312+
.enter(span::mock().named("b"))
313+
.exit(span::mock().named("b"))
314+
.drop_span(span::mock().named("b"))
315+
.exit(span::mock().named("a"))
316+
.drop_span(span::mock().named("a"))
317+
.done()
318+
.run_with_handle();
319+
let mut runtime = tokio::runtime::Runtime::new().unwrap();
320+
with_default(subscriber, || {
321+
span!(Level::TRACE, "a").in_scope(|| {
322+
let future = PollN::new_ok(2)
323+
.instrument(span!(Level::TRACE, "b"))
324+
.map(|_| {
325+
span!(Level::TRACE, "c").in_scope(|| {
326+
// "c" happens _outside_ of the instrumented future's
327+
// span, so we don't expect it.
328+
})
329+
});
330+
runtime.block_on(Box::new(future)).unwrap();
331+
})
332+
});
333+
handle.assert_finished();
334+
}
335335
}
336336
}

0 commit comments

Comments
 (0)