1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
//! Loom model tests for the mailbox protocol (run with
//! `RUSTFLAGS="--cfg loom" cargo test --release --features loom loom --
//! --test-threads=1`).
//!
//! The models live in [`actor_kit::loom_mailbox`]: a loom-native double of
//! the mailbox's crate-owned discipline (permit/size accounting, the
//! enable-before-check recv handshake) with the trusted third-party
//! internals (tokio Semaphore/Notify, crossbeam ArrayQueue) replaced by
//! loom stand-ins. See that module's docs for the precise mapping.
//!
//! Scenarios per invariant:
//! * capacity gate — `loom_mailbox_capacity_gate_two_senders`,
//! `loom_mailbox_permit_conservation_roundtrip`
//! * permit/size conservation & no loss/duplication —
//! `loom_mailbox_permit_conservation_roundtrip`,
//! `loom_mailbox_two_senders_receiver_drains_via_handshake`
//! * no lost wakeup — `loom_mailbox_recv_no_lost_wakeup`,
//! `loom_mailbox_two_senders_receiver_drains_via_handshake`
// --- Non-vacuousness proof (seeded race) --------------------------------
//
// Uncomment and run: the model MUST FAIL — loom reports the receiver
// parked forever ("deadlock detected") in exactly the interleaving the
// crate's enable-before-check ordering forecloses. It exercises the
// deliberately broken recv variant in
// `loom_mailbox::model_broken_recv_loses_wakeup`, which checks queue
// emptiness *before* registering with the wakeup gate: receiver checks
// empty → sender pushes + notifies (no waiter registered) → receiver
// registers → parks with no future notification. If this test ever
// *passes*, the wakeup models above are vacuous and must be fixed.
//
// #[test]
// #[should_panic(expected = "deadlock")]
// fn loom_broken_recv_loses_wakeup_is_caught() {
// actor_kit::loom_mailbox::model_broken_recv_loses_wakeup();
// }