Skip to content

Commit 683eed1

Browse files
committed
refactor(auth): declare the tests' delivery channels with test_channels!
1 parent 097598c commit 683eed1

3 files changed

Lines changed: 12 additions & 62 deletions

File tree

‎apps/auth-service/src/admin/tests/deliveries.rs‎

Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -5,22 +5,9 @@ use crate::security::CONFIRMATION_MAX_AGE;
55
use sourceorigin_common::DeliveryId;
66
use sourceorigin_repository::{Channel, DatabaseError, DeliveryStatus, EventFilter, NewDelivery};
77

8-
/// A delivery no worker sends, which the tests only retry and cancel.
9-
struct Unsent;
10-
11-
impl Channel for Unsent {
12-
const NAME: &'static str = "test_admin_unsent";
13-
type Recipient = ();
14-
type Payload = ();
15-
16-
fn deliveries(
17-
_: &DomainEvent,
18-
_: Option<UserId>,
19-
_: &[sourceorigin_repository::Notified],
20-
_: &mut DatabaseTransaction<'_>,
21-
) -> impl Future<Output = Result<Vec<NewDelivery<Self>>, DatabaseError>> + Send {
22-
std::future::ready(Ok(vec![]))
23-
}
8+
sourceorigin_repository::test_channels! {
9+
/// A delivery no worker sends, which the tests only retry and cancel.
10+
Unsent = "test_admin_unsent": () => ();
2411
}
2512

2613
/// Retrying and cancelling a delivery check their administrator as every change

‎apps/auth-service/src/deliveries/tests.rs‎

Lines changed: 6 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -236,40 +236,16 @@ async fn responses_are_classified_by_status_alone() {
236236
assert_eq!(long, Ok(64 * 1024));
237237
}
238238

239-
/// Declares channels for worker tests, whose deliveries are inserted directly.
240-
/// Tests run at once on one database, so each worker test has its own channel.
241-
macro_rules! worker_channels {
242-
($($(#[doc = $doc:literal])* $name:ident = $value:literal;)*) => {$(
243-
$(#[doc = $doc])*
244-
struct $name;
245-
246-
impl Channel for $name {
247-
const NAME: &'static str = $value;
248-
/// How [`Recorder`] answers the delivery.
249-
type Recipient = Behavior;
250-
type Payload = ();
251-
252-
fn deliveries(
253-
_: &DomainEvent,
254-
_: Option<UserId>,
255-
_: &[sourceorigin_repository::Notified],
256-
_: &mut DatabaseTransaction<'_>,
257-
) -> impl Future<Output = Result<Vec<NewDelivery<Self>>, DatabaseError>> + Send {
258-
std::future::ready(Ok(vec![]))
259-
}
260-
}
261-
)*};
262-
}
263-
264-
worker_channels! {
239+
// Worker tests' channels, each recipient saying how [`Recorder`] answers it.
240+
sourceorigin_repository::test_channels! {
265241
/// Retryable and permanent failures.
266-
Failing = "test_worker";
242+
Failing = "test_worker": Behavior => ();
267243
/// An operator retry after a permanent failure.
268-
Resent = "test_worker_resent";
244+
Resent = "test_worker_resent": Behavior => ();
269245
/// What an attempt and an idle worker export.
270-
Traced = "test_worker_traced";
246+
Traced = "test_worker_traced": Behavior => ();
271247
/// A replica killed, or stalled, while it sends.
272-
Killed = "test_worker_killed";
248+
Killed = "test_worker_killed": Behavior => ();
273249
}
274250

275251
/// How [`Recorder`] answers a delivery.

‎apps/auth-service/src/web/admin/tests.rs‎

Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1664,22 +1664,9 @@ async fn a_client_named_new_has_its_overview() {
16641664
assert!(registration.contains(r#"name="id""#), "{registration}");
16651665
}
16661666

1667-
/// A delivery no worker sends, which the dashboard's tests list, cancel and retry.
1668-
struct Unsent;
1669-
1670-
impl Channel for Unsent {
1671-
const NAME: &'static str = "test_dashboard_unsent";
1672-
type Recipient = ();
1673-
type Payload = ();
1674-
1675-
fn deliveries(
1676-
_: &DomainEvent,
1677-
_: Option<UserId>,
1678-
_: &[sourceorigin_repository::Notified],
1679-
_: &mut DatabaseTransaction<'_>,
1680-
) -> impl Future<Output = Result<Vec<NewDelivery<Self>>, DatabaseError>> + Send {
1681-
std::future::ready(Ok(vec![]))
1682-
}
1667+
sourceorigin_repository::test_channels! {
1668+
/// A delivery no worker sends, which the dashboard's tests list, cancel and retry.
1669+
Unsent = "test_dashboard_unsent": () => ();
16831670
}
16841671

16851672
impl Harness {

0 commit comments

Comments
 (0)