architecturekit 0.24.0

Building blocks for DDD-based applications with CQRS and event sourcing, on top of the EventSourcingDB by the native web.
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
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
// These tests check reading: its bounds, the newest event first, reading from
// the latest event, IDs that are not revisions, and empty ranges against the
// database. They show that Store::read refuses what check_read_options refuses
// before it asks the database, whose own tests cover every range. Every test
// has a database of its own, so the IDs of its events start at "0".
//
// A stream that the caller drops stops reading, as a dropped future does, so
// "stops when the caller stops" reads part of a stream only.

use std::pin::pin;

use eventsourcingdb::{Event as StoredEvent, error::ClientError};
use futures_util::StreamExt;
use serde_json::json;

use super::{
    Incremented, Reset, cause_of,
    commands::SOURCE,
    database::Database,
    fake::{Answer, Api, Fake, Reply, dead_client},
};
use crate::{
    Categorized, Category, Event, EventOn, IfLatestEventIsMissing, LowerBound, Order, Permanent,
    Precondition, ReadError, ReadOptions, Revision, Store, Subject, Subjects, UpperBound,
    read::{DatabaseBounds, database_options},
};

const READ_EVENTS: &str = "/api/v1/read-events";

/// Writes increments by the given amounts to the subject, and returns their
/// IDs.
async fn write(store: &Store, subject: &str, amounts: &[i64]) -> Vec<String> {
    let subject = Subject::new(subject);
    let written = store
        .write(
            amounts
                .iter()
                .map(|by| EventOn::new(subject.clone(), &Incremented { by: *by }))
                .collect(),
            vec![Precondition::unconditionally()],
        )
        .await
        .expect("the events are written");

    written.iter().map(|event| event.id().to_owned()).collect()
}

async fn write_reset(store: &Store, subject: &str) -> String {
    let written = store
        .write(
            vec![EventOn::new(Subject::new(subject), &Reset {})],
            vec![Precondition::unconditionally()],
        )
        .await
        .expect("the reset is written");

    written[0].id().to_owned()
}

/// Reads all events the store hands out, or the failure it ends with.
async fn read(
    store: &Store,
    subjects: &Subjects,
    options: &ReadOptions,
) -> Result<Vec<StoredEvent>, ReadError> {
    let events = store.read(subjects, options).await?;
    let mut events = pin!(events);

    let mut read = Vec::new();
    while let Some(event) = events.next().await {
        read.push(event?);
    }

    Ok(read)
}

fn ids(events: &[StoredEvent]) -> Vec<&str> {
    events.iter().map(StoredEvent::id).collect()
}

fn bounded(lower_bound: LowerBound, upper_bound: UpperBound) -> ReadOptions {
    ReadOptions {
        lower_bound,
        upper_bound,
        ..ReadOptions::default()
    }
}

/// Reads an event ID that the database has written, or that a test spells
/// out, as a revision.
fn revision(id: &str) -> Revision {
    id.parse().expect("the ID is a revision")
}

fn after(id: &str) -> LowerBound {
    LowerBound::AfterEvent(revision(id))
}

fn from(id: &str) -> LowerBound {
    LowerBound::FromEvent(revision(id))
}

fn up_to(id: &str) -> UpperBound {
    UpperBound::UpToEvent(revision(id))
}

fn before(id: &str) -> UpperBound {
    UpperBound::BeforeEvent(revision(id))
}

fn from_latest_reset(subject: &str, if_missing: IfLatestEventIsMissing) -> LowerBound {
    LowerBound::FromLatestEvent {
        subject: Subject::new(subject),
        event_type: Reset::EVENT_TYPE.to_owned(),
        if_missing,
    }
}

// Reading.

#[tokio::test]
async fn reads_the_events_of_a_subject_in_order() {
    let database = Database::start().await;
    let store = database.store().await;
    let ids_written = write(&store, "/books/42", &[1, 2, 3]).await;

    let events = read(
        &store,
        &Subjects::exact(Subject::new("/books/42")),
        &ReadOptions::default(),
    )
    .await
    .expect("the events are read");

    assert_eq!(ids(&events), ids_written);
    assert_eq!(events[0].data(), &json!({ "by": 1 }));
}

#[tokio::test]
async fn reads_an_exact_subject_without_the_subjects_below_it() {
    let database = Database::start().await;
    let store = database.store().await;
    let on_book = write(&store, "/books/42", &[1]).await;
    let _ = write(&store, "/books/42/notes", &[2]).await;

    let events = read(
        &store,
        &Subjects::exact(Subject::new("/books/42")),
        &ReadOptions::default(),
    )
    .await
    .expect("the events are read");

    assert_eq!(ids(&events), on_book);
}

