Skip to content

Commit 0cf9d2a

Browse files
committed
tests: check file size instead of content sha in purge_caches
Hashing all the files in the workspace was taking a lot of time (around 40 seconds on my computer, with a NVMe disk), significantly slowing down the amount of time needed for running the tests. This commit switches to comparing file sizes, as after all we only care about the workspace size not increasing when purging all caches.
1 parent 6009d68 commit 0cf9d2a

File tree

2 files changed

+6
-9
lines changed

2 files changed

+6
-9
lines changed

Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,4 +45,3 @@ getrandom = { version = "0.1.12", features = ["std"] }
4545
[dev-dependencies]
4646
env_logger = "0.6.1"
4747
tiny_http = "0.7.0"
48-
sha1 = "0.6.0"

tests/integration/purge_caches.rs

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
use failure::Error;
22
use rustwide::cmd::SandboxBuilder;
33
use rustwide::{Crate, Toolchain};
4-
use sha1::{Digest, Sha1};
54
use std::collections::HashMap;
65
use std::path::{Path, PathBuf};
76

@@ -74,7 +73,7 @@ fn should_ignore(base: &Path, path: &Path) -> bool {
7473
#[derive(Debug, PartialEq, Eq)]
7574
struct WorkspaceContents {
7675
base: PathBuf,
77-
files: HashMap<PathBuf, Digest>,
76+
files: HashMap<PathBuf, u64>,
7877
}
7978

8079
impl WorkspaceContents {
@@ -83,14 +82,13 @@ impl WorkspaceContents {
8382

8483
for entry in walkdir::WalkDir::new(path) {
8584
let entry = entry?;
86-
if !entry.metadata()?.is_file() {
85+
let metadata = entry.metadata()?;
86+
87+
if !metadata.is_file() {
8788
continue;
8889
}
8990

90-
let mut sha = Sha1::new();
91-
sha.update(&std::fs::read(entry.path())?);
92-
93-
files.insert(entry.path().into(), sha.digest());
91+
files.insert(entry.path().into(), metadata.len());
9492
}
9593

9694
Ok(Self {
@@ -111,7 +109,7 @@ impl WorkspaceContents {
111109

112110
if let Some(end_digest) = other.files.remove(&path) {
113111
if start_digest != end_digest {
114-
println!("file {} changed", path.display());
112+
println!("file {} changed its size", path.display());
115113
same = false;
116114
}
117115
} else {

0 commit comments

Comments
 (0)