indicatrix-worker 0.7.2

Coordinator and render worker for an indicatrix-backed design catalogue. `serve` (default build) is the coordinator: it serves indicatrix-net's read-only design-library protocol to viewers over mutual TLS and accepts joining render workers on a separate worker port. The optional `worker` feature adds render capacity -- `join` (dial a coordinator and render its requests), `serve --render` (render with the coordinator's own CPU/GPU) and `render` (a one-shot scene-to-PNG CLI).
Documentation
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
//! Coordinator job limits: a global memory budget for
//! in-flight jobs ([`MemoryBudget`]) and the per-viewer limits ([`ViewerQueues`]): one
//! active throughput job per viewer certificate, first in first out, and up to a cap of
//! whole-image jobs at once.

use super::Coordinator;
use indicatrix_dispatch::ParkedBudget;
use std::{
    collections::{BTreeMap, HashMap, VecDeque},
    fmt,
    sync::{Arc, Condvar, Mutex, PoisonError},
    time::Duration,
};

/// Bytes of one full-resolution `Vec3` radiance pixel.
const BYTES_PER_PIXEL: u64 = 12;

/// Full-resolution `Vec3` buffers one coordinator job holds at once regardless of how
/// many lanes it runs: the emitter's pending delta, running total and spare, and the
/// lane pool's merged sum. The per-lane buffers ([`FRAME_BUFFERS_PER_LANE`]) and chunks
/// parked ahead of the merge frontier (charged through [`JobParkedBudget`]) come on top.
pub const FRAME_BUFFERS_PER_JOB: u64 = 4;

/// Full-resolution `Vec3` buffers one lane of a job can hold at the same time, counted
/// from the code:
///
/// - a joined worker lane: the reply accumulator of the request in flight
///   (`lanes::chunk::Reply::new`'s `sum`), the running total the chunk's requests fold
///   into (`lanes::JoinedWorkerLane::run_on`'s `total`, which becomes the chunk result)
///   and the copy held back for the emitter until the merge confirms the chunk
///   (`producer::SinkLane::render_chunk`'s `pending`, which a chunk the merger refused
///   leaves in place while the next chunk already runs);
/// - the coordinator's own lane: the tracer's pending delta
///   (`stream_emit::SharedState::new`), the returned sum (`stream_emit::trace_range`'s
///   `sum`) and the hybrid calibration buffer (`calibrate_hybrid_split`'s `calib_buf`),
///   with the same `pending` copy replacing the delta once the chunk returns.
///
/// Both kinds peak at three, so the estimate charges three for every lane.
pub const FRAME_BUFFERS_PER_LANE: u64 = 3;

/// Bytes the lane-independent part of a `width x height` job is charged against
/// [`MemoryBudget`]: `width * height * 12 * FRAME_BUFFERS_PER_JOB`.
///
/// A job with a reserved viewer contribution (`FinalImageRequest.viewer_samples > 0`)
/// and a job with an HDR map are charged more on top of this, and every lane adds
/// [`lane_bytes`]; [`job_estimate_bytes`] is the whole admission figure.
#[must_use]
pub fn job_bytes(width: u32, height: u32) -> u64 {
    frame_bytes(width, height) * FRAME_BUFFERS_PER_JOB
}

/// Bytes `lanes` lanes of a `width x height` job are charged:
/// `width * height * 12 * FRAME_BUFFERS_PER_LANE` each.
#[must_use]
pub fn lane_bytes(width: u32, height: u32, lanes: u32) -> u64 {
    frame_bytes(width, height) * FRAME_BUFFERS_PER_LANE * u64::from(lanes)
}

/// Bytes the viewer's reserved contribution holds while it is in flight: one full-resolution
/// buffer (`stream_emit::ContributionSlot`).
#[must_use]
pub fn contribution_bytes(width: u32, height: u32) -> u64 {
    frame_bytes(width, height)
}

