ingraph 0.1.0

A declaration-driven indexing framework: records and nodes are written as Rust types, and the storage rows, the dataflow between them and the GraphQL query surface are emitted from the declaration.
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
use core::{pin::pin, time::Duration};

use std::{
  sync::{
    Arc,
    atomic::{AtomicBool, AtomicUsize, Ordering},
  },
  thread,
};

use super::{Arm, Taken, arm, bounded, park_on, select};

/// What a two-arm select answers, and the classification the arms meet at.
#[derive(Debug, PartialEq, Eq)]
enum Which {
  Left(u8),
  Right(u8),
}

// ---------------------------------------------------------------------------------------------
// The four mode combinations. ONE channel carries all of them, which is the property the wrapper
// exists to keep: a body's blocking loop and an engine's task meet on the same edge without a
// bridge between two channel families.
// ---------------------------------------------------------------------------------------------

#[test]
fn a_thread_producer_reaches_a_thread_consumer() {
  let (tx, rx) = bounded::<u8>(2);
  let producer = thread::spawn(move || {
    tx.send(1).expect("the consumer is here");
    tx.send(2).expect("the consumer is here");
  });
  assert_eq!(rx.recv(), Some(1));
  assert_eq!(rx.recv(), Some(2));
  producer.join().expect("the producer thread");
  assert_eq!(rx.recv(), None, "every sender is gone");
}

#[tokio::test]
async fn a_thread_producer_reaches_a_task_consumer() {
  let (tx, rx) = bounded::<u8>(2);
  let producer = thread::spawn(move || {
    tx.send(1).expect("the consumer is here");
    tx.send(2).expect("the consumer is here");
  });
  assert_eq!(rx.recv_async().await, Some(1));
  assert_eq!(rx.recv_async().await, Some(2));
  producer.join().expect("the producer thread");
  assert_eq!(rx.recv_async().await, None);
}

#[tokio::test]
async fn a_task_producer_reaches_a_thread_consumer() {
  let (tx, rx) = bounded::<u8>(2);
  let consumer = thread::spawn(move || {
    let mut taken = Vec::new();
    while let Some(item) = rx.recv() {
      taken.push(item);
    }
    taken
  });
  tx.send_async(1).await.expect("the consumer is here");
  tx.send_async(2).await.expect("the consumer is here");
  drop(tx);
  assert_eq!(consumer.join().expect("the consumer thread"), [1, 2]);
}

#[tokio::test]
async fn a_task_producer_reaches_a_task_consumer() {
  let (tx, rx) = bounded::<u8>(2);
  let producer = tokio::spawn(async move {
    tx.send_async(1).await.expect("the consumer is here");
    tx.send_async(2).await.expect("the consumer is here");
  });
  assert_eq!(rx.recv_async().await, Some(1));
  assert_eq!(rx.recv_async().await, Some(2));
  producer.await.expect("the producer task");
  assert_eq!(rx.recv_async().await, None);
}

// ---------------------------------------------------------------------------------------------
// The bound, and the wait that makes it mean something.
// ---------------------------------------------------------------------------------------------

#[test]
fn the_capacity_is_a_number_because_there_is_no_unbounded_door() {
  // `Outbox::capacity` one layer up answers an option, because a declared edge may resolve
  // unbounded. This face has no such constructor, so the absence has nothing to represent.
  let (tx, rx) = bounded::<u8>(3);
  assert_eq!(tx.capacity(), 3);
  assert_eq!(rx.capacity(), 3);
  assert!(tx.is_empty());
  tx.send(1).expect("room");
  assert_eq!(tx.len(), 1);
  assert_eq!(rx.len(), 1);
}