#[tokio::test]
async fn reads_a_subject_tree_with_the_subjects_below_it() {
    let database = Database::start().await;
    let store = database.store().await;
    let _ = write(&store, "/books/42", &[1]).await;
    let _ = write(&store, "/books/42/notes", &[2]).await;
    let _ = write(&store, "/readers/7", &[3]).await;

    let events = read(
        &store,
        &Subjects::tree(Subject::new("/books")),
        &ReadOptions::default(),
    )
    .await
    .expect("the events are read");

    let subjects: Vec<&str> = events.iter().map(StoredEvent::subject).collect();
    assert_eq!(subjects, ["/books/42", "/books/42/notes"]);
}

#[tokio::test]
async fn stops_when_the_caller_stops() {
    let database = Database::start().await;
    let store = database.store().await;
    let _ = write(&store, "/books/42", &[1, 2, 3]).await;

    let subjects = Subjects::exact(Subject::new("/books/42"));
    let options = ReadOptions::default();
    let first = store
        .read(&subjects, &options)
        .await
        .expect("the events are read")
        .take(1)
        .collect::<Vec<_>>()
        .await;

    assert_eq!(first.len(), 1);
    let all = read(&store, &subjects, &options)
        .await
        .expect("the store reads again");
    assert_eq!(all.len(), 3);
}

/// An event as EventSourcingDB hands it out through the v1 API, with a hash
/// that does not match its content.
const TAMPERED_EVENT: &str = r#"{"type":"event","payload":{"specversion":"1.0","id":"0","time":"2026-01-01T00:00:00Z","source":"https://thenativeweb.io","subject":"/books/42","type":"io.thenativeweb.test.incremented","datacontenttype":"application/json","data":{"by":1},"hash":"0000000000000000000000000000000000000000000000000000000000000001","predecessorhash":"0000000000000000000000000000000000000000000000000000000000000000"}}"#;

#[tokio::test]
async fn refuses_an_event_whose_hash_does_not_match() {
    let client = Fake::new(Api::V1)
        .route(
            READ_EVENTS,
            Answer::Reply(Reply::status(200, &format!("{TAMPERED_EVENT}\n"))),
        )
        .client()
        .await;
    let store = Store::builder(client, SOURCE).build();

    let failure = read(
        &store,
        &Subjects::exact(Subject::new("/books/42")),
        &ReadOptions::default(),
    )
    .await
    .expect_err("the hash does not match");

    assert!(
        matches!(failure, ReadError::Permanent(Permanent::Unverified(_))),
        "{failure:?}"
    );
}

#[tokio::test]
async fn ends_with_the_first_failure() {
    let client = Fake::new(Api::V1)
        .route(
            READ_EVENTS,
            Answer::Reply(Reply::status(
                200,
                &format!("{TAMPERED_EVENT}\n{TAMPERED_EVENT}\n"),
            )),
        )
        .client()
        .await;
    let store = Store::builder(client, SOURCE).build();
    let subjects = Subjects::exact(Subject::new("/books/42"));
    let options = ReadOptions::default();

    let items = store
        .read(&subjects, &options)
        .await
        .expect("the read begins")
        .collect::<Vec<_>>()
        .await;

    assert_eq!(items.len(), 1, "{items:?}");
    assert!(items[0].is_err(), "{items:?}");
}

