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
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
//! **THE DRIVER, ON A BARE EDGE** — both engines, over a head that is a channel rather than a node.
//!
//! What is under test here is the COALESCING and the COUNT, so the head is the smallest thing that
//! can be one: an [`Inbox`] this file drains and acks by hand. A head that were a real node would
//! add a resident's own scheduling to every assertion about a window, and prove nothing this does
//! not — the launch-level road, where the driver takes its place in a real wind-down, is
//! `ingraph/tests/registry_driver.rs`.
//!
//! # The windows are SHORT and the assertions are AWAITED, never slept through
//!
//! Every wait here is a poll against a generous ceiling rather than a sleep of the length under
//! test: what the driver promises is *not before* and *by then*, and a test that slept exactly the
//! window would be asserting the scheduler's punctuality rather than the machine's.

use core::time::Duration;

use std::{
  sync::{
    Arc,
    atomic::{AtomicUsize, Ordering},
  },
  time::Instant,
};

use agnostic_lite::tokio::TokioRuntime;

use crate::{
  Ack, Feed, ItemId, Lifecycle, RegistryOptions, RetireOrigin, RootState, Stamp, Wake, Yielded,
  drive::{Inbox, Outbox, channel},
};

use super::{DriverEngine, Registry, RegistryDriver};

/// Long enough that a machine holding a key is unmistakably holding it, short enough that a suite
/// waiting for two of them is not a suite anybody notices.
const QUIET: Duration = Duration::from_millis(30);

/// The ceiling every wait in this file is bounded by. It is not a duration under test — it is the
/// point at which *the driver never did the thing* is the honest report.
const CEILING: Duration = Duration::from_secs(10);

/// The head node, as small as a head can be: one bounded edge, drained and acked by hand.
struct Head {
  inbox: Inbox<ItemId, u64>,
  taken: Vec<u64>,
}

impl Head {
  /// A head with room for `depth` deliveries, and the producing half a driver writes through.
  fn open(depth: usize) -> (Outbox<ItemId, u64>, Self) {
    let (outbox, inbox) = channel::<ItemId, u64>(depth);
    (
      outbox,
      Self {
        inbox,
        taken: Vec::new(),
      },
    )
  }

  /// Everything queued right now, TAKEN and ACKED — the ordinary head, which answers as it goes.
  ///
  /// The ack is what releases the driver's own `+1`, so a test that wants to look at the count
  /// mid-flight uses [`held`](Self::held) instead.
  fn drained(&mut self) -> usize {
    let mut took = 0;
    for wake in self.inbox.drain() {
      let Wake::Delivered(delivery) = wake else {
        continue;
      };
      let (payload, custody) = delivery.into_parts();
      let released = payload.keys().copied().collect();
      for item in payload {
        self.taken.push(item.into_value());
        took += 1;
      }
      if let Some(custody) = custody {
        custody.send(Ack::new(released, "head", Lifecycle::Processed(())));
      }
    }
    took
  }

  /// Everything queued right now, taken and NOT acked — the head that is still working, which is the
  /// state the `+1`-until-the-ack is about.
  ///
  /// The released set travels with the token because that is what an ack IS: the keys this delivery
  /// spoke for, read off the delivery rather than guessed from a counter's starting value.
  fn held(&mut self) -> Vec<(std::collections::HashSet<ItemId>, crate::Custody<ItemId>)> {
    let mut holding = Vec::new();
    for wake in self.inbox.drain() {
      let Wake::Delivered(delivery) = wake else {
        continue;
      };
      let (payload, custody) = delivery.into_parts();
      let released = payload.keys().copied().collect();
      for item in payload {
        self.taken.push(item.into_value());
      }
      if let Some(custody) = custody {
        holding.push((released, custody));
      }
    }
    holding
  }

  /// How many keys have reached this head, in arrival order.
  fn taken(&self) -> &[u64] {
    &self.taken
  }

  /// Drain until `count` keys have arrived, or give up at [`CEILING`].
  fn awaiting(&mut self, count: usize) {
    let deadline = Instant::now() + CEILING;
    while self.taken.len() < count {
      let _took = self.drained();
      assert!(
        Instant::now() < deadline,
        "the head waited {CEILING:?} for {count} keys and saw {}: {:?}",
        self.taken.len(),
        self.taken,
      );
      std::thread::sleep(Duration::from_millis(1));
    }
  }
}

/// A family running `options`, and nothing held.
fn family(options: RegistryOptions) -> Arc<Registry<u64>> {
  Arc::new(Registry::new(options))
}

