Skip to content

Commit 06ff0d0

Browse files
committed
test client doesn't package toolchain twice if the scheduler already has it
1 parent a97136e commit 06ff0d0

File tree

2 files changed

+24
-7
lines changed

2 files changed

+24
-7
lines changed

tests/dist.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -300,13 +300,15 @@ async fn test_dist_cpp_toolchain(message_broker: &str) -> Result<()> {
300300
.await?;
301301

302302
// Run twice to verify toolchain is only uploaded once
303-
for _ in 0..2 {
303+
for i in 0..2 {
304304
let client = system.new_client(&dist_test_sccache_client_cfg(
305305
system.data_dir(),
306306
system.scheduler(0)?.url(),
307307
false,
308308
));
309309

310+
let tc_dir = client.clear_toolchains_cache()?;
311+
310312
cc_compile(&client, system.test_dir()).await?;
311313

312314
let stats = client.stats()?;
@@ -318,6 +320,13 @@ async fn test_dist_cpp_toolchain(message_broker: &str) -> Result<()> {
318320
assert_eq!(0, stats.cache_hits.all());
319321

320322
assert_eq!(system.count_server_toolchains(system.server(0)?)?, 1);
323+
324+
// Ensure the client doesn't package the toolchain again the 2nd time
325+
if i == 0 {
326+
assert_eq!(std::fs::read_dir(tc_dir).map(|dir| dir.count())?, 1);
327+
} else {
328+
assert_eq!(std::fs::read_dir(tc_dir).map(|dir| dir.count())?, 0);
329+
}
321330
}
322331

323332
Ok(())

tests/harness/client.rs

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ impl SccacheClient {
173173
);
174174
}
175175

176-
pub fn clear_disk_cache(&self) -> sccache::errors::Result<()> {
176+
pub fn clear_disk_cache(&self) -> sccache::errors::Result<PathBuf> {
177177
self.zero_stats();
178178
let disk_cache = (|| {
179179
if let Some(cfg_path_idx) = self.envvars.iter().position(|(k, _)| k == "SCCACHE_CONF") {
@@ -191,10 +191,10 @@ impl SccacheClient {
191191
})();
192192
println!("clear_disk_cache: {:?}", disk_cache.dir);
193193
fs::remove_dir_all(&disk_cache.dir)?;
194-
Ok(())
194+
Ok(disk_cache.dir.clone())
195195
}
196196

197-
pub fn clear_toolchains_cache(&self) -> sccache::errors::Result<()> {
197+
pub fn clear_toolchains_cache(&self) -> sccache::errors::Result<PathBuf> {
198198
let dist_config = (|| {
199199
if let Some(cfg_path_idx) = self.envvars.iter().position(|(k, _)| k == "SCCACHE_CONF") {
200200
if let Some((_, cfg_path)) = self.envvars.get(cfg_path_idx) {
@@ -207,9 +207,17 @@ impl SccacheClient {
207207
}
208208
DistConfig::default()
209209
})();
210-
println!("clear_toolchains_cache: {:?}", dist_config.cache_dir);
211-
fs::remove_dir_all(&dist_config.cache_dir)?;
212-
Ok(())
210+
let tc_dir = dist_config.cache_dir.join("client").join("tc");
211+
println!("clear_toolchains_cache: {:?}", tc_dir);
212+
for entry in std::fs::read_dir(&tc_dir)? {
213+
let path = entry?.path();
214+
if fs::symlink_metadata(&path)?.is_dir() {
215+
fs::remove_dir_all(&path)?;
216+
} else {
217+
fs::remove_file(&path)?;
218+
}
219+
}
220+
Ok(tc_dir.clone())
213221
}
214222
}
215223

0 commit comments

Comments
 (0)