#[test]
fn a_full_conduit_blocks_the_thread_until_a_receive_makes_room() {
  // Capacity ONE, so the second item cannot be taken until the consumer takes the first. The sender
  // WAITING — rather than dropping, or growing — is the whole backpressure posture.
  let (tx, rx) = bounded::<u8>(1);
  tx.send(1).expect("room for one");

  let sent = Arc::new(AtomicUsize::new(0));
  let producer = {
    let tx = tx.clone();
    let sent = sent.clone();
    thread::spawn(move || {
      for item in 2..=4 {
        tx.send(item).expect("the consumer is here");
        sent.fetch_add(1, Ordering::SeqCst);
      }
    })
  };

  thread::sleep(Duration::from_millis(50));
  assert_eq!(
    sent.load(Ordering::SeqCst),
    0,
    "nothing gets through while the one slot is occupied"
  );

  let mut taken = Vec::new();
  while taken.len() < 4 {
    taken.push(rx.recv().expect("the producer is still alive"));
  }
  producer.join().expect("the producer thread");
  assert_eq!(taken, [1, 2, 3, 4], "every item arrived; none was dropped");
}

#[tokio::test]
async fn a_full_conduit_parks_the_task_until_a_receive_makes_room() {
  let (tx, rx) = bounded::<u8>(1);
  tx.send_async(1).await.expect("room for one");

  let producer = {
    let tx = tx.clone();
    tokio::spawn(async move {
      tx.send_async(2).await.expect("eventually room");
    })
  };
  // The task cannot finish until a slot frees, and taking one is what frees it.
  assert_eq!(rx.recv_async().await, Some(1));
  producer.await.expect("the producer task");
  assert_eq!(rx.recv_async().await, Some(2));
}

#[test]
fn a_zero_capacity_conduit_is_a_rendezvous_rather_than_a_refusal() {
  // The strongest bound the type can carry: the send ends when a receive takes the item, so there
  // is no queue at all between the two parties.
  let (tx, rx) = bounded::<u8>(0);
  assert_eq!(tx.capacity(), 0);
  assert_eq!(
    tx.try_send(1).expect_err("nowhere to park it").into_inner(),
    1,
    "an impatient door finds a rendezvous permanently full"
  );

  let producer = thread::spawn(move || tx.send(7).expect("the consumer is here"));
  assert_eq!(rx.recv(), Some(7));
  producer.join().expect("the producer thread");
}

// ---------------------------------------------------------------------------------------------
// The impatient doors, and the three answers a receive can have.
// ---------------------------------------------------------------------------------------------

#[test]
fn try_send_refuses_a_full_conduit_and_a_gone_one_alike_and_the_predicate_tells_them_apart() {
  let (tx, rx) = bounded::<u8>(1);
  tx.try_send(1).expect("room for one");

  let full = tx.try_send(2).expect_err("the one slot is occupied");
  assert_eq!(full.into_inner(), 2, "the item comes back");
  assert!(
    !tx.is_disconnected(),
    "full, not gone — and this is what says which"
  );

  drop(rx);
  let gone = tx.try_send(3).expect_err("the consumer has hung up");
  assert!(tx.is_disconnected());
  assert_eq!(
    gone.to_string(),
    "the item was not taken — the conduit is full, or every receiver has hung up",
    "ONE sentence for the two failures, because the predicate above is what says which"
  );
  assert_eq!(gone.into_inner(), 3);
}

#[test]
fn try_recv_answers_empty_then_the_item_then_hung_up() {
  let (tx, rx) = bounded::<u8>(2);
  assert_eq!(rx.try_recv(), Taken::Empty, "nothing is queued yet");

  tx.send(5).expect("room");
  assert_eq!(rx.try_recv(), Taken::Item(5));
  assert!(rx.try_recv().is_empty());

  tx.send(6).expect("room");
  drop(tx);
  assert_eq!(
    rx.try_recv(),
    Taken::Item(6),
    "a disconnected conduit answers what is still queued"
  );
  assert_eq!(rx.try_recv(), Taken::HungUp);
  assert!(rx.is_disconnected());
}

