Add `concurrent_recursive_mkdir` test

This commit is contained in:
Dawid Ciężarkiewicz 2017-03-12 23:07:16 -07:00
parent 0ec28b796d
commit f2adee74a3
1 changed files with 22 additions and 1 deletions

View File

@ -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) {
@ -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};
@ -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("/")));