/// Bytes of the HDR map a job pins for its whole run: the encoded file (shared by every
/// lane through one `Arc`, see `assets::HeldAsset::bytes`) and, when the own lane
/// renders it, the decoded texels (`width * height * 12`). The importance-sampling
/// tables built beside the texels are not included.
#[must_use]
pub fn hdr_bytes(encoded_len: u64, decoded_texels: Option<u64>) -> u64 {
    encoded_len.saturating_add(decoded_texels.map_or(0, |texels| texels.saturating_mul(12)))
}

/// Everything a job is charged against [`MemoryBudget`]: the lane-independent frame
/// buffers ([`job_bytes`]), `lanes` lanes ([`lane_bytes`]) and `extra_bytes` (the
/// [`contribution_bytes`] and [`hdr_bytes`] the job holds). The producer reserves the
/// lane-independent part and `extra_bytes` when the job starts and the lane part once
/// the lanes are checked out; the sum is what must fit.
#[must_use]
pub fn job_estimate_bytes(width: u32, height: u32, lanes: u32, extra_bytes: u64) -> u64 {
    job_bytes(width, height)
        .saturating_add(lane_bytes(width, height, lanes))
        .saturating_add(extra_bytes)
}

/// Bytes of one full-resolution `Vec3` frame.
fn frame_bytes(width: u32, height: u32) -> u64 {
    u64::from(width) * u64::from(height) * BYTES_PER_PIXEL
}

/// A global cap on the bytes in-flight coordinator jobs may hold.
pub struct MemoryBudget {
    cap: u64,
    used: Mutex<u64>,
}

/// Bytes reserved from a [`MemoryBudget`], returned on drop.
pub struct Reservation<'a> {
    budget: &'a MemoryBudget,
    bytes: u64,
}

impl MemoryBudget {
    /// A budget of `cap` bytes.
    #[must_use]
    pub const fn new(cap: u64) -> Self {
        Self {
            cap,
            used: Mutex::new(0),
        }
    }

    /// The cap in bytes.
    #[must_use]
    pub const fn cap(&self) -> u64 {
        self.cap
    }

    /// Reserves `bytes`, or returns the bytes already in use when that would exceed the
    /// cap (nothing is queued: the request is refused).
    ///
    /// # Errors
    ///
    /// `Err(in_use)` past the cap.
    pub fn try_reserve(&self, bytes: u64) -> Result<Reservation<'_>, u64> {
        let mut used = self.used.lock().unwrap_or_else(PoisonError::into_inner);
        if used.saturating_add(bytes) > self.cap {
            return Err(*used);
        }
        *used += bytes;
        drop(used);
        Ok(Reservation {
            budget: self,
            bytes,
        })
    }

    /// Bytes currently reserved.
    #[must_use]
    pub fn in_use(&self) -> u64 {
        *self.used.lock().unwrap_or_else(PoisonError::into_inner)
    }

    /// Charges `bytes` against the cap without an RAII guard: for a caller (a
    /// [`indicatrix_dispatch::Merger`]'s parked chunks, see [`JobParkedBudget`]) that
    /// reserves and releases from entirely different call sites -- not one scope a
    /// [`Reservation`] could span. `false` past the cap; nothing is charged then.
    pub fn charge(&self, bytes: u64) -> bool {
        let mut used = self.used.lock().unwrap_or_else(PoisonError::into_inner);
        if used.saturating_add(bytes) > self.cap {
            return false;
        }
        *used += bytes;
        true
    }

    /// Releases `bytes` charged through [`Self::charge`].
    pub fn uncharge(&self, bytes: u64) {
        let mut used = self.used.lock().unwrap_or_else(PoisonError::into_inner);
        *used = used.saturating_sub(bytes);
    }
}

impl Drop for Reservation<'_> {
    fn drop(&mut self) {
        let mut used = self
            .budget
            .used
            .lock()
            .unwrap_or_else(PoisonError::into_inner);
        *used = used.saturating_sub(self.bytes);
    }
}