/// Poll `settled` until it holds, or fail at [`CEILING`] saying `whining`.
///
/// A short SLEEP rather than a yield, and the difference is what a yield costs here: the party this
/// file is waiting for is a thread of the driver's own, and a spin racing it for the core is the one
/// way a test can make the thing it is timing slower.
fn awaited(mut settled: impl FnMut() -> bool, whining: &str) {
  let deadline = Instant::now() + CEILING;
  while !settled() {
    assert!(Instant::now() < deadline, "{whining} (waited {CEILING:?})");
    std::thread::sleep(Duration::from_millis(1));
  }
}

/// The knobs most of this file runs under: a real quiet window, the shipped ten-item ceiling, and a
/// wait short enough that a batch of one still lands inside a test's patience.
fn knobs() -> RegistryOptions {
  RegistryOptions::new()
    .with_debounce(QUIET)
    .with_batch_max_wait(QUIET * 2)
}

/// **THE DEBOUNCE, END TO END**: a burst on ONE key is ONE delivery.
#[test]
fn three_touches_in_one_window_are_one_head_delivery() {
  let registry = family(knobs());
  let (outbox, mut head) = Head::open(16);
  let (push, keys) = crate::feed::<u64>(16);
  let driver = RegistryDriver::spawn(Arc::clone(&registry), keys, outbox);

  for _ in 0..3 {
    push.give(7).expect("the driver is listening");
  }
  head.awaiting(1);

  // The window has to be given a chance to produce a SECOND delivery before the absence of one
  // means anything, which is what makes this wait a proof rather than a race won.
  std::thread::sleep(QUIET * 4);
  let _took = head.drained();

  assert_eq!(head.taken(), [7], "one intake for the whole burst");
  drop(driver);
}

/// **THE COUNT TRIGGER**: ten keys close a batch on the ITEM CEILING, with the wait nowhere near.
#[test]
fn ten_keys_close_one_batch_on_the_ceiling() {
  // The wait is thirty seconds HERE and nowhere else, which is the whole assertion: a batch that
  // lands inside `CEILING` landed on the count.
  let registry = family(
    RegistryOptions::new()
      .with_debounce(QUIET)
      .with_batch_max_wait(Duration::from_secs(30)),
  );
  let (outbox, mut head) = Head::open(64);
  let (push, keys) = crate::feed::<u64>(64);
  let driver = RegistryDriver::spawn(Arc::clone(&registry), keys, outbox);

  for key in 0..10 {
    push.give(key).expect("the driver is listening");
  }
  // `batch_max_wait` is thirty seconds and `CEILING` is ten, so arriving at all is arriving on the
  // COUNT: a batch that had waited for its timer could not have landed inside this wait.
  head.awaiting(10);

  let mut arrived = head.taken().to_vec();
  arrived.sort_unstable();
  assert_eq!(arrived, (0..10).collect::<Vec<_>>(), "all ten, one batch");
  drop(driver);
}

/// **THE TIMER TRIGGER**: a batch nothing filled still lands, at its own deadline.
#[test]
fn a_partial_batch_flushes_at_the_deadline() {
  let registry = family(
    RegistryOptions::new()
      .with_debounce(QUIET)
      .with_batch_max_wait(Duration::from_millis(60)),
  );
  let (outbox, mut head) = Head::open(16);
  let (push, keys) = crate::feed::<u64>(16);
  let driver = RegistryDriver::spawn(Arc::clone(&registry), keys, outbox);

  for key in 0..3 {
    push.give(key).expect("the driver is listening");
  }
  // Three of a ten-item ceiling: nothing but the wait can close this one.
  head.awaiting(3);

  let mut arrived = head.taken().to_vec();
  arrived.sort_unstable();
  assert_eq!(
    arrived,
    [0, 1, 2],
    "the wait closed what the count could not"
  );
  drop(driver);
}

/// **THE PUNCTUATION**: the intake line ENDING beats both timers, at once.
#[test]
fn an_ended_line_flushes_at_once() {
  let registry = family(
    RegistryOptions::new()
      // Both windows are longer than the wait below, so anything that arrives arrived because the
      // line ended and for no other reason.
      .with_debounce(Duration::from_secs(30))
      .with_batch_max_wait(Duration::from_secs(30)),
  );
  let (outbox, mut head) = Head::open(16);
  let (push, keys) = crate::feed::<u64>(16);
  let driver = RegistryDriver::spawn(Arc::clone(&registry), keys, outbox);

  for key in 0..3 {
    push.give(key).expect("the driver is listening");
  }
  // THE END, in the only vocabulary this layer has one in: the last feed onto the line is gone.
  drop(push);
  head.awaiting(3);

  let mut arrived = head.taken().to_vec();
  arrived.sort_unstable();
  assert_eq!(arrived, [0, 1, 2], "every pending key, however young");
  drop(driver);
}

