Skip to content

Commit 4fb5324

Browse files
committed
rand
1 parent 3d044ea commit 4fb5324

File tree

6 files changed

+53
-39
lines changed

6 files changed

+53
-39
lines changed

Cargo.lock

Lines changed: 40 additions & 23 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ log = { version = "0.4", features = [
6262
"release_max_level_info",
6363
] }
6464
protobuf = "=2.25.2" # pin to 2.25.2 to prevent side updating
65-
rand = "0.8"
65+
rand = "0.10"
6666
regex = "1.12"
6767
reqwest = { version = "0.12", default-features = false, features = [
6868
"rustls-tls",

syncserver/src/server/test.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ use hawk::{self, Credentials, Key, RequestBuilder};
1515
use hmac::{Hmac, Mac};
1616
use http::StatusCode;
1717
use lazy_static::lazy_static;
18-
use rand::{Rng, thread_rng};
1918
use serde::de::DeserializeOwned;
2019
use serde_json::{Value, json};
2120
use sha2::Sha256;
@@ -36,7 +35,7 @@ lazy_static! {
3635
static ref SERVER_LIMITS: Arc<ServerLimits> = Arc::new(ServerLimits::default());
3736
static ref SECRETS: Arc<Secrets> =
3837
Arc::new(Secrets::new("foo").expect("Could not get Secrets in server/test.rs"));
39-
static ref RAND_UID: u32 = thread_rng().gen_range(0..10000);
38+
static ref RAND_UID: u32 = rand::random_range(0..10000);
4039
}
4140

4241
const TEST_HOST: &str = "localhost";

syncserver/src/web/extractors/test_utils.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ use glean::server_events::GleanEventsLogger;
1414
use hawk::{Credentials, Key, RequestBuilder};
1515
use hmac::{Hmac, Mac};
1616
use lazy_static::lazy_static;
17-
use rand::{Rng, thread_rng};
1817
use sha2::Sha256;
1918
use tokio::sync::RwLock;
2019

@@ -29,7 +28,7 @@ use crate::{server::ServerState, web::auth::HawkPayload};
2928
lazy_static! {
3029
static ref SERVER_LIMITS: Arc<ServerLimits> = Arc::new(ServerLimits::default());
3130
pub static ref SECRETS: Arc<Secrets> = Arc::new(Secrets::new("Ted Koppel is a robot").unwrap());
32-
pub static ref USER_ID: u64 = thread_rng().gen_range(0..10000);
31+
pub static ref USER_ID: u64 = rand::random_range(0..10000);
3332
pub static ref USER_ID_STR: String = USER_ID.to_string();
3433
}
3534

syncstorage-db/src/tests/db.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
#![allow(clippy::cognitive_complexity)]
2-
use std::collections::HashMap;
3-
42
use lazy_static::lazy_static;
5-
use rand::{Rng, distributions::Alphanumeric, thread_rng};
3+
use rand::rng;
4+
use rand::{RngExt, distr::Alphanumeric};
5+
use std::collections::HashMap;
66
use syncserver_settings::Settings;
77
use syncstorage_db_common::{
88
DEFAULT_BSO_TTL, Sorting, error::DbErrorIntrospect, params, util::SyncTimestamp,
@@ -17,7 +17,7 @@ use crate::{Db, DbError, tests::support::test_db};
1717
const MAX_TIMESTAMP: u64 = 4_070_937_600_000;
1818

1919
lazy_static! {
20-
static ref UID: u32 = thread_rng().gen_range(0..10000);
20+
static ref UID: u32 = rng().random_range(0..10000);
2121
}
2222

2323
#[tokio::test]
@@ -623,8 +623,8 @@ async fn get_collection_usage() -> Result<(), DbError> {
623623

624624
for &coll in ["bookmarks", "history", "prefs"].iter() {
625625
for i in 0..5 {
626-
let size = 50 + thread_rng().gen_range(0..100);
627-
let payload = thread_rng()
626+
let size = 50 + rng().random_range(0..100);
627+
let payload = rng()
628628
.sample_iter(&Alphanumeric)
629629
.take(size)
630630
.collect::<Vec<u8>>();
@@ -681,7 +681,7 @@ async fn test_quota() -> Result<(), DbError> {
681681
let coll = "bookmarks";
682682

683683
let size = 5000;
684-
let random = thread_rng()
684+
let random = rng()
685685
.sample_iter(&Alphanumeric)
686686
.take(size)
687687
.collect::<Vec<u8>>();
@@ -714,10 +714,10 @@ async fn get_collection_counts() -> Result<(), DbError> {
714714
with_test_transaction(None, async |db: &mut dyn Db<Error = DbError>| {
715715
let uid = *UID;
716716
let mut expected = HashMap::new();
717-
let mut rng = thread_rng();
717+
let mut rng = rng();
718718

719719
for &coll in ["bookmarks", "history", "prefs"].iter() {
720-
let count = 5 + rng.gen_range(0..5);
720+
let count = 5 + rng.random_range(0..5);
721721
expected.insert(coll.to_owned(), count);
722722
for i in 0..count {
723723
db.put_bso(pbso(uid, coll, &format!("b{}", i), Some("x"), None, None))

syncstorage-settings/src/lib.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ use std::{
55
time::{Duration, Instant},
66
};
77

8-
use rand::{Rng, thread_rng};
98
use serde::{Deserialize, Serialize};
109
use syncserver_common::{self, MAX_SPANNER_LOAD_SIZE};
1110

@@ -56,7 +55,7 @@ impl From<&Settings> for Deadman {
5655
// ttl w/ a 10% jitter results in a random final ttl between 60-66s
5756
let ttl = lbheartbeat_ttl as f32;
5857
let max_jitter = ttl * (settings.lbheartbeat_ttl_jitter as f32 * 0.01);
59-
let ttl = thread_rng().gen_range(ttl..ttl + max_jitter);
58+
let ttl = rand::random_range(ttl..ttl + max_jitter);
6059
Instant::now() + Duration::from_secs(ttl as u64)
6160
});
6261
Deadman {

0 commit comments

Comments
 (0)