Skip to content

Commit f2adee7

Browse files
committed
Add concurrent_recursive_mkdir test
1 parent 0ec28b7 commit f2adee7

File tree

1 file changed

+22
-1
lines changed

1 file changed

+22
-1
lines changed

src/libstd/fs.rs

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1782,7 +1782,7 @@ impl DirBuilder {
17821782
Err(e) => return Err(e),
17831783
}
17841784
match path.parent() {
1785-
Some(p) => try!(create_dir_all(p)),
1785+
Some(p) => try!(self.create_dir_all(p)),
17861786
None => return Err(io::Error::new(io::ErrorKind::Other, "failed to create whole tree")),
17871787
}
17881788
match self.inner.mkdir(path) {
@@ -1809,6 +1809,7 @@ mod tests {
18091809
use rand::{StdRng, Rng};
18101810
use str;
18111811
use sys_common::io::test::{TempDir, tmpdir};
1812+
use thread;
18121813

18131814
#[cfg(windows)]
18141815
use os::windows::fs::{symlink_dir, symlink_file};
@@ -2276,6 +2277,26 @@ mod tests {
22762277
assert!(result.is_err());
22772278
}
22782279

2280+
#[test]
2281+
fn concurrent_recursive_mkdir() {
2282+
for _ in 0..100 {
2283+
let mut dir = tmpdir().join("a");
2284+
for _ in 0..100 {
2285+
dir = dir.join("a");
2286+
}
2287+
let mut join = vec!();
2288+
for _ in 0..8 {
2289+
let dir = dir.clone();
2290+
join.push(thread::spawn(move || {
2291+
check!(fs::create_dir_all(&dir));
2292+
}))
2293+
}
2294+
2295+
// No `Display` on result of `join()`
2296+
join.drain(..).map(|join| join.join().unwrap()).count();
2297+
}
2298+
}
2299+
22792300
#[test]
22802301
fn recursive_mkdir_slash() {
22812302
check!(fs::create_dir_all(&Path::new("/")));

0 commit comments

Comments
 (0)