/// **THE STOP DROPS THE PENDING BATCH**, and leaves the registry saying nothing about it.
#[test]
fn a_stop_drops_what_was_pending() {
  let registry = family(
    RegistryOptions::new()
      .with_debounce(Duration::from_secs(30))
      .with_batch_max_wait(Duration::from_secs(30)),
  );
  let (outbox, mut head) = Head::open(16);
  let (push, keys) = crate::feed::<u64>(16);
  let driver = RegistryDriver::spawn(Arc::clone(&registry), keys, outbox);

  for key in 0..3 {
    push.give(key).expect("the driver is listening");
  }
  // The keys are in the quiet window and nowhere else. Stopping is what this test is about, so the
  // feed is deliberately NOT dropped: an ended line is the other case and flushes.
  drop(driver);

  let _took = head.drained();
  assert!(
    head.taken().is_empty(),
    "a stop pushes nothing into a graph that is winding down: {:?}",
    head.taken()
  );
  for key in 0..3 {
    assert_eq!(
      registry.state(&key),
      RootState::Idle,
      "the intake is taken at the give, so a dropped batch leaves the table untouched"
    );
  }
  assert!(registry.is_empty(), "nothing is held for a key never sent");
  drop(push);
}

/// **THE `+1` IS HELD UNTIL THE HEAD ACKS** — the gap an intake alone would leave open.
#[test]
fn the_count_is_held_across_the_heads_ack() {
  let registry = family(knobs());
  let (outbox, mut head) = Head::open(16);
  let (push, keys) = crate::feed::<u64>(16);
  let driver = RegistryDriver::spawn(Arc::clone(&registry), keys, outbox);

  push.give(4).expect("the driver is listening");

  // TAKEN and NOT acked: the head is holding, which is what a head that has been given work but has
  // not yet fanned it out looks like.
  let deadline = Instant::now() + CEILING;
  let holding = loop {
    let holding = head.held();
    if !holding.is_empty() {
      break holding;
    }
    assert!(
      Instant::now() < deadline,
      "the head was never given the key"
    );
    std::thread::sleep(Duration::from_millis(1));
  };
  assert_eq!(
    registry.inflight(&4),
    1,
    "the driver's own dispatch, held across the gap the head has not yet filled"
  );
  assert!(matches!(registry.state(&4), RootState::Analyzing { .. }));

  // THE ACK, which is where the driver lets go.
  for (released, custody) in holding {
    custody.send(Ack::new(released, "head", Lifecycle::Processed(())));
  }
  awaited(
    || registry.state(&4) == RootState::Idle,
    "the key never came back from the ack",
  );
  drop(driver);
}

/// **A RETIRED KEY IS NOT DISPATCHED**, and the intake is the gate that says so.
#[test]
fn a_retired_key_never_reaches_the_head() {
  let registry = family(knobs());
  let (outbox, mut head) = Head::open(16);
  let (push, keys) = crate::feed::<u64>(16);
  let driver = RegistryDriver::spawn(Arc::clone(&registry), keys, outbox);

  let _retired = registry.retire(&11, RetireOrigin::User, Stamp::now());
  push.give(11).expect("the driver is listening");
  push.give(12).expect("the driver is listening");
  // The live key is what says the driver got that far at all — an assertion on the retired one
  // alone would pass against a driver that never ran.
  head.awaiting(1);
  std::thread::sleep(QUIET * 4);
  let _took = head.drained();

  assert_eq!(
    head.taken(),
    [12],
    "the retired key was refused at the gate"
  );
  assert!(
    matches!(registry.state(&11), RootState::Retired { .. }),
    "and stayed retired: {:?}",
    registry.state(&11)
  );
  drop(driver);
}

/// **THE THIRD TIER REACHES A RUNNING DRIVER** — the dial turned by hand, taken at the next quiet
/// moment.
#[test]
fn the_live_dial_is_re_read_when_nothing_is_pending() {
  // A window no test would wait out, so a driver that kept it would fail this rather than pass it
  // slowly.
  let registry = family(
    RegistryOptions::new()
      .with_debounce(Duration::from_secs(30))
      .with_batch_max_wait(Duration::from_secs(30)),
  );
  let (outbox, mut head) = Head::open(16);
  let (push, keys) = crate::feed::<u64>(16);
  let driver = RegistryDriver::spawn(Arc::clone(&registry), keys, outbox);

  registry.apply_knobs(
    &crate::RegistryOverride::new()
      .with_debounce(Duration::from_millis(1))
      .with_batch_max_wait(Duration::from_millis(5)),
  );
  push.give(3).expect("the driver is listening");
  head.awaiting(1);

  assert_eq!(head.taken(), [3], "the turned dial, not the started one");
  drop(driver);
}

