Skip to content

Commit ddb0af9

Browse files
committed
test: use random SEED numbers
This is needed to omit occurrences of the same seed in a sequence of following seeds due to the reason of that two initial seed are very close if based on unix epoch seconds.
1 parent 3aeef44 commit ddb0af9

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

cli/src/tests/helpers/mod.rs

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ pub(super) mod random;
66
pub(super) mod scope_sequence;
77

88
use lazy_static::lazy_static;
9-
use std::{env, time, usize};
9+
use rand::Rng;
10+
use std::env;
1011

1112
lazy_static! {
1213
pub static ref LOG_ENABLED: bool = env::var("TREE_SITTER_LOG").is_ok();
@@ -16,15 +17,18 @@ lazy_static! {
1617
}
1718

1819
lazy_static! {
19-
pub static ref START_SEED: usize =
20-
int_env_var("TREE_SITTER_SEED").unwrap_or_else(|| time::SystemTime::now()
21-
.duration_since(time::UNIX_EPOCH)
22-
.unwrap()
23-
.as_secs() as usize,);
20+
pub static ref START_SEED: usize = new_seed();
2421
pub static ref EDIT_COUNT: usize = int_env_var("TREE_SITTER_EDITS").unwrap_or(3);
2522
pub static ref ITERATION_COUNT: usize = int_env_var("TREE_SITTER_ITERATIONS").unwrap_or(10);
2623
}
2724

2825
fn int_env_var(name: &'static str) -> Option<usize> {
2926
env::var(name).ok().and_then(|e| e.parse().ok())
3027
}
28+
29+
pub(crate) fn new_seed() -> usize {
30+
int_env_var("TREE_SITTER_SEED").unwrap_or_else(|| {
31+
let mut rng = rand::thread_rng();
32+
rng.gen::<usize>()
33+
})
34+
}

0 commit comments

Comments
 (0)