/// Per-viewer limits: FIFO queues with at most one active throughput job per viewer
/// (certificate), the rest waiting in arrival order (a fair queue across viewers is
/// backlog), and a counted slot per running whole-image job, which do not queue behind
/// each other up to the cap.
#[derive(Default)]
pub struct ViewerQueues {
    queues: Mutex<(u64, Queues)>,
    changed: Condvar,
    /// Whole-image jobs running per viewer; a viewer with none has no entry.
    slots: Mutex<BTreeMap<Arc<str>, u32>>,
    slot_freed: Condvar,
}

/// Each viewer's waiting and active tickets, front = active.
type Queues = HashMap<Arc<str>, VecDeque<u64>>;

/// A viewer's turn: its job is the active one until this is dropped.
pub struct Turn<'a> {
    queues: &'a ViewerQueues,
    viewer: Arc<str>,
    ticket: u64,
}

/// One of a viewer's whole-image job slots, given back when this is dropped.
pub struct SlotGuard<'a> {
    queues: &'a ViewerQueues,
    viewer: Arc<str>,
}

/// What a running job holds in its viewer's limits until it ends: its FIFO [`Turn`], one
/// of the viewer's whole-image [`SlotGuard`]s, or nothing (live-view jobs). Everything it
/// holds is released when it is dropped.
#[derive(Default)]
pub struct Admission<'a> {
    _turn: Option<Turn<'a>>,
    _slot: Option<SlotGuard<'a>>,
}

impl<'a> Admission<'a> {
    /// A job running in its viewer's FIFO turn.
    #[must_use]
    pub const fn turn(turn: Turn<'a>) -> Self {
        Self {
            _turn: Some(turn),
            _slot: None,
        }
    }

    /// A job running in one of its viewer's whole-image slots.
    #[must_use]
    pub const fn slot(slot: SlotGuard<'a>) -> Self {
        Self {
            _turn: None,
            _slot: Some(slot),
        }
    }
}

impl ViewerQueues {
    /// How often a waiting job re-checks its cancellation.
    const RECHECK: Duration = Duration::from_millis(50);

    /// Queues a job for `viewer` and blocks until it is at the front, or returns `None`
    /// (dequeued) as soon as `cancelled()` says so.
    pub fn wait_turn(&self, viewer: &Arc<str>, cancelled: impl Fn() -> bool) -> Option<Turn<'_>> {
        let mut guard = self.queues.lock().unwrap_or_else(PoisonError::into_inner);
        let ticket = guard.0;
        guard.0 += 1;
        guard
            .1
            .entry(Arc::clone(viewer))
            .or_default()
            .push_back(ticket);
        loop {
            if guard.1.get(viewer).and_then(VecDeque::front) == Some(&ticket) {
                return Some(Turn {
                    queues: self,
                    viewer: Arc::clone(viewer),
                    ticket,
                });
            }
            if cancelled() {
                Self::remove(&mut guard.1, viewer, ticket);
                drop(guard);
                self.changed.notify_all();
                return None;
            }
            guard = self
                .changed
                .wait_timeout(guard, Self::RECHECK)
                .unwrap_or_else(PoisonError::into_inner)
                .0;
        }
    }

    /// Takes one of `viewer`'s whole-image slots, blocking until fewer than `cap` (at least
    /// one) of its whole-image jobs are running, or returns `None` as soon as `cancelled()`
    /// says so. Slots are not FIFO-ordered: whichever waiter re-checks first takes a freed
    /// one.
    pub fn wait_slot(
        &self,
        viewer: &Arc<str>,
        cap: u32,
        cancelled: impl Fn() -> bool,
    ) -> Option<SlotGuard<'_>> {
        let cap = cap.max(1);
        let mut slots = self.slots.lock().unwrap_or_else(PoisonError::into_inner);
        loop {
            if slots.get(viewer).copied().unwrap_or(0) < cap {
                *slots.entry(Arc::clone(viewer)).or_insert(0) += 1;
                return Some(SlotGuard {
                    queues: self,
                    viewer: Arc::clone(viewer),
                });
            }
            if cancelled() {
                return None;
            }
            slots = self
                .slot_freed
                .wait_timeout(slots, Self::RECHECK)
                .unwrap_or_else(PoisonError::into_inner)
                .0;
        }
    }

    /// Jobs queued or active for `viewer`.
    #[cfg(test)]
    #[must_use]
    pub fn queued(&self, viewer: &str) -> usize {
        self.queues
            .lock()
            .unwrap_or_else(PoisonError::into_inner)
            .1
            .get(viewer)
            .map_or(0, VecDeque::len)
    }

    /// Whole-image slots `viewer` holds.
    #[cfg(test)]
    #[must_use]
    pub fn slots_held(&self, viewer: &str) -> u32 {
        self.slots
            .lock()
            .unwrap_or_else(PoisonError::into_inner)
            .get(viewer)
            .copied()
            .unwrap_or(0)
    }

    fn remove(queues: &mut Queues, viewer: &Arc<str>, ticket: u64) {
        if let Some(queue) = queues.get_mut(viewer) {
            queue.retain(|&t| t != ticket);
            if queue.is_empty() {
                queues.remove(viewer);
            }
        }
    }
}