#[test]
fn recv_timeout_reads_its_own_expiry_as_empty_and_the_end_as_hung_up() {
  let (tx, rx) = bounded::<u8>(2);
  assert_eq!(
    rx.recv_timeout(Duration::from_millis(20)),
    Taken::Empty,
    "the expiry says nothing about the channel"
  );

  tx.send(8).expect("room");
  assert_eq!(
    rx.recv_timeout(Duration::from_secs(2)).into_item(),
    Some(8),
    "an item ends the wait early"
  );

  drop(tx);
  assert_eq!(rx.recv_timeout(Duration::from_secs(2)), Taken::HungUp);
}

#[test]
fn a_drain_takes_the_whole_burst_without_waiting() {
  let (tx, rx) = bounded::<u8>(4);
  for item in 1..=3 {
    tx.send(item).expect("room");
  }
  assert_eq!(rx.drain().collect::<Vec<_>>(), [1, 2, 3]);
  assert!(rx.is_empty());
}

#[test]
fn a_second_receiver_is_another_consumer_rather_than_another_copy() {
  // The clone semantics differ by half and the difference is load-bearing: a second SENDER is
  // fan-in, a second RECEIVER shares one queue — which is what lets a node's own worker pool draw
  // from a single in-queue.
  let (tx, first) = bounded::<u8>(4);
  let second = first.clone();
  tx.send(1).expect("room");
  tx.send(2).expect("room");
  let mut taken = [
    first.recv().expect("an item"),
    second.recv().expect("an item"),
  ];
  taken.sort_unstable();
  assert_eq!(taken, [1, 2], "each item reached exactly one of them");
}

// ---------------------------------------------------------------------------------------------
// The select: the same device in both spellings.
// ---------------------------------------------------------------------------------------------