/// **THE ENGINE FORK**: the R-less road takes a thread and says so.
#[test]
fn the_thread_road_names_its_engine() {
  let registry = family(knobs());
  let (outbox, _head) = Head::open(4);
  let (push, keys) = crate::feed::<u64>(4);
  let driver = RegistryDriver::spawn(registry, keys, outbox);
  assert_eq!(driver.engine(), DriverEngine::Thread);
  assert_eq!(driver.engine().as_str(), "thread");
  drop(push);
  drop(driver);
}

/// **THE ENGINE FORK, THE OTHER WAY**: a driver on a runtime is a TASK and holds no thread of its
/// own — the assertion behind *no `std::thread` on the async engine*, made against the value rather
/// than against prose.
#[tokio::test]
async fn the_async_road_takes_a_task_and_no_thread() {
  let registry = family(knobs());
  let (outbox, mut head) = Head::open(16);
  let (push, keys) = crate::feed::<u64>(16);
  let driver = RegistryDriver::spawn_on::<TokioRuntime, u64>(Arc::clone(&registry), keys, outbox);

  assert_eq!(
    driver.engine(),
    DriverEngine::Task,
    "no thread was asked for: the only line in the module that asks is the other road's"
  );
  assert_eq!(driver.engine().as_str(), "task");

  // And it is a WORKING task, coalescing on the runtime's own sleep: the same burst, the same one
  // delivery, driven by a timer this crate did not write.
  for _ in 0..3 {
    push.give_async(9).await.expect("the driver is listening");
  }
  let deadline = tokio::time::Instant::now() + CEILING;
  while head.taken().is_empty() {
    let _took = head.drained();
    assert!(
      tokio::time::Instant::now() < deadline,
      "the task never coalesced the burst"
    );
    tokio::time::sleep(Duration::from_millis(2)).await;
  }
  tokio::time::sleep(QUIET * 4).await;
  let _took = head.drained();
  assert_eq!(head.taken(), [9], "one intake for the whole burst");
  drop(driver);
}

/// A hung-up head does not strand a key `Analyzing` over an item that never landed.
#[test]
fn a_give_the_graph_refused_balances_its_own_count() {
  let registry = family(knobs());
  let (outbox, head) = Head::open(4);
  let (push, keys) = crate::feed::<u64>(4);
  // THE GRAPH IS GONE before the driver ever gives: the inbox is dropped, so every give is refused.
  drop(head);
  let driver = RegistryDriver::spawn(Arc::clone(&registry), keys, outbox);

  push.give(5).expect("the driver is listening");
  // WAITED FOR ON THE LINE, not on the state. The balanced `+1` is transient by construction — the
  // key is `Analyzing` for the length of one refused give — so polling the state would be racing a
  // window measured in microseconds. What CAN be waited for is the driver having taken the key at
  // all, which is what makes the assertion below about a give that was made and refused rather than
  // about a driver that never ran.
  awaited(|| push.is_empty(), "the driver never took the key");
  // And then the window and the batch's wait, so the give has certainly been attempted.
  std::thread::sleep(QUIET * 4);

  assert_eq!(
    registry.state(&5),
    RootState::Idle,
    "the `+1` for a give that never landed is balanced where it was taken"
  );
  assert!(registry.is_empty(), "and the table holds nothing for it");
  drop(driver);
  drop(push);
}

/// The machine's own deadline is the EARLIER of its two, which is what a loop owning both parks on.
#[test]
fn the_deadline_is_the_earlier_of_the_two_machines() {
  let registry = family(
    RegistryOptions::new()
      .with_debounce(Duration::from_millis(10))
      .with_batch_max_wait(Duration::from_secs(30)),
  );
  let (outbox, _head) = Head::open(4);
  let mut machine = super::Machine::new(registry, outbox);
  assert!(machine.deadline().is_none(), "nothing pending, nothing due");

  let now = Instant::now();
  machine.touched(1, now);
  let quiet = machine.deadline().expect("the debounce is holding one");
  assert_eq!(quiet, now + Duration::from_millis(10));

  // Ripening moves it into the batch, whose own wait is far longer — so the answer is now the
  // batch's, there being nothing left in the window.
  let closed = machine.ripened(now + Duration::from_millis(10));
  assert!(closed.is_empty(), "one key does not close a ten-item batch");
  assert_eq!(
    machine.deadline(),
    Some(now + Duration::from_millis(10) + Duration::from_secs(30)),
    "the batch's, the window being empty"
  );
}

