Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rt: fix rng_seed test for threaded runtime #5133

Merged
merged 1 commit into from Oct 27, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
30 changes: 17 additions & 13 deletions tokio/tests/rt_threaded.rs
Expand Up @@ -571,35 +571,39 @@ mod unstable {
.rng_seed(RngSeed::from_bytes(seed))
.build()
.unwrap();
let rt1_value = rt1.block_on(async {
let random = tokio::macros::support::thread_rng_n(100);
assert_eq!(random, 86);
let rt1_values = rt1.block_on(async {
let rand_1 = tokio::macros::support::thread_rng_n(100);

let _ = tokio::spawn(async {
let rand_2 = tokio::spawn(async {
// Because we only have a single worker thread, the
// RNG will be deterministic here as well.
tokio::macros::support::thread_rng_n(100);
tokio::macros::support::thread_rng_n(100)
})
.await;
.await
.unwrap();

(rand_1, rand_2)
});

let rt2 = tokio::runtime::Builder::new_multi_thread()
.worker_threads(1)
.rng_seed(RngSeed::from_bytes(seed))
.build()
.unwrap();
let rt2_value = rt2.block_on(async {
let random = tokio::macros::support::thread_rng_n(100);
assert_eq!(random, 86);
let rt2_values = rt2.block_on(async {
let rand_1 = tokio::macros::support::thread_rng_n(100);

let _ = tokio::spawn(async {
let rand_2 = tokio::spawn(async {
// Because we only have a single worker thread, the
// RNG will be deterministic here as well.
tokio::macros::support::thread_rng_n(100);
tokio::macros::support::thread_rng_n(100)
})
.await;
.await
.unwrap();

(rand_1, rand_2)
});

assert_eq!(rt1_value, rt2_value);
assert_eq!(rt1_values, rt2_values);
}
}