Add local CAS cleanup policy
This commit is contained in:
parent
00471bcec0
commit
21920b51b5
10 changed files with 184 additions and 8 deletions
|
|
@ -168,6 +168,90 @@ fn cas_pin_unpin_updates_local_pin_metadata() {
|
|||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn cas_cleanup_removes_unpinned_and_retains_pinned_blobs() {
|
||||
let home = tempfile::tempdir().expect("tempdir");
|
||||
let paths = geth_config::GethPaths::from_home(home.path());
|
||||
let node = geth_node::init_node(&paths).expect("init node");
|
||||
let pinned_path = home.path().join("pinned.txt");
|
||||
let unpinned_path = home.path().join("unpinned.txt");
|
||||
std::fs::write(&pinned_path, b"keep me").expect("write pinned");
|
||||
std::fs::write(&unpinned_path, b"remove me").expect("write unpinned");
|
||||
|
||||
let pinned_hash = match geth_node::handle_request(
|
||||
&node,
|
||||
geth_control::ControlRequest::CasAdd { path: pinned_path },
|
||||
)
|
||||
.expect("add pinned")
|
||||
{
|
||||
geth_control::ControlResponse::CasAdded { hash, .. } => hash,
|
||||
other => panic!("unexpected response: {other:?}"),
|
||||
};
|
||||
let unpinned_hash = match geth_node::handle_request(
|
||||
&node,
|
||||
geth_control::ControlRequest::CasAdd {
|
||||
path: unpinned_path,
|
||||
},
|
||||
)
|
||||
.expect("add unpinned")
|
||||
{
|
||||
geth_control::ControlResponse::CasAdded { hash, .. } => hash,
|
||||
other => panic!("unexpected response: {other:?}"),
|
||||
};
|
||||
geth_node::handle_request(
|
||||
&node,
|
||||
geth_control::ControlRequest::CasPin {
|
||||
hash: pinned_hash.clone(),
|
||||
},
|
||||
)
|
||||
.expect("pin blob");
|
||||
|
||||
let dry_run = geth_node::handle_request(
|
||||
&node,
|
||||
geth_control::ControlRequest::CasCleanup { dry_run: true },
|
||||
)
|
||||
.expect("dry-run cleanup");
|
||||
match dry_run {
|
||||
geth_control::ControlResponse::CasCleanup {
|
||||
removed,
|
||||
retained_pinned,
|
||||
dry_run,
|
||||
} => {
|
||||
assert!(dry_run);
|
||||
assert_eq!(removed, vec![unpinned_hash.clone()]);
|
||||
assert_eq!(retained_pinned, vec![pinned_hash.clone()]);
|
||||
}
|
||||
other => panic!("unexpected response: {other:?}"),
|
||||
}
|
||||
assert!(
|
||||
geth_cas::LocalCas::new(paths.cas_dir())
|
||||
.has(&unpinned_hash)
|
||||
.expect("dry-run keeps unpinned")
|
||||
);
|
||||
|
||||
let cleanup = geth_node::handle_request(
|
||||
&node,
|
||||
geth_control::ControlRequest::CasCleanup { dry_run: false },
|
||||
)
|
||||
.expect("cleanup");
|
||||
match cleanup {
|
||||
geth_control::ControlResponse::CasCleanup {
|
||||
removed,
|
||||
retained_pinned,
|
||||
dry_run,
|
||||
} => {
|
||||
assert!(!dry_run);
|
||||
assert_eq!(removed, vec![unpinned_hash.clone()]);
|
||||
assert_eq!(retained_pinned, vec![pinned_hash.clone()]);
|
||||
}
|
||||
other => panic!("unexpected response: {other:?}"),
|
||||
}
|
||||
|
||||
let cas = geth_cas::LocalCas::new(paths.cas_dir());
|
||||
assert!(cas.has(&pinned_hash).expect("pinned retained"));
|
||||
assert!(!cas.has(&unpinned_hash).expect("unpinned removed"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn auth_explain_distinguishes_discovered_peer_candidates() {
|
||||
let home = tempfile::tempdir().expect("tempdir");
|
||||
|
|
|
|||
Loading…
Reference in a new issue