I have the following snippet:
fn main() {
async_std::task::block_on(async {
let handle_fast = async {
for i in 1..=8 {
println!("fast {}", i);
async_std::task::sleep(std::time::Duration::from_millis(250)).await;
}
()
};
let handle_slow = async {
for i in 1..=4 {
println!("slow {}", i);
async_std::task::sleep(std::time::Duration::from_millis(500)).await;
}
()
};
futures_util::join!(handle_fast, handle_slow)
});
}
#[cfg(test)]
mod tests {
#[test]
fn test() {
async_std::task::block_on(async {
let handle_fast = async {
for i in 1..=8 {
println!("fast {}", i);
async_std::task::sleep(std::time::Duration::from_millis(250)).await;
}
()
};
let handle_slow = async {
for i in 1..=4 {
println!("slow {}", i);
async_std::task::sleep(std::time::Duration::from_millis(500)).await;
}
()
};
futures_util::join!(handle_fast, handle_slow)
});
}
}
When I run the main method it works as expected. But when running from the tests it doesn't work and just prints all at once at the end of the execution.
How can I reproduce the behavior from main
in the tests?