Skip to content

Commit 7382a2d

Browse files
committed
test(global_cache_tracker): verify workspace manifest and target dir recorded correctly
1 parent d542986 commit 7382a2d

File tree

2 files changed

+51
-0
lines changed

2 files changed

+51
-0
lines changed

src/cargo/core/global_cache_tracker.rs

+36
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

+15
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,10 @@ fn implies_source() {
245245
short_name: "f0a4ee0".into(),
246246
size: None,
247247
});
248+
deferred.mark_workspace_src_used(global_cache_tracker::WorkspaceSrc {
249+
target_dir_path: "/Users/foo/cargo/target".into(),
250+
workspace_manifest_path: "/Users/foo/cargo/Cargo.toml".into(),
251+
});
248252
deferred.save(&mut tracker).unwrap();
249253

250254
let mut indexes = tracker.registry_index_all().unwrap();
@@ -262,6 +266,17 @@ fn implies_source() {
262266
let dbs = tracker.git_db_all().unwrap();
263267
assert_eq!(dbs.len(), 1);
264268
assert_eq!(dbs[0].0.encoded_git_name, "cargo-e7ff1db891893a9e");
269+
270+
let workspace_manifests = tracker.workspace_manifest_all().unwrap();
271+
assert_eq!(workspace_manifests.len(), 1);
272+
assert_eq!(
273+
workspace_manifests[0].0.workspace_manifest_path,
274+
"/Users/foo/cargo/Cargo.toml"
275+
);
276+
277+
let target_dirs = tracker.target_dir_all().unwrap();
278+
assert_eq!(target_dirs.len(), 1);
279+
assert_eq!(target_dirs[0].0.target_dir_path, "/Users/foo/cargo/target");
265280
}
266281

267282
#[cargo_test]

0 commit comments

Comments
 (0)