{"type":"remove","actor"} shuts the actor down normally, drops its
mailbox and supervisor, and deletes /actor/<id>/. Native actors cannot
be removed. Test in cli/tests/host.rs, documented in PROTOCOL.md.
This commit is contained in:
@@ -494,6 +494,61 @@ async fn explicit_rollback_keeps_current_data() {
|
||||
host.stop().await;
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn remove_shuts_an_actor_down_and_deletes_its_folder() {
|
||||
let world = create_world("remove");
|
||||
let wasm = toolbox_wasm().clone();
|
||||
let (host, mut mailbox) = start(&world).await;
|
||||
let source = passing_source(&world, "source");
|
||||
spawn_type(&host, &mut mailbox, "doomed", &wasm, &source).await;
|
||||
let write = json!({"type": "write", "path": "/data/state", "text": "x"});
|
||||
ask_type(&host, &mut mailbox, "doomed", write, "ok").await;
|
||||
ask_type(&host, &mut mailbox, "doomed", json!({"type": "arm-shutdown"}), "armed").await;
|
||||
|
||||
// Normal shutdown: the actor gets "shutdown" and its last message is routed.
|
||||
let id = host.broker.send("console", Some("broker"), None, None, json!({"type": "remove", "actor": "doomed"}));
|
||||
let (mut removed, mut last_words) = (false, false);
|
||||
tokio::time::timeout(Duration::from_secs(10), async {
|
||||
while !removed || !last_words {
|
||||
let message = mailbox.recv().await.expect("console mailbox closed");
|
||||
if message.reply_to.as_deref() == Some(id.as_str()) {
|
||||
assert_eq!(message.body, json!({"type": "removed", "actor": "doomed"}));
|
||||
removed = true;
|
||||
} else if message.reply_to.as_deref() == Some("broker/shutdown") {
|
||||
assert_eq!(message.body["type"], "shutdown-reply");
|
||||
last_words = true;
|
||||
}
|
||||
}
|
||||
})
|
||||
.await
|
||||
.expect("remove did not answer or did not shut the actor down");
|
||||
assert!(!world.actor_dir("doomed").exists());
|
||||
|
||||
let gone = ask(&host, &mut mailbox, "doomed", json!({"type": "echo", "value": "hi"})).await;
|
||||
assert_eq!(gone.body["type"], "undeliverable");
|
||||
let again = request(&host, &mut mailbox, json!({"type": "remove", "actor": "doomed"})).await;
|
||||
assert_eq!(again.body["type"], "error");
|
||||
let broker = request(&host, &mut mailbox, json!({"type": "remove", "actor": "broker"})).await;
|
||||
assert_eq!(broker.body["type"], "error");
|
||||
assert!(world.actor_dir("broker").exists());
|
||||
|
||||
// The ID is free again: a new spawn starts at version 1 with empty data.
|
||||
assert_eq!(spawn_type(&host, &mut mailbox, "doomed", &wasm, &source).await.body["version"], 1);
|
||||
let read = json!({"type": "read", "path": "/data/state"});
|
||||
ask_type(&host, &mut mailbox, "doomed", read, "error").await;
|
||||
host.stop().await;
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn unknown_broker_request_lists_the_known_ones() {
|
||||
let world = create_world("unknown-request");
|
||||
let (host, mut mailbox) = start(&world).await;
|
||||
let unknown = request(&host, &mut mailbox, json!({"type": "frobnicate"})).await;
|
||||
assert_eq!(unknown.body["type"], "error");
|
||||
assert!(unknown.body["reason"].as_str().unwrap().contains("remove"));
|
||||
host.stop().await;
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn cargo_actor_builds_valid_crates_and_reports_compiler_errors() {
|
||||
let world = create_world("cargo-actor");
|
||||
|
||||
Reference in New Issue
Block a user