Skip to content

Commit 15e2898

Browse files
committed
Remove the dependence of std::io::test on rand.
This replaces it with a manual "task rng" using XorShift and a crappy seeding mechanism. Theoretically good enough for the purposes though (unique for tests).
1 parent 6fa4bbe commit 15e2898

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

src/libstd/io/test.rs

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,9 @@
1212

1313
#[macro_escape];
1414

15+
use libc;
1516
use os;
1617
use prelude::*;
17-
use rand;
18-
use rand::Rng;
1918
use std::io::net::ip::*;
2019
use sync::atomics::{AtomicUint, INIT_ATOMIC_UINT, Relaxed};
2120

@@ -65,10 +64,18 @@ pub fn next_test_port() -> u16 {
6564

6665
/// Get a temporary path which could be the location of a unix socket
6766
pub fn next_test_unix() -> Path {
67+
static mut COUNT: AtomicUint = INIT_ATOMIC_UINT;
68+
// base port and pid are an attempt to be unique between multiple
69+
// test-runners of different configurations running on one
70+
// buildbot, the count is to be unique within this executable.
71+
let string = format!("rust-test-unix-path-{}-{}-{}",
72+
base_port(),
73+
unsafe {libc::getpid()},
74+
unsafe {COUNT.fetch_add(1, Relaxed)});
6875
if cfg!(unix) {
69-
os::tmpdir().join(rand::task_rng().gen_ascii_str(20))
76+
os::tmpdir().join(string)
7077
} else {
71-
Path::new(r"\\.\pipe\" + rand::task_rng().gen_ascii_str(20))
78+
Path::new(r"\\.\pipe\" + string)
7279
}
7380
}
7481

0 commit comments

Comments
 (0)