Skip to content

Commit 23d136e

Browse files
authored
chore(test): Use tempfile crate to handle temporary file (#2325)
1 parent 207577c commit 23d136e

File tree

2 files changed

+5
-10
lines changed

2 files changed

+5
-10
lines changed

tests/default_stubs/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ tokio-stream = {version = "0.1", features = ["net"]}
1010
tonic = {path = "../../tonic"}
1111

1212
[dev-dependencies]
13-
rand = "0.9"
13+
tempfile = "3.20"
1414

1515
[build-dependencies]
1616
tonic-build = {path = "../../tonic-build" }

tests/default_stubs/tests/default.rs

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -127,21 +127,16 @@ async fn run_services_in_background() -> (SocketAddr, SocketAddr) {
127127

128128
#[cfg(not(target_os = "windows"))]
129129
async fn run_services_in_background_uds() -> (String, String) {
130-
use rand::Rng as _;
131-
use std::{env, fs};
132130
use tokio::net::UnixListener;
133131

134132
let svc = test_server::TestServer::new(Svc {});
135133
let svc_default_stubs = test_default_server::TestDefaultServer::new(Svc {});
136134

137-
let mut rng = rand::rng();
138-
let suffix: String = (0..8)
139-
.map(|_| rng.sample(rand::distr::Alphanumeric) as char)
140-
.collect();
141-
let tmpdir = fs::canonicalize(env::temp_dir())
135+
let tmpdir = tempfile::Builder::new()
136+
.prefix("tonic-test-")
137+
.tempdir()
142138
.unwrap()
143-
.join(format!("tonic_test_{suffix}"));
144-
fs::create_dir(&tmpdir).unwrap();
139+
.keep();
145140

146141
let uds_filepath = tmpdir.join("impl.sock").to_str().unwrap().to_string();
147142
let listener = UnixListener::bind(uds_filepath.as_str()).unwrap();

0 commit comments

Comments
 (0)