Skip to content

Commit

Permalink
Add concurrent_recursive_mkdir test
Browse files Browse the repository at this point in the history
  • Loading branch information
dpc committed Mar 13, 2017
1 parent 07188fe commit a63ecf9
Showing 1 changed file with 22 additions and 1 deletion.
23 changes: 22 additions & 1 deletion src/libstd/fs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1782,7 +1782,7 @@ impl DirBuilder {
Err(e) => return Err(e),
}
match path.parent() {
Some(p) => try!(create_dir_all(p)),
Some(p) => try!(self.create_dir_all(p)),
None => return Err(io::Error::new(io::ErrorKind::Other, "failed to create whole tree")),
}
match self.inner.mkdir(path) {
Expand All @@ -1809,6 +1809,7 @@ mod tests {
use rand::{StdRng, Rng};
use str;
use sys_common::io::test::{TempDir, tmpdir};
use thread;

#[cfg(windows)]
use os::windows::fs::{symlink_dir, symlink_file};
Expand Down Expand Up @@ -2276,6 +2277,26 @@ mod tests {
assert!(result.is_err());
}

#[test]
fn concurrent_recursive_mkdir() {
for _ in 0..100 {
let mut dir = tmpdir().join("a");
for _ in 0..100 {
dir = dir.join("a");
}
let mut join = vec!();
for _ in 0..8 {
let dir = dir.clone();
join.push(thread::spawn(move || {
check!(fs::create_dir_all(&dir));
}))
}

// No `Display` on result of `join()`
join.drain(..).map(|join| join.join().unwrap()).count();
}
}

#[test]
fn recursive_mkdir_slash() {
check!(fs::create_dir_all(&Path::new("/")));
Expand Down

0 comments on commit a63ecf9

Please sign in to comment.