#[tokio::test]
async fn sorts_a_rejected_api_token_as_permanent() {
    let client = Fake::new(Api::V1)
        .route(
            READ_EVENTS,
            Answer::Reply(Reply::status(401, "unauthorized")),
        )
        .client()
        .await;
    let store = Store::builder(client, SOURCE).build();

    let failure = read(
        &store,
        &Subjects::exact(Subject::new("/books/42")),
        &ReadOptions::default(),
    )
    .await
    .expect_err("the token is rejected");

    assert!(matches!(failure, ReadError::Permanent(_)), "{failure:?}");
    assert!(
        failure
            .to_string()
            .contains(r#"reading "/books/42": the database rejected the API token"#),
        "{failure}"
    );
}

#[tokio::test]
async fn sorts_an_unreachable_database_as_transient() {
    let store = Store::builder(dead_client().await, SOURCE).build();

    let failure = read(
        &store,
        &Subjects::exact(Subject::new("/books/42")),
        &ReadOptions::default(),
    )
    .await
    .expect_err("the database can not be reached");

    assert_eq!(failure.category(), Some(Category::Transient), "{failure:?}");
}

#[tokio::test]
async fn sorts_an_answer_that_does_not_come_from_an_eventsourcingdb_as_transient() {
    // A proxy in front of the database answers on its behalf, for example
    // while the database restarts, whatever its status says, so trying again
    // may succeed.
    for status in [403, 404, 502] {
        let client = Fake::new(Api::V1)
            .route(
                READ_EVENTS,
                Answer::Reply(Reply {
                    is_from_eventsourcingdb: false,
                    ..Reply::status(status, "from a proxy")
                }),
            )
            .client()
            .await;
        let store = Store::builder(client, SOURCE).build();

        let failure = read(
            &store,
            &Subjects::exact(Subject::new("/books/42")),
            &ReadOptions::default(),
        )
        .await
        .expect_err("the answer does not come from an EventSourcingDB");

        assert!(
            matches!(failure, ReadError::Transient(_)),
            "{status}: {failure:?}"
        );
        assert!(
            failure.to_string().contains(
                r#"reading "/books/42": the answer does not come from an EventSourcingDB"#
            ),
            "{status}: {failure}"
        );
        assert!(
            matches!(cause_of(&failure), Some(ClientError::InvalidServerHeader)),
            "{status}: {failure:?}"
        );
    }
}

// Bounds.

#[tokio::test]
async fn reads_within_the_bounds() {
    let database = Database::start().await;
    let store = database.store().await;
    let _ = write(&store, "/books/42", &[1, 2, 3, 4, 5]).await;
    let subjects = Subjects::exact(Subject::new("/books/42"));

    for (name, options, expected) in [
        (
            "FromEvent includes the event with the given ID",
            bounded(from("1"), UpperBound::Unbounded),
            vec!["1", "2", "3", "4"],
        ),
        (
            "AfterEvent leaves out the event with the given ID",
            bounded(after("1"), UpperBound::Unbounded),
            vec!["2", "3", "4"],
        ),
        (
            "UpToEvent includes the event with the given ID",
            bounded(LowerBound::Unbounded, up_to("1")),
            vec!["0", "1"],
        ),
        (
            "BeforeEvent leaves out the event with the given ID",
            bounded(LowerBound::Unbounded, before("1")),
            vec!["0"],
        ),
        (
            "a lower and an upper bound read what lies between them",
            bounded(after("0"), before("4")),
            vec!["1", "2", "3"],
        ),
        (
            "an inclusive lower and upper bound read them as well",
            bounded(from("1"), up_to("3")),
            vec!["1", "2", "3"],
        ),
        (
            "the highest possible ID is an ID",
            bounded(LowerBound::Unbounded, up_to("9223372036854775807")),
            vec!["0", "1", "2", "3", "4"],
        ),
    ] {
        let events = read(&store, &subjects, &options).await.expect(name);

        assert_eq!(ids(&events), expected, "{name}");
    }
}

#[tokio::test]
async fn takes_a_bound_that_is_not_an_event_of_the_subjects_that_are_read() {
    let database = Database::start().await;
    let store = database.store().await;
    let _ = write(&store, "/books/42", &[1]).await;
    let other = write(&store, "/books/23", &[2]).await;
    let later = write(&store, "/books/42", &[3]).await;

    let events = read(
        &store,
        &Subjects::exact(Subject::new("/books/42")),
        &bounded(from(&other[0]), UpperBound::Unbounded),
    )
    .await
    .expect("the events are read");

    assert_eq!(ids(&events), later);
}

#[tokio::test]
async fn refuses_options_that_check_read_options_refuses_before_the_database_is_asked() {
    let (url, requests) = Fake::new(Api::V1).start().await;
    let store = Store::builder(eventsourcingdb::Client::new(url, "secret"), SOURCE).build();
    let subjects = Subjects::exact(Subject::new("/books/42"));

    let empty = read(
        &store,
        &subjects,
        &bounded(LowerBound::Unbounded, before("0")),
    )
    .await
    .expect_err("no event can lie before 0");
    assert!(matches!(empty, ReadError::EmptyRange(_)), "{empty:?}");
    assert_eq!(
        empty.to_string(),
        r#"empty range: no event can lie before "0""#
    );
    assert_eq!(empty.category(), None);

    assert_eq!(requests.count(), 0, "the database is not asked");

    // Bounds that leave room for an event, and the latest event of a type,
    // which has no ID, go to the database.
    let _ = read(&store, &subjects, &bounded(from("0"), up_to("5")))
        .await
        .expect("the bounds are fine");
    let _ = read(
        &store,
        &subjects,
        &bounded(
            from_latest_reset("/books/42", IfLatestEventIsMissing::ReadEverything),
            UpperBound::Unbounded,
        ),
    )
    .await
    .expect("the latest event has no ID to check");
    assert!(requests.to(READ_EVENTS) >= 2, "the database is asked");
}

// Newest first.

#[tokio::test]
async fn hands_out_the_newest_event_first_within_the_bounds() {
    let database = Database::start().await;
    let store = database.store().await;
    let _ = write(&store, "/books/42", &[1, 2, 3]).await;
    let _ = write(&store, "/books/42/notes", &[4]).await;

    let newest_first = |lower_bound, upper_bound| ReadOptions {
        lower_bound,
        upper_bound,
        order: Order::NewestFirst,
    };

    let all = read(
        &store,
        &Subjects::exact(Subject::new("/books/42")),
        &newest_first(LowerBound::Unbounded, UpperBound::Unbounded),
    )
    .await
    .expect("the events are read");
    assert_eq!(ids(&all), ["2", "1", "0"]);

    let bounded = read(
        &store,
        &Subjects::exact(Subject::new("/books/42")),
        &newest_first(LowerBound::Unbounded, before("2")),
    )
    .await
    .expect("the events are read");
    assert_eq!(ids(&bounded), ["1", "0"], "the bounds stay what they are");

    let tree = read(
        &store,
        &Subjects::tree(Subject::new("/books")),
        &newest_first(LowerBound::Unbounded, UpperBound::Unbounded),
    )
    .await
    .expect("the events are read");
    assert_eq!(ids(&tree), ["3", "2", "1", "0"]);
}

// The latest event of a type.

#[tokio::test]
async fn reads_from_the_latest_event_of_the_type_and_includes_it() {
    let database = Database::start().await;
    let store = database.store().await;
    let _ = write(&store, "/books/42", &[1]).await;
    let _ = write_reset(&store, "/books/42").await;
    let _ = write(&store, "/books/42", &[2]).await;
    let latest = write_reset(&store, "/books/42").await;
    let after_it = write(&store, "/books/42", &[3]).await;

    let events = read(
        &store,
        &Subjects::exact(Subject::new("/books/42")),
        &bounded(
            from_latest_reset("/books/42", IfLatestEventIsMissing::ReadNothing),
            UpperBound::Unbounded,
        ),
    )
    .await
    .expect("the events are read");

    assert_eq!(ids(&events), [latest.as_str(), after_it[0].as_str()]);
}

#[tokio::test]
async fn reads_everything_or_nothing_if_the_latest_event_is_missing() {
    let database = Database::start().await;
    let store = database.store().await;
    let _ = write(&store, "/books/42", &[1, 2]).await;
    let subjects = Subjects::exact(Subject::new("/books/42"));

    let everything = read(
        &store,
        &subjects,
        &bounded(
            from_latest_reset("/books/42", IfLatestEventIsMissing::ReadEverything),
            UpperBound::Unbounded,
        ),
    )
    .await
    .expect("the events are read");
    assert_eq!(ids(&everything), ["0", "1"]);

    let up_to_one = read(
        &store,
        &subjects,
        &bounded(
            from_latest_reset("/books/42", IfLatestEventIsMissing::ReadEverything),
            up_to("0"),
        ),
    )
    .await
    .expect("the events are read");
    assert_eq!(ids(&up_to_one), ["0"], "up to the upper bound");

    let nothing = read(
        &store,
        &subjects,
        &bounded(
            from_latest_reset("/books/42", IfLatestEventIsMissing::ReadNothing),
            UpperBound::Unbounded,
        ),
    )
    .await
    .expect("the events are read");
    assert_eq!(ids(&nothing), Vec::<&str>::new());
}

#[tokio::test]
async fn looks_for_the_latest_event_on_the_given_subject_alone() {
    let database = Database::start().await;
    let store = database.store().await;
    let _ = write(&store, "/books/42", &[1]).await;
    let _ = write_reset(&store, "/books/42/notes").await;
    let _ = write(&store, "/books/42", &[2]).await;

    let events = read(
        &store,
        &Subjects::tree(Subject::new("/books/42")),
        &bounded(
            from_latest_reset("/books/42", IfLatestEventIsMissing::ReadNothing),
            UpperBound::Unbounded,
        ),
    )
    .await
    .expect("the events are read");

    assert_eq!(
        ids(&events),
        Vec::<&str>::new(),
        "a reset below the subject is not looked for"
    );
}

#[tokio::test]
async fn reads_a_subject_tree_from_the_latest_event_of_a_subject_in_it() {
    let database = Database::start().await;
    let store = database.store().await;
    let _ = write(&store, "/books/23", &[1]).await;
    let latest = write_reset(&store, "/books/42").await;
    let after_it = write(&store, "/books/23", &[2]).await;

    let events = read(
        &store,
        &Subjects::tree(Subject::new("/books")),
        &bounded(
            from_latest_reset("/books/42", IfLatestEventIsMissing::ReadNothing),
            UpperBound::Unbounded,
        ),
    )
    .await
    .expect("the events are read");

    assert_eq!(ids(&events), [latest.as_str(), after_it[0].as_str()]);
}

#[tokio::test]
async fn goes_with_an_upper_bound_and_is_refused_if_the_latest_event_comes_after_it() {
    let database = Database::start().await;
    let store = database.store().await;
    let _ = write(&store, "/books/42", &[1]).await;
    let latest = write_reset(&store, "/books/42").await;
    let _ = write(&store, "/books/42", &[2, 3]).await;
    let subjects = Subjects::exact(Subject::new("/books/42"));
    let from_latest = || from_latest_reset("/books/42", IfLatestEventIsMissing::ReadNothing);

    let events = read(&store, &subjects, &bounded(from_latest(), up_to("2")))
        .await
        .expect("the events are read");
    assert_eq!(ids(&events), [latest.as_str(), "2"]);

    let failure = read(&store, &subjects, &bounded(from_latest(), before("1")))
        .await
        .expect_err("the latest event comes after the upper bound");
    assert!(matches!(failure, ReadError::Permanent(_)), "{failure:?}");
    assert!(
        matches!(cause_of(&failure), Some(ClientError::DbApiError(_))),
        "the database refused the read: {failure:?}"
    );
}

// Ranges against the database.

#[tokio::test]
async fn hands_out_no_events_for_a_range_that_is_only_empty_for_now_but_the_events_that_come_there_later()
 {
    let database = Database::start().await;
    let store = database.store().await;
    let written = write(&store, "/books/42", &[1, 2, 3, 4, 5]).await;
    let subjects = Subjects::exact(Subject::new("/books/42"));
    let after_the_last = bounded(after(&written[4]), UpperBound::Unbounded);

    let now = read(&store, &subjects, &after_the_last)
        .await
        .expect("events can still come after the last one");
    assert_eq!(ids(&now), Vec::<&str>::new());

    let later = write(&store, "/books/42", &[6]).await;
    let then = read(&store, &subjects, &after_the_last)
        .await
        .expect("the events are read");
    assert_eq!(ids(&then), later);
}

#[tokio::test]
async fn refuses_exactly_the_bounds_the_database_would_refuse() {
    // Without the check, the database answers bounds that leave no room for
    // an event with 400, so the kit has to refuse the same ones, and no
    // others. The largest revision is left out, since EventSourcingDB 1.2.0
    // counts past it.
    let database = Database::start().await;
    let store = database.store().await;
    let client = database.client().await;
    let _ = write(&store, "/books/42", &[1, 2, 3, 4, 5]).await;
    let subjects = Subjects::exact(Subject::new("/books/42"));

    let mut lower_bounds = vec![
        LowerBound::Unbounded,
        from_latest_reset("/books/42", IfLatestEventIsMissing::ReadEverything),
    ];
    let mut upper_bounds = vec![UpperBound::Unbounded];
    for id in ["0", "1", "2", "4"] {
        lower_bounds.extend([from(id), after(id)]);
        upper_bounds.extend([up_to(id), before(id)]);
    }

    for lower_bound in &lower_bounds {
        for upper_bound in &upper_bounds {
            let options = bounded(lower_bound.clone(), upper_bound.clone());

            let is_refused_by_the_kit = crate::check_read_options(&options).is_err();
            let bounds = DatabaseBounds::of(&options);
            let is_refused_by_the_database = match client
                .read_events(
                    subjects.subject().as_str(),
                    Some(database_options(&subjects, &options, &bounds)),
                )
                .await
            {
                Ok(events) => events.any(|event| async move { event.is_err() }).await,
                Err(_) => true,
            };

            assert_eq!(
                is_refused_by_the_kit, is_refused_by_the_database,
                "{options:?}"
            );
        }
    }
}