Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
olegnn committed Mar 20, 2023
1 parent d94765b commit 7e49a40
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 31 deletions.
1 change: 1 addition & 0 deletions futures/tests/no-std/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#![cfg(nightly)]
#![no_std]
#![allow(useless_anonymous_reexport)]

#[cfg(feature = "futures-core-alloc")]
#[cfg(target_has_atomic = "ptr")]
Expand Down
64 changes: 33 additions & 31 deletions futures/tests/stream.rs
Original file line number Diff line number Diff line change
Expand Up @@ -344,40 +344,42 @@ fn flatten_unordered() {

// nested `flatten_unordered`
let te = ThreadPool::new().unwrap();
let handle = te.spawn_with_handle(async move {
let inner = stream::iter(0..10)
.then(|_| {
let task = Arc::new(AtomicBool::new(false));
let mut spawned = false;

future::poll_fn(move |cx| {
if !spawned {
let waker = cx.waker().clone();
let task = task.clone();

std::thread::spawn(move || {
std::thread::sleep(Duration::from_millis(500));
task.store(true, Ordering::Release);

waker.wake_by_ref()
});
spawned = true;
}

if task.load(Ordering::Acquire) {
Poll::Ready(Some(()))
} else {
Poll::Pending
}
let handle = te
.spawn_with_handle(async move {
let inner = stream::iter(0..10)
.then(|_| {
let task = Arc::new(AtomicBool::new(false));
let mut spawned = false;

future::poll_fn(move |cx| {
if !spawned {
let waker = cx.waker().clone();
let task = task.clone();

std::thread::spawn(move || {
std::thread::sleep(Duration::from_millis(500));
task.store(true, Ordering::Release);

waker.wake_by_ref()
});
spawned = true;
}

if task.load(Ordering::Acquire) {
Poll::Ready(Some(()))
} else {
Poll::Pending
}
})
})
})
.map(|_| stream::once(future::ready(())))
.flatten_unordered(None);
.map(|_| stream::once(future::ready(())))
.flatten_unordered(None);

let stream = stream::once(future::ready(inner)).flatten_unordered(None);
let stream = stream::once(future::ready(inner)).flatten_unordered(None);

assert_eq!(stream.count().await, 10);
}).unwrap();
assert_eq!(stream.count().await, 10);
})
.unwrap();

block_on(handle);
}
Expand Down

0 comments on commit 7e49a40

Please sign in to comment.