#[test]
fn the_sync_select_serves_both_arms_under_the_turn_cursor() {
  let (left_in, left) = bounded::<u8>(2);
  let (right_in, right) = bounded::<u8>(2);
  left_in.send(1).expect("room");
  right_in.send(2).expect("room");

  // Both arms are ready. Starting at zero takes zero — which is what a fixed order would do every
  // time, and why the cursor exists.
  let first = {
    let mut a = pin!(arm(true, &left, Which::Left));
    let mut b = pin!(arm(true, &right, Which::Right));
    let mut arms: [Arm<'_, Option<Which>>; 2] = [a.as_mut(), b.as_mut()];
    park_on(select(0, &mut arms), Duration::from_secs(2))
  };
  assert_eq!(first, Some(Some((0, Some(Which::Left(1))))));

  // Both ready again, and the cursor has moved past the winner: the quiet arm gets its turn.
  left_in.send(3).expect("room");
  let second = {
    let mut a = pin!(arm(true, &left, Which::Left));
    let mut b = pin!(arm(true, &right, Which::Right));
    let mut arms: [Arm<'_, Option<Which>>; 2] = [a.as_mut(), b.as_mut()];
    park_on(select(1, &mut arms), Duration::from_secs(2))
  };
  assert_eq!(second, Some(Some((1, Some(Which::Right(2))))));
}

#[tokio::test]
async fn the_async_select_serves_both_arms_under_the_turn_cursor() {
  // The SAME device, awaited rather than driven — one select rather than one per engine.
  let (left_in, left) = bounded::<u8>(2);
  let (right_in, right) = bounded::<u8>(2);
  left_in.send_async(1).await.expect("room");
  right_in.send_async(2).await.expect("room");

  let first = {
    let mut a = pin!(arm(true, &left, Which::Left));
    let mut b = pin!(arm(true, &right, Which::Right));
    let mut arms: [Arm<'_, Option<Which>>; 2] = [a.as_mut(), b.as_mut()];
    select(0, &mut arms).await
  };
  assert_eq!(first, Some((0, Some(Which::Left(1)))));

  left_in.send_async(3).await.expect("room");
  let second = {
    let mut a = pin!(arm(true, &left, Which::Left));
    let mut b = pin!(arm(true, &right, Which::Right));
    let mut arms: [Arm<'_, Option<Which>>; 2] = [a.as_mut(), b.as_mut()];
    select(1, &mut arms).await
  };
  assert_eq!(second, Some((1, Some(Which::Right(2)))));
}

#[test]
fn a_hung_up_arm_says_so_once_and_then_retires_from_the_rotation() {
  let (dead_in, dead) = bounded::<u8>(1);
  let (live_in, live) = bounded::<u8>(1);
  drop(dead_in);

  // OPEN over a hung-up channel: the arm answers `None`, which is how the loop learns to close it.
  let told = {
    let mut a = pin!(arm(true, &dead, Which::Left));
    let mut b = pin!(arm(true, &live, Which::Right));
    let mut arms: [Arm<'_, Option<Which>>; 2] = [a.as_mut(), b.as_mut()];
    park_on(select(0, &mut arms), Duration::from_secs(2))
  };
  assert_eq!(told, Some(Some((0, None))));

  // CLOSED, and now it never answers at all — which is what keeps a disconnected channel from
  // spinning the select, since a receive on one returns immediately.
  live_in.send(9).expect("room");
  let served = {
    let mut a = pin!(arm(false, &dead, Which::Left));
    let mut b = pin!(arm(true, &live, Which::Right));
    let mut arms: [Arm<'_, Option<Which>>; 2] = [a.as_mut(), b.as_mut()];
    park_on(select(0, &mut arms), Duration::from_secs(2))
  };
  assert_eq!(served, Some(Some((1, Some(Which::Right(9))))));
}

#[test]
fn a_select_over_only_retired_arms_waits_out_its_sweep() {
  let (dead_in, dead) = bounded::<u8>(1);
  drop(dead_in);
  let mut a = pin!(arm(false, &dead, Which::Left));
  let mut arms: [Arm<'_, Option<Which>>; 1] = [a.as_mut()];
  assert!(
    park_on(select(0, &mut arms), Duration::from_millis(30)).is_none(),
    "the deadline expires, which is what a park with nothing to hear does"
  );
}

#[test]
fn a_select_over_nothing_is_the_honest_no_channel_left() {
  // Not a future that hangs: a loop whose every arm has closed has nothing to wait on, and the
  // answer to that is shutdown rather than a park nobody ever ends.
  let mut arms: [Arm<'_, u8>; 0] = [];
  assert_eq!(
    park_on(select(0, &mut arms), Duration::from_millis(50)),
    Some(None)
  );
}

#[test]
fn a_timed_out_park_leaves_the_message_where_the_next_one_finds_it() {
  // The deadline DROPS an unfinished receive. What it must not do is take the message with it: the
  // whole select rests on a dropped arm losing nothing.
  let (tx, rx) = bounded::<u8>(4);
  assert!(park_on(rx.recv_async(), Duration::from_millis(30)).is_none());
  tx.send(4).expect("room");
  assert_eq!(
    park_on(rx.recv_async(), Duration::from_secs(2)),
    Some(Some(4))
  );
}

// ---------------------------------------------------------------------------------------------
// THE PROBE: waiting is not taking, and one queue keeps one order because it has one reader.
// ---------------------------------------------------------------------------------------------

#[test]
fn a_probe_answers_what_is_queued_and_takes_none_of_it() {
  let (tx, rx) = bounded::<u8>(4);
  tx.send(1).expect("room");
  tx.send(2).expect("room");

  assert!(rx.readable(), "two items are queued");
  assert_eq!(rx.len(), 2, "the probe took one of them");
  // And AGAIN: a probe is a reading of the depth, so it answers the same thing twice.
  assert!(rx.readable());
  assert_eq!(rx.try_recv(), Taken::Item(1));
  assert_eq!(rx.try_recv(), Taken::Item(2));
}

#[test]
fn a_probe_over_a_line_nobody_speaks_on_parks_rather_than_answering() {
  // The sender is HELD, which is the inline crew's own case: a line with a sender that never speaks
  // has not ended, so the probe waits instead of reporting one.
  let (tx, rx) = bounded::<u8>(4);
  assert!(
    park_on(rx.readable_async(), Duration::from_millis(50)).is_none(),
    "the probe answered on a line nothing had reached"
  );
  drop(tx);
}

#[test]
fn a_probe_wakes_on_an_item_and_on_the_last_sender_going() {
  let (tx, rx) = bounded::<u8>(4);
  let speaker = thread::spawn(move || {
    thread::sleep(Duration::from_millis(20));
    tx.send(7).expect("the consumer is here");
    thread::sleep(Duration::from_millis(20));
    // And then GOES, which is the other thing a probe is woken by.
  });

  assert_eq!(
    park_on(rx.readable_async(), Duration::from_secs(5)),
    Some(true),
    "the probe slept through an item landing"
  );
  assert_eq!(rx.try_recv(), Taken::Item(7));
  assert_eq!(
    park_on(rx.readable_async(), Duration::from_secs(5)),
    Some(false),
    "the probe slept through the last sender going"
  );
  speaker.join().expect("the speaker thread");
}

#[test]
fn what_is_queued_outlives_the_end_and_the_probe_says_so() {
  // `false` is the END and not merely *the senders are gone*: a hung-up channel with items in it
  // still has something to take, and a body that stopped at the hang-up would drop them.
  let (tx, rx) = bounded::<u8>(4);
  tx.send(9).expect("room");
  drop(tx);

  assert!(
    rx.readable(),
    "an item outlives the sender that put it there"
  );
  assert_eq!(rx.try_recv(), Taken::Item(9));
  assert!(!rx.readable(), "and now there is nothing and nobody");
}

#[test]
fn a_probe_never_becomes_the_second_reader_a_handoff_could_jump() {
  // THE DEFECT THE PROBE EXISTS FOR, at the transport. A `recv` that waits registers its caller as
  // the queue's next reader, and a sender may hand its item to that reader instead of queueing it.
  // Two readers of one channel — one parked, one taking — therefore deliver a single producer's
  // stream out of order. A probe registers nothing that can be handed anything, so the sequence
  // below is the queue's own however the two doors interleave.
  let (tx, rx) = bounded::<u8>(8);
  let mut watching = pin!(rx.readable_async());
  // Poll ONCE and leave it parked: this is the arm a body holds over a channel it reads elsewhere.
  assert!(park_on(watching.as_mut(), Duration::from_millis(20)).is_none());

  let speaker = thread::spawn(move || {
    for step in 0..6u8 {
      tx.send(step).expect("the consumer is here");
    }
  });
  speaker.join().expect("the speaker thread");

  // Taken with the probe still parked over the same channel.
  let mut took = Vec::new();
  while let Taken::Item(item) = rx.try_recv() {
    took.push(item);
  }
  assert_eq!(took, [0, 1, 2, 3, 4, 5], "the queue is the only order");
  // NOTHING WAS HELD BACK IN THE PROBE: the speaker has gone and the queue is drained, so what the
  // still-parked probe has left to say is the END rather than an item it was sitting on.
  assert_eq!(
    park_on(watching.as_mut(), Duration::from_secs(5)),
    Some(false)
  );
}

#[test]
fn a_probe_that_expires_gives_its_seat_back() {
  // A blocking driver mints a FRESH waker per call, so a wake list keyed on the waker alone would
  // grow by one for every expiry — and an armed loop over a quiet channel expires every sweep for
  // as long as it runs. The seat is what makes the list the length of the probes that exist.
  let (tx, rx) = bounded::<u8>(4);
  for _ in 0..200 {
    assert!(park_on(rx.readable_async(), Duration::from_millis(1)).is_none());
  }
  assert_eq!(rx.parked(), 0, "an expired probe left its waker behind");

  // And a probe that is still parked holds exactly one seat, however often it is polled.
  {
    let mut watching = pin!(rx.readable_async());
    for _ in 0..20 {
      assert!(park_on(watching.as_mut(), Duration::from_millis(1)).is_none());
    }
    assert_eq!(rx.parked(), 1, "one probe took more than one seat");
  }
  assert_eq!(rx.parked(), 0, "a dropped probe left its waker behind");
  drop(tx);
}

/// **THE LAST ITEM AND THE LAST SENDER, RACING — `readable` could answer `false` over a queue that
/// was not empty, and a drain that believed it lost the item.**
///
/// *Empty* and *closed* are two reads of two words, and a sender that queues its last item and then
/// goes lands BETWEEN them: the depth is read while the queue is still empty, the sender queues, the
/// sender drops, the count is read at zero, and the composed answer — *ended, with nothing on it* —
/// is false the moment it is given.
///
/// THE SHAPE IS `Crew::wind_down`'s VERBATIM, which is where the loss was first measured: drain what
/// is there, ask whether to go round again, stop on `false`. A probe that lies there is a `close()`
/// handing back fewer results than the benches made — silently, because a lost item is nobody's
/// error.
///
/// SEVERAL SENDERS AND A LOAD, both deliberate. The window only opens at the LAST sender's going, so
/// a lone one gives one attempt per round where four give the reader four chances to be looking at
/// the wrong one of the two words; and the reader has to be descheduled BETWEEN two loads, which is
/// a thing a busy machine does and an idle one does not — the sharding device's own contended lane
/// is loaded for the same reason and this is the same defect one layer down.
///
/// PROBABILISTIC, and it says so rather than pretending. Measured on the unfixed probe: it loses
/// items well inside this many rounds under this load. On the repaired one the count is zero, which
/// is the only number this assertion accepts.
#[test]
fn a_probe_never_answers_ended_over_a_queue_that_still_holds_something() {
  let stop = Arc::new(AtomicBool::new(false));
  let burners: Vec<_> = (0..8)
    .map(|_| {
      let stop = Arc::clone(&stop);
      thread::spawn(move || {
        let mut spun = 0u64;
        while !stop.load(Ordering::Relaxed) {
          spun = spun.wrapping_mul(6_364_136_223_846_793_005).wrapping_add(1);
          core::hint::black_box(spun);
        }
      })
    })
    .collect();

  let mut lost = 0usize;
  let mut first = 0usize;
  for round in 0..3_000 {
    let (tx, rx) = bounded::<u8>(4);
    // FOUR senders, each queueing one item and going on the next instruction — the crew's shape,
    // where the workers are the only senders and the line ends when the last of them finishes.
    let gate = Arc::new(std::sync::Barrier::new(5));
    let senders: Vec<_> = (0..4u8)
      .map(|which| {
        let tx = tx.clone();
        let gate = Arc::clone(&gate);
        thread::spawn(move || {
          gate.wait();
          tx.send(which).expect("the receiver is alive");
        })
      })
      .collect();
    drop(tx);

    gate.wait();
    let mut taken = 0usize;
    loop {
      while let Taken::Item(_) = rx.try_recv() {
        taken += 1;
      }
      if !rx.readable() {
        break;
      }
    }
    for sender in senders {
      sender.join().expect("the sender ends");
    }

    if taken != 4 {
      if lost == 0 {
        first = round;
      }
      lost += 1;
    }
  }

  stop.store(true, Ordering::Relaxed);
  for burner in burners {
    burner.join().expect("the burner ends");
  }
  assert_eq!(
    lost, 0,
    "the drain stopped {lost} times on a probe that answered `ended` over a queue that still held \
     an item — first at round {first}. The item is lost, and nothing reports it"
  );
}