Skip to content

Commit 87c1fdb

Browse files
committed
Make the kernel_copy tests more robust/concurrent.
These tests write to the same filenames in /tmp and in some cases these files don't get cleaned up properly. This caused issues for us when different users run the tests on the same system, e.g.: ``` ---- sys::unix::kernel_copy::tests::bench_file_to_file_copy stdout ---- thread 'sys::unix::kernel_copy::tests::bench_file_to_file_copy' panicked at 'called `Result::unwrap()` on an `Err` value: Os { code: 13, kind: PermissionDenied, message: "Permission denied" }', library/std/src/sys/unix/kernel_copy/tests.rs:71:10 ---- sys::unix::kernel_copy::tests::bench_file_to_socket_copy stdout ---- thread 'sys::unix::kernel_copy::tests::bench_file_to_socket_copy' panicked at 'called `Result::unwrap()` on an `Err` value: Os { code: 13, kind: PermissionDenied, message: "Permission denied" }', library/std/src/sys/unix/kernel_copy/tests.rs:100:10 ``` Use `std::sys_common::io__test::tmpdir()` to solve this.
1 parent c7cff21 commit 87c1fdb

File tree

1 file changed

+11
-8
lines changed
  • library/std/src/sys/unix/kernel_copy

1 file changed

+11
-8
lines changed

library/std/src/sys/unix/kernel_copy/tests.rs

+11-8
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
1-
use crate::env::temp_dir;
21
use crate::fs::OpenOptions;
32
use crate::io;
43
use crate::io::Result;
54
use crate::io::SeekFrom;
65
use crate::io::{BufRead, Read, Seek, Write};
76
use crate::os::unix::io::AsRawFd;
7+
use crate::sys_common::io::test::tmpdir;
88

99
#[test]
1010
fn copy_specialization() -> Result<()> {
1111
use crate::io::{BufReader, BufWriter};
1212

13-
let path = crate::env::temp_dir();
14-
let source_path = path.join("copy-spec.source");
15-
let sink_path = path.join("copy-spec.sink");
13+
let tmp_path = tmpdir();
14+
let source_path = tmp_path.join("copy-spec.source");
15+
let sink_path = tmp_path.join("copy-spec.sink");
1616

1717
let result: Result<()> = try {
1818
let mut source = crate::fs::OpenOptions::new()
@@ -61,7 +61,8 @@ fn copy_specialization() -> Result<()> {
6161
#[bench]
6262
fn bench_file_to_file_copy(b: &mut test::Bencher) {
6363
const BYTES: usize = 128 * 1024;
64-
let src_path = temp_dir().join("file-copy-bench-src");
64+
let temp_path = tmpdir();
65+
let src_path = temp_path.join("file-copy-bench-src");
6566
let mut src = crate::fs::OpenOptions::new()
6667
.create(true)
6768
.truncate(true)
@@ -71,7 +72,7 @@ fn bench_file_to_file_copy(b: &mut test::Bencher) {
7172
.unwrap();
7273
src.write(&vec![0u8; BYTES]).unwrap();
7374

74-
let sink_path = temp_dir().join("file-copy-bench-sink");
75+
let sink_path = temp_path.join("file-copy-bench-sink");
7576
let mut sink = crate::fs::OpenOptions::new()
7677
.create(true)
7778
.truncate(true)
@@ -90,7 +91,8 @@ fn bench_file_to_file_copy(b: &mut test::Bencher) {
9091
#[bench]
9192
fn bench_file_to_socket_copy(b: &mut test::Bencher) {
9293
const BYTES: usize = 128 * 1024;
93-
let src_path = temp_dir().join("pipe-copy-bench-src");
94+
let temp_path = tmpdir();
95+
let src_path = temp_path.join("pipe-copy-bench-src");
9496
let mut src = OpenOptions::new()
9597
.create(true)
9698
.truncate(true)
@@ -121,7 +123,8 @@ fn bench_file_to_socket_copy(b: &mut test::Bencher) {
121123
#[bench]
122124
fn bench_file_to_uds_copy(b: &mut test::Bencher) {
123125
const BYTES: usize = 128 * 1024;
124-
let src_path = temp_dir().join("uds-copy-bench-src");
126+
let temp_path = tmpdir();
127+
let src_path = temp_path.join("uds-copy-bench-src");
125128
let mut src = OpenOptions::new()
126129
.create(true)
127130
.truncate(true)

0 commit comments

Comments
 (0)