Skip to content

Commit

Permalink
fix rtc-ice/rand_test.rs
Browse files Browse the repository at this point in the history
  • Loading branch information
yngrtc committed Mar 9, 2024
1 parent c91e5ad commit 0e8f3bf
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 33 deletions.
4 changes: 2 additions & 2 deletions rtc-ice/src/rand/mod.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//TODO:#[cfg(test)]
//TODO:mod rand_test;
#[cfg(test)]
mod rand_test;

use rand::{thread_rng, Rng};

Expand Down
44 changes: 13 additions & 31 deletions rtc-ice/src/rand/rand_test.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,8 @@
use std::sync::Arc;

use tokio::sync::Mutex;
use waitgroup::WaitGroup;

use super::*;
use crate::error::Result;
use shared::error::Result;

#[tokio::test]
async fn test_random_generator_collision() -> Result<()> {
#[test]
fn test_random_generator_collision() -> Result<()> {
let test_cases = vec![
(
"CandidateID",
Expand All @@ -32,33 +27,20 @@ async fn test_random_generator_collision() -> Result<()> {

for (name, test_case) in test_cases {
for _ in 0..ITERATION {
let rands = Arc::new(Mutex::new(vec![]));

// Create a new wait group.
let wg = WaitGroup::new();
let mut rs = vec![];

for _ in 0..N {
let w = wg.worker();
let rs = Arc::clone(&rands);

tokio::spawn(async move {
let _d = w;

let s = if test_case == 0 {
generate_cand_id()
} else if test_case == 1 {
generate_pwd()
} else {
generate_ufrag()
};

let mut r = rs.lock().await;
r.push(s);
});
let s = if test_case == 0 {
generate_cand_id()
} else if test_case == 1 {
generate_pwd()
} else {
generate_ufrag()
};

rs.push(s);
}
wg.wait().await;

let rs = rands.lock().await;
assert_eq!(rs.len(), N, "{name} Failed to generate randoms");

for i in 0..N {
Expand Down

0 comments on commit 0e8f3bf

Please sign in to comment.