Skip to content

Commit

Permalink
Upgrade rand crate version and stabalize test rand generation
Browse files Browse the repository at this point in the history
Upgrades the rand crate version and ensures that every new test
gets a new random seed by default.
  • Loading branch information
allada committed Feb 9, 2025
1 parent a9302dc commit bedfbca
Show file tree
Hide file tree
Showing 19 changed files with 169 additions and 63 deletions.
125 changes: 103 additions & 22 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions nativelink-macro/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ pub fn nativelink_test(attr: TokenStream, item: TokenStream) -> TokenStream {
#[warn(clippy::disallowed_methods)]
::std::sync::Arc::new(::nativelink_util::origin_context::OriginContext::new()).wrap_async(
::nativelink_util::__tracing::trace_span!("test"), async move {
::nativelink_util::common::reseed_rng_for_test().unwrap();
#fn_block
}
)
Expand Down
2 changes: 1 addition & 1 deletion nativelink-scheduler/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ futures = { version = "0.3.31", default-features = false }
lru = { version = "0.12.5", default-features = false }
mock_instant = "0.5.2"
parking_lot = "0.12.3"
rand = { version = "0.8.5", default-features = false }
rand = { version = "0.9.0", default-features = false, features = ["thread_rng"] }
scopeguard = { version = "1.2.0", default-features = false }
tokio = { version = "1.43.0", features = ["fs", "rt-multi-thread", "signal", "io-util"], default-features = false }
tokio-stream = { version = "0.1.17", features = ["fs"], default-features = false }
Expand Down
3 changes: 1 addition & 2 deletions nativelink-scheduler/src/grpc_scheduler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ use nativelink_util::origin_event::OriginMetadata;
use nativelink_util::retry::{Retrier, RetryResult};
use nativelink_util::{background_spawn, tls_utils};
use parking_lot::Mutex;
use rand::rngs::OsRng;
use rand::Rng;
use tokio::select;
use tokio::sync::watch;
Expand Down Expand Up @@ -107,7 +106,7 @@ impl GrpcScheduler {
}
let min = 1. - (jitter_amt / 2.);
let max = 1. + (jitter_amt / 2.);
delay.mul_f32(OsRng.gen_range(min..max))
delay.mul_f32(rand::rng().random_range(min..max))
}),
)
}
Expand Down
2 changes: 1 addition & 1 deletion nativelink-service/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ futures = { version = "0.3.31", default-features = false }
http-body = "1.0.1"
http-body-util = "0.1.2"
hyper = { version = "1.5.2" }
rand = { version = "0.8.5", default-features = false }
rand = { version = "0.9.0", default-features = false, features = ["thread_rng"] }
serde_json5 = "0.1.0"
parking_lot = "0.12.3"
prost = { version = "0.13.4", default-features = false }
Expand Down
3 changes: 1 addition & 2 deletions nativelink-service/src/worker_api_server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,8 @@ impl WorkerApiServer {
schedulers: &HashMap<String, Arc<dyn WorkerScheduler>>,
) -> Result<Self, Error> {
let node_id = {
let mut rng = rand::thread_rng();
let mut out = [0; 6];
rng.fill_bytes(&mut out);
rand::rng().fill_bytes(&mut out);
out
};
for scheduler in schedulers.values() {
Expand Down
3 changes: 2 additions & 1 deletion nativelink-store/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ hyper-rustls = { version = "0.24.2", default-features = false, features = [
lz4_flex = { version = "0.11.3", default-features = false }
parking_lot = "0.12.3"
prost = { version = "0.13.4", default-features = false }
rand = { version = "0.8.5", default-features = false }
rand = { version = "0.9.0", default-features = false, features = ["thread_rng"] }
serde = { version = "1.0.217", default-features = false }
tokio = { version = "1.43.0", features = ["fs", "rt-multi-thread", "signal", "io-util"], default-features = false }
tokio-stream = { version = "0.1.17", features = ["fs"], default-features = false }
Expand All @@ -78,6 +78,7 @@ aws-sdk-s3 = { version = "=1.68.0", features = [
"rt-tokio",
], default-features = false }
aws-smithy-runtime-api = "1.7.3"
rand = { version = "0.9.0", default-features = false, features = ["thread_rng", "small_rng"] }
serde_json = "1.0.135"
fred = { version = "10.0.3", default-features = false, features = ["mocks"] }
tracing-subscriber = { version = "0.3.19", default-features = false }
3 changes: 1 addition & 2 deletions nativelink-store/src/grpc_store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ use nativelink_util::store_trait::{StoreDriver, StoreKey, UploadSizeInfo};
use nativelink_util::{default_health_status_indicator, tls_utils};
use parking_lot::Mutex;
use prost::Message;
use rand::rngs::OsRng;
use rand::Rng;
use tokio::time::sleep;
use tonic::{IntoRequest, Request, Response, Status, Streaming};
Expand Down Expand Up @@ -81,7 +80,7 @@ impl GrpcStore {
}
let min = 1. - (jitter_amt / 2.);
let max = 1. + (jitter_amt / 2.);
delay.mul_f32(OsRng.gen_range(min..max))
delay.mul_f32(rand::rng().random_range(min..max))
}),
)
.await
Expand Down
3 changes: 1 addition & 2 deletions nativelink-store/src/s3_store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ use nativelink_util::health_utils::{HealthStatus, HealthStatusIndicator};
use nativelink_util::instant_wrapper::InstantWrapper;
use nativelink_util::retry::{Retrier, RetryResult};
use nativelink_util::store_trait::{StoreDriver, StoreKey, UploadSizeInfo};
use rand::rngs::OsRng;
use rand::Rng;
use tokio::io::{AsyncRead, AsyncWrite, ReadBuf};
use tokio::net::TcpStream;
Expand Down Expand Up @@ -266,7 +265,7 @@ where
}
let min = 1. - (jitter_amt / 2.);
let max = 1. + (jitter_amt / 2.);
delay.mul_f32(OsRng.gen_range(min..max))
delay.mul_f32(rand::rng().random_range(min..max))
});
let s3_client = {
let http_client =
Expand Down
Loading

0 comments on commit bedfbca

Please sign in to comment.