Skip to content

Commit 481de08

Browse files
committed
test(global_cache_tracker): verify workspace manifest and target dir recorded correctly
1 parent 0eb4ca7 commit 481de08

File tree

2 files changed

+51
-0
lines changed

2 files changed

+51
-0
lines changed

src/cargo/core/global_cache_tracker.rs

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -558,6 +558,42 @@ impl GlobalCacheTracker {
558558
Ok(rows)
559559
}
560560

561+
// Return all workspace_manifest cache timestamps.
562+
pub fn workspace_manifest_all(&self) -> CargoResult<Vec<(WorkspaceManifestIndex, Timestamp)>> {
563+
let mut stmt = self
564+
.conn
565+
.prepare_cached("SELECT name, timestamp FROM workspace_manifest_index")?;
566+
let rows = stmt
567+
.query_map([], |row| {
568+
let workspace_manifest_path = row.get_unwrap(0);
569+
let timestamp = row.get_unwrap(1);
570+
let kind = WorkspaceManifestIndex {
571+
workspace_manifest_path: workspace_manifest_path,
572+
};
573+
Ok((kind, timestamp))
574+
})?
575+
.collect::<Result<Vec<_>, _>>()?;
576+
Ok(rows)
577+
}
578+
579+
// Return all target dir cache timestamps.
580+
pub fn target_dir_all(&self) -> CargoResult<Vec<(TargetDirIndex, Timestamp)>> {
581+
let mut stmt = self
582+
.conn
583+
.prepare_cached("SELECT name, timestamp FROM target_dir_index")?;
584+
let rows = stmt
585+
.query_map([], |row| {
586+
let target_dir_path = row.get_unwrap(0);
587+
let timestamp = row.get_unwrap(1);
588+
let kind = TargetDirIndex {
589+
target_dir_path: target_dir_path,
590+
};
591+
Ok((kind, timestamp))
592+
})?
593+
.collect::<Result<Vec<_>, _>>()?;
594+
Ok(rows)
595+
}
596+
561597
/// Returns whether or not an auto GC should be performed, compared to the
562598
/// last time it was recorded in the database.
563599
pub fn should_run_auto_gc(&mut self, frequency: Duration) -> CargoResult<bool> {

tests/testsuite/global_cache_tracker.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,10 @@ fn implies_source() {
223223
short_name: "f0a4ee0".into(),
224224
size: None,
225225
});
226+
deferred.mark_workspace_src_used(global_cache_tracker::WorkspaceSrc {
227+
target_dir_path: "/Users/foo/cargo/target".into(),
228+
workspace_manifest_path: "/Users/foo/cargo/Cargo.toml".into(),
229+
});
226230
deferred.save(&mut tracker).unwrap();
227231

228232
let mut indexes = tracker.registry_index_all().unwrap();
@@ -240,6 +244,17 @@ fn implies_source() {
240244
let dbs = tracker.git_db_all().unwrap();
241245
assert_eq!(dbs.len(), 1);
242246
assert_eq!(dbs[0].0.encoded_git_name, "cargo-e7ff1db891893a9e");
247+
248+
let workspace_manifests = tracker.workspace_manifest_all().unwrap();
249+
assert_eq!(workspace_manifests.len(), 1);
250+
assert_eq!(
251+
workspace_manifests[0].0.workspace_manifest_path,
252+
"/Users/foo/cargo/Cargo.toml"
253+
);
254+
255+
let target_dirs = tracker.target_dir_all().unwrap();
256+
assert_eq!(target_dirs.len(), 1);
257+
assert_eq!(target_dirs[0].0.target_dir_path, "/Users/foo/cargo/target");
243258
}
244259

245260
#[cargo_test]

0 commit comments

Comments
 (0)