test(wasm-actor): cycle 73 — conditional trap, 3 runtimes, 1000 actors (324 tests)
Added 5 tests: trap on specific byte, three runtimes share engine, spawn with no messages, multiply/divide operations, 1000 actors from same engine stress test. No new bugs found. Authored by Claude, lovingly guided by Zachery Aaron Shores-Chmielewski
This commit is contained in:
parent
7f7e25f3d9
commit
d1de863760
1 changed files with 115 additions and 0 deletions
|
|
@ -10635,3 +10635,118 @@ fn guest_comparison_operations() {
|
||||||
rt.send_to(addr, ByteMessage(vec![0u8; 4])).unwrap();
|
rt.send_to(addr, ByteMessage(vec![0u8; 4])).unwrap();
|
||||||
rt.tick();
|
rt.tick();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ── Cycle 73 ─────────────────────────────────────────────────────────────────
|
||||||
|
|
||||||
|
// Guest that traps on specific payload content (trap-on-0xFF)
|
||||||
|
#[test]
|
||||||
|
fn guest_traps_on_specific_byte_survives_others() {
|
||||||
|
let wat = r#"(module
|
||||||
|
(memory (export "memory") 1)
|
||||||
|
(func (export "alloc") (param $len i32) (result i32) i32.const 1024)
|
||||||
|
(func (export "handle") (param $ptr i32) (param $len i32)
|
||||||
|
;; If first byte is 0xFF, trap
|
||||||
|
(if (i32.and
|
||||||
|
(i32.gt_u (local.get $len) (i32.const 0))
|
||||||
|
(i32.eq (i32.load8_u (local.get $ptr)) (i32.const 0xFF)))
|
||||||
|
(then unreachable)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)"#;
|
||||||
|
let engine = SharedEngine::new().unwrap();
|
||||||
|
let actor = WasmActorBuilder::new(engine, wat::parse_str(wat).unwrap())
|
||||||
|
.build().unwrap();
|
||||||
|
let rt = Runtime::new(RuntimeConfig::default());
|
||||||
|
let addr = rt.spawn(actor).unwrap();
|
||||||
|
|
||||||
|
// Normal message — survives
|
||||||
|
rt.send_to(addr, ByteMessage(vec![0x42])).unwrap();
|
||||||
|
rt.tick();
|
||||||
|
|
||||||
|
// Trap-triggering message — actor survives trap
|
||||||
|
rt.send_to(addr, ByteMessage(vec![0xFF])).unwrap();
|
||||||
|
rt.tick();
|
||||||
|
|
||||||
|
// Another normal message — still alive
|
||||||
|
rt.send_to(addr, ByteMessage(vec![0x00])).unwrap();
|
||||||
|
rt.tick();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Multiple runtimes share one engine, all operate correctly
|
||||||
|
#[test]
|
||||||
|
fn three_runtimes_share_one_engine() {
|
||||||
|
let engine = SharedEngine::new().unwrap();
|
||||||
|
let mut rts = Vec::new();
|
||||||
|
let mut inboxes = Vec::new();
|
||||||
|
|
||||||
|
for _ in 0..3 {
|
||||||
|
let rt = Runtime::new(RuntimeConfig::default());
|
||||||
|
let inbox = rt.new_inbox::<ByteMessage>().unwrap();
|
||||||
|
let actor = WasmActorBuilder::new(engine.clone(), guest_wasm("echo")).build().unwrap();
|
||||||
|
let addr = rt.spawn(actor).unwrap();
|
||||||
|
rt.send_to(addr, framed_msg(inbox.addr(), b"shared-engine")).unwrap();
|
||||||
|
inboxes.push(inbox);
|
||||||
|
rts.push(rt);
|
||||||
|
}
|
||||||
|
|
||||||
|
for rt in &rts {
|
||||||
|
rt.tick();
|
||||||
|
}
|
||||||
|
|
||||||
|
for inbox in &inboxes {
|
||||||
|
let resp = inbox.try_recv().expect("each runtime should echo");
|
||||||
|
assert_eq!(resp.0, b"shared-engine");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Spawn actor, never send any message, stop — clean lifecycle
|
||||||
|
#[test]
|
||||||
|
fn spawn_no_messages_then_stop() {
|
||||||
|
let engine = SharedEngine::new().unwrap();
|
||||||
|
let actor = WasmActorBuilder::new(engine, guest_wasm("echo")).build().unwrap();
|
||||||
|
let rt = Runtime::new(RuntimeConfig::default());
|
||||||
|
let addr = rt.spawn(actor).unwrap();
|
||||||
|
rt.tick(); // idle tick
|
||||||
|
rt.stop_actor(addr);
|
||||||
|
rt.tick(); // cleanup
|
||||||
|
rt.tick(); // verify
|
||||||
|
}
|
||||||
|
|
||||||
|
// Guest with i32.mul and i32.div_u
|
||||||
|
#[test]
|
||||||
|
fn guest_multiply_and_divide() {
|
||||||
|
let wat = r#"(module
|
||||||
|
(memory (export "memory") 1)
|
||||||
|
(func (export "alloc") (param $len i32) (result i32) i32.const 1024)
|
||||||
|
(func (export "handle") (param $ptr i32) (param $len i32)
|
||||||
|
;; Multiply len by 3, divide by 2, store at ptr
|
||||||
|
(i32.store (local.get $ptr)
|
||||||
|
(i32.div_u
|
||||||
|
(i32.mul (local.get $len) (i32.const 3))
|
||||||
|
(i32.const 2)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)"#;
|
||||||
|
let engine = SharedEngine::new().unwrap();
|
||||||
|
let actor = WasmActorBuilder::new(engine, wat::parse_str(wat).unwrap())
|
||||||
|
.build().unwrap();
|
||||||
|
let rt = Runtime::new(RuntimeConfig::default());
|
||||||
|
let addr = rt.spawn(actor).unwrap();
|
||||||
|
rt.send_to(addr, ByteMessage(vec![0u8; 10])).unwrap();
|
||||||
|
rt.tick(); // 10*3/2 = 15
|
||||||
|
}
|
||||||
|
|
||||||
|
// 1000 actors from same engine — stress test engine sharing
|
||||||
|
#[test]
|
||||||
|
fn thousand_actors_from_same_engine() {
|
||||||
|
let engine = SharedEngine::new().unwrap();
|
||||||
|
let rt = Runtime::new(RuntimeConfig::default());
|
||||||
|
|
||||||
|
for _ in 0..1000 {
|
||||||
|
let actor = WasmActorBuilder::new(engine.clone(), guest_wasm("silent"))
|
||||||
|
.build().unwrap();
|
||||||
|
rt.spawn(actor).unwrap();
|
||||||
|
}
|
||||||
|
rt.tick();
|
||||||
|
}
|
||||||
Loading…
Reference in a new issue