/// A burst wider than the ceiling closes MORE THAN ONE batch in a single ripening, and a driver that
/// answered only the first would leave full batches waiting on a timer.
#[test]
fn one_ripening_can_close_several_batches() {
  let registry = family(RegistryOptions::new().with_debounce(Duration::from_millis(10)));
  let (outbox, _head) = Head::open(4);
  let mut machine = super::Machine::new(registry, outbox);

  let now = Instant::now();
  for key in 0..25 {
    machine.touched(key, now);
  }
  let closed = machine.ripened(now + Duration::from_millis(10));
  assert_eq!(closed.len(), 2, "twenty-five keys at ten a batch");
  assert!(closed.iter().all(|batch| batch.len() == 10));
  assert_eq!(machine.due(now), None, "five are still open and not due");
}

/// The punctuation door takes the window AND the batch, whatever either timer says.
#[test]
fn the_punctuation_door_takes_everything() {
  let registry = family(
    RegistryOptions::new()
      .with_debounce(Duration::from_secs(30))
      .with_batch_max_wait(Duration::from_secs(30)),
  );
  let (outbox, _head) = Head::open(4);
  let mut machine = super::Machine::new(registry, outbox);

  let now = Instant::now();
  for key in 0..3 {
    machine.touched(key, now);
  }
  assert!(machine.ripened(now).is_empty(), "nothing has fallen quiet");
  let closed = machine.ended(now);
  assert_eq!(closed.len(), 1);
  assert_eq!(closed[0].len(), 3, "every pending key, however young");
  assert!(machine.ended(now).is_empty(), "and nothing twice");
}

/// A driver that is only ever asked for its engine word costs nothing and says the same thing twice.
#[test]
fn the_engine_word_is_stable() {
  let counted = Arc::new(AtomicUsize::new(0));
  assert_eq!(counted.load(Ordering::SeqCst), 0);
  assert_eq!(DriverEngine::Task.as_str(), "task");
  assert_eq!(DriverEngine::Thread.as_str(), "thread");
  assert_ne!(DriverEngine::Task, DriverEngine::Thread);
}

/// The two intake roads are ONE door, and this is the second: a deployment with no origin at all
/// holds the loose feed itself.
#[test]
fn the_hand_road_pushes_through_the_same_feed() {
  let registry = family(knobs());
  let (outbox, mut head) = Head::open(16);
  let (push, keys): (Feed<u64>, Yielded<u64>) = crate::feed(16);
  let driver = RegistryDriver::spawn(Arc::clone(&registry), keys, outbox);

  // A second holder, which is what a command face and an origin sharing one door looks like.
  let second = push.clone();
  push.give(1).expect("the driver is listening");
  second.give(2).expect("the driver is listening");
  head.awaiting(2);

  let mut arrived = head.taken().to_vec();
  arrived.sort_unstable();
  assert_eq!(arrived, [1, 2]);
  drop(driver);
}

/// The head's own edge is BOUNDED and the driver waits for room on it, which is the backpressure a
/// coalescer must not route around.
#[test]
fn a_full_head_edge_is_waited_for_rather_than_shed() {
  let registry = family(
    RegistryOptions::new()
      .with_debounce(Duration::from_millis(1))
      .with_batch_max_wait(Duration::from_millis(5)),
  );
  // ONE slot, so a second give cannot land until the head has taken the first.
  let (outbox, mut head) = Head::open(1);
  let (push, keys) = crate::feed::<u64>(16);
  let driver = RegistryDriver::spawn(Arc::clone(&registry), keys, outbox);

  for key in 0..4 {
    push.give(key).expect("the driver is listening");
  }
  // Nothing is dropped: the driver parks on the bounded edge and every key still arrives.
  head.awaiting(4);

  let mut arrived = head.taken().to_vec();
  arrived.sort_unstable();
  assert_eq!(arrived, [0, 1, 2, 3], "waited for, not shed");
  drop(driver);
}

/// Dropping a driver is idempotent from the caller's side and finite from the body's — the stop is
/// said before the join, which is what makes the wait end.
#[test]
fn dropping_the_handle_stops_and_joins() {
  let registry = family(knobs());
  let (outbox, _head) = Head::open(4);
  let (push, keys) = crate::feed::<u64>(4);
  let driver = RegistryDriver::spawn(registry, keys, outbox);
  let at = Instant::now();
  drop(driver);
  assert!(
    at.elapsed() < CEILING,
    "the join waited for a body nothing had told to go"
  );
  drop(push);
}