File operations under /actor/<id>/fs/ become messages from `fs` to <id> (fs_read, fs_write, fs_mkdir, fs_remove, fs_rename) with a 10 s timeout. vfs.rs wraps the wasi:filesystem implementation of wasmtime-wasi.
This commit is contained in:
@@ -216,6 +216,36 @@ async fn actors_can_read_but_not_write_other_actor_data() {
|
||||
host.stop().await;
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn actors_serve_files_under_fs() {
|
||||
// "writer" serves its fs/ from memory (toolbox fs_read / fs_write / fs_remove).
|
||||
let (_, host, mut mailbox) = filesystem_world("actor-fs").await;
|
||||
let file = "/actor/writer/fs/notes/a.txt";
|
||||
let write = json!({"type": "write", "path": file, "text": "hello"});
|
||||
ask_type(&host, &mut mailbox, "reader", write, "ok").await;
|
||||
// The write reached the owner as one fs_write message.
|
||||
let direct = json!({"type": "fs_read", "path": "/notes/a.txt"});
|
||||
let served = ask_type(&host, &mut mailbox, "writer", direct, "fs_file").await;
|
||||
assert_eq!(served.body["text"], "hello");
|
||||
|
||||
let read = json!({"type": "read", "path": file});
|
||||
assert_eq!(ask_type(&host, &mut mailbox, "reader", read, "content").await.body["text"], "hello");
|
||||
let list = json!({"type": "list", "path": "/actor/writer/fs/notes"});
|
||||
assert_eq!(ask_type(&host, &mut mailbox, "reader", list, "entries").await.body["names"], json!(["a.txt"]));
|
||||
let root = json!({"type": "list", "path": "/actor/writer/fs"});
|
||||
assert_eq!(ask_type(&host, &mut mailbox, "reader", root, "entries").await.body["names"], json!(["notes"]));
|
||||
|
||||
// fs_error and undeliverable become errors of the file operation.
|
||||
for path in ["/actor/writer/fs/missing.txt", "/actor/nobody/fs/x"] {
|
||||
ask_type(&host, &mut mailbox, "reader", json!({"type": "read", "path": path}), "error").await;
|
||||
}
|
||||
// An actor that does not answer (here: it is busy reading itself) fails after the timeout.
|
||||
let id = host.broker.send("console", Some("reader"), None, None, json!({"type": "read", "path": "/actor/reader/fs/x"}));
|
||||
let timed_out = receive_reply(&mut mailbox, &id, Duration::from_secs(20)).await;
|
||||
assert_eq!(timed_out.body["type"], "error");
|
||||
host.stop().await;
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn files_are_plain_posix_files() {
|
||||
let (_, host, mut mailbox) = filesystem_world("posix").await;
|
||||
|
||||
Reference in New Issue
Block a user