impl Drop for Turn<'_> {
    fn drop(&mut self) {
        let mut guard = self
            .queues
            .queues
            .lock()
            .unwrap_or_else(PoisonError::into_inner);
        ViewerQueues::remove(&mut guard.1, &self.viewer, self.ticket);
        drop(guard);
        self.queues.changed.notify_all();
    }
}

impl Drop for SlotGuard<'_> {
    fn drop(&mut self) {
        let mut slots = self
            .queues
            .slots
            .lock()
            .unwrap_or_else(PoisonError::into_inner);
        if let Some(running) = slots.get_mut(&self.viewer) {
            *running = running.saturating_sub(1);
            if *running == 0 {
                slots.remove(&self.viewer);
            }
        }
        drop(slots);
        self.queues.slot_freed.notify_all();
    }
}

/// Adapts [`MemoryBudget`] to [`indicatrix_dispatch::ParkedBudget`] so a job's
/// [`indicatrix_dispatch::Merger`] charges its parked (full-frame) buffers against the
/// same coordinator-wide cap [`job_bytes`]'s fixed [`FRAME_BUFFERS_PER_JOB`] charge
/// uses: a stalled lane's straggling frontier would otherwise park an
/// unbounded number of full-frame buffers even though the job's own fixed reservation
/// never grows.
pub struct JobParkedBudget(pub Arc<Coordinator>);

impl fmt::Debug for JobParkedBudget {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        f.debug_struct("JobParkedBudget").finish_non_exhaustive()
    }
}

impl ParkedBudget for JobParkedBudget {
    fn reserve(&self, bytes: u64) -> bool {
        self.0.budget().charge(bytes)
    }

    fn release(&self, bytes: u64) {
        self.0.budget().uncharge(bytes);
    }
}

#[cfg(test)]
mod tests {
    use super::*;
    use std::sync::atomic::{AtomicBool, Ordering};

    #[test]
    fn the_budget_refuses_past_its_cap_and_frees_on_drop() {
        let budget = MemoryBudget::new(100);
        let a = budget.try_reserve(60).unwrap();
        assert_eq!(budget.try_reserve(50).err(), Some(60));
        drop(a);
        assert_eq!(budget.in_use(), 0);
        assert!(budget.try_reserve(100).is_ok());
        assert_eq!(job_bytes(10, 10), 100 * 12 * FRAME_BUFFERS_PER_JOB);
    }

    #[test]
    fn charge_and_uncharge_share_the_cap_with_try_reserve() {
        let budget = MemoryBudget::new(100);
        let reservation = budget.try_reserve(60).unwrap();
        assert!(budget.charge(40));
        assert_eq!(budget.in_use(), 100);
        assert!(!budget.charge(1), "past the shared cap");
        budget.uncharge(40);
        assert_eq!(budget.in_use(), 60);
        drop(reservation);
        assert_eq!(budget.in_use(), 0);
    }

    #[test]
    fn one_viewer_runs_one_job_at_a_time_in_arrival_order() {
        let queues = Arc::new(ViewerQueues::default());
        let viewer: Arc<str> = Arc::from("laptop");
        let other: Arc<str> = Arc::from("desktop");
        let first = queues.wait_turn(&viewer, || false).unwrap();
        // Another viewer is never blocked by this one.
        drop(queues.wait_turn(&other, || false).unwrap());

        let started = Arc::new(AtomicBool::new(false));
        // The waiter reports each pass of its wait loop (`wait_turn` polls `cancelled`
        // once per pass while it is not at the front), so the assertion below runs only
        // after it has provably been queued behind `first` and waited through several
        // passes -- however late the thread was scheduled.
        let (pass_tx, pass_rx) = std::sync::mpsc::channel();
        let waiter = {
            let (queues, viewer, started) = (
                Arc::clone(&queues),
                Arc::clone(&viewer),
                Arc::clone(&started),
            );
            std::thread::spawn(move || {
                let _turn = queues
                    .wait_turn(&viewer, || {
                        let _ = pass_tx.send(());
                        false
                    })
                    .unwrap();
                started.store(true, Ordering::SeqCst);
            })
        };
        for pass in 1..=3 {
            pass_rx
                .recv_timeout(Duration::from_secs(5))
                .unwrap_or_else(|_| {
                    panic!("the second job never reached wait pass {pass} of its viewer's queue")
                });
        }
        assert!(!started.load(Ordering::SeqCst), "the second job must wait");
        assert_eq!(queues.queued("laptop"), 2);
        drop(first);
        waiter.join().unwrap();
        assert!(started.load(Ordering::SeqCst));
        assert_eq!(queues.queued("laptop"), 0);
    }

    /// The default `--max-job-memory-mib` (2 GiB) in bytes.
    const DEFAULT_BUDGET: u64 = 2048 * 1024 * 1024;

    #[test]
    fn the_estimate_charges_every_lane_its_frame_buffers() {
        let (w, h) = (100, 10);
        let frame = 100 * 10 * 12;
        assert_eq!(lane_bytes(w, h, 1), frame * FRAME_BUFFERS_PER_LANE);
        assert_eq!(lane_bytes(w, h, 0), 0);
        assert_eq!(
            job_estimate_bytes(w, h, 5, 7),
            frame * (FRAME_BUFFERS_PER_JOB + 5 * FRAME_BUFFERS_PER_LANE) + 7
        );
        assert_eq!(contribution_bytes(w, h), frame);
        assert_eq!(hdr_bytes(1000, None), 1000);
        assert_eq!(hdr_bytes(1000, Some(10)), 1000 + 120);
    }

    #[test]
    fn an_8k_job_on_ten_lanes_exceeds_the_default_budget_while_1080p_on_two_lanes_fits() {
        let budget = MemoryBudget::new(DEFAULT_BUDGET);
        let huge = job_estimate_bytes(7680, 4320, 10, 0);
        assert!(huge > DEFAULT_BUDGET, "{huge} bytes must not fit");
        assert!(budget.try_reserve(huge).is_err());

        let small = job_estimate_bytes(1920, 1080, 2, 0);
        assert!(small < DEFAULT_BUDGET, "{small} bytes must fit");
        assert!(budget.try_reserve(small).is_ok());
    }

    #[test]
    fn a_cancelled_waiter_leaves_the_queue() {
        let queues = ViewerQueues::default();
        let viewer: Arc<str> = Arc::from("laptop");
        let _first = queues.wait_turn(&viewer, || false).unwrap();
        assert!(queues.wait_turn(&viewer, || true).is_none());
        assert_eq!(queues.queued("laptop"), 1);
    }

    /// `cap` whole-image jobs of one viewer run at once; the next one blocks until one of
    /// them drops its slot, and another viewer's count is its own.
    #[test]
    fn wait_slot_admits_cap_jobs_and_blocks_the_next_until_one_drops() {
        let queues = Arc::new(ViewerQueues::default());
        let viewer: Arc<str> = Arc::from("laptop");
        let other: Arc<str> = Arc::from("desktop");
        let first = queues.wait_slot(&viewer, 2, || false).unwrap();
        let second = queues.wait_slot(&viewer, 2, || false).unwrap();
        assert_eq!(queues.slots_held("laptop"), 2);
        drop(queues.wait_slot(&other, 1, || false).unwrap());
        assert_eq!(
            queues.slots_held("desktop"),
            0,
            "a dropped slot is given back"
        );

        let started = Arc::new(AtomicBool::new(false));
        // As in the FIFO test: the waiter reports each pass of its wait loop, so the
        // assertion below runs only after it has provably waited several passes.
        let (pass_tx, pass_rx) = std::sync::mpsc::channel();
        let waiter = {
            let (queues, viewer, started) = (
                Arc::clone(&queues),
                Arc::clone(&viewer),
                Arc::clone(&started),
            );
            std::thread::spawn(move || {
                let _slot = queues
                    .wait_slot(&viewer, 2, || {
                        let _ = pass_tx.send(());
                        false
                    })
                    .unwrap();
                started.store(true, Ordering::SeqCst);
            })
        };
        for pass in 1..=3 {
            pass_rx
                .recv_timeout(Duration::from_secs(5))
                .unwrap_or_else(|_| {
                    panic!("the third job never reached wait pass {pass} of its viewer's slots")
                });
        }
        assert!(!started.load(Ordering::SeqCst), "the third job must wait");
        assert_eq!(queues.slots_held("laptop"), 2);
        drop(first);
        waiter.join().unwrap();
        assert!(started.load(Ordering::SeqCst));
        assert_eq!(queues.slots_held("laptop"), 1, "only `second` is left");
        drop(second);
        assert_eq!(queues.slots_held("laptop"), 0);
    }

    /// A cancelled waiter gives up without taking a slot; a cap of 0 still admits one job.
    #[test]
    fn a_cancelled_slot_waiter_takes_nothing_and_a_zero_cap_means_one() {
        let queues = ViewerQueues::default();
        let viewer: Arc<str> = Arc::from("laptop");
        let first = queues.wait_slot(&viewer, 0, || false).unwrap();
        assert!(queues.wait_slot(&viewer, 0, || true).is_none());
        assert_eq!(queues.slots_held("laptop"), 1);
        drop(first);
        assert_eq!(queues.slots_held("laptop"), 0);
    }

    /// Dropping an `Admission` gives back whatever it held, and the two kinds do not
    /// count against each other.
    #[test]
    fn an_admission_releases_its_turn_or_slot_when_dropped() {
        let queues = ViewerQueues::default();
        let viewer: Arc<str> = Arc::from("laptop");
        let turn = Admission::turn(queues.wait_turn(&viewer, || false).unwrap());
        let slot = Admission::slot(queues.wait_slot(&viewer, 1, || false).unwrap());
        assert_eq!(
            (queues.queued("laptop"), queues.slots_held("laptop")),
            (1, 1)
        );
        drop(slot);
        assert_eq!(
            (queues.queued("laptop"), queues.slots_held("laptop")),
            (1, 0)
        );
        drop(turn);
        assert_eq!(
            (queues.queued("laptop"), queues.slots_held("laptop")),
            (0, 0)
        );
        drop(Admission::default());
    }
}