@ultimat3/testing 31.12.0 → 31.13.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ultimat3/testing",
3
- "version": "31.12.0",
3
+ "version": "31.13.0",
4
4
  "description": "Test harness: cloned template DBs per worker, frozen clock, sealed network, 6 test types",
5
5
  "keywords": [
6
6
  "ultimate",
@@ -47,26 +47,26 @@
47
47
  "test": "bun test"
48
48
  },
49
49
  "dependencies": {
50
- "@ultimat3/action": "31.12.0",
51
- "@ultimat3/ai": "31.12.0",
52
- "@ultimat3/auth": "31.12.0",
53
- "@ultimat3/cache": "31.12.0",
54
- "@ultimat3/core": "31.12.0",
55
- "@ultimat3/db": "31.12.0",
56
- "@ultimat3/entity": "31.12.0",
57
- "@ultimat3/http": "31.12.0",
58
- "@ultimat3/i18n": "31.12.0",
59
- "@ultimat3/jobs": "31.12.0",
60
- "@ultimat3/mail": "31.12.0",
61
- "@ultimat3/notify": "31.12.0",
62
- "@ultimat3/policy": "31.12.0",
63
- "@ultimat3/pwa": "31.12.0",
64
- "@ultimat3/query": "31.12.0",
65
- "@ultimat3/realtime": "31.12.0",
66
- "@ultimat3/render": "31.12.0",
67
- "@ultimat3/schema": "31.12.0",
68
- "@ultimat3/scraping": "31.12.0",
69
- "@ultimat3/seo": "31.12.0",
70
- "@ultimat3/time": "31.12.0"
50
+ "@ultimat3/action": "31.13.0",
51
+ "@ultimat3/ai": "31.13.0",
52
+ "@ultimat3/auth": "31.13.0",
53
+ "@ultimat3/cache": "31.13.0",
54
+ "@ultimat3/core": "31.13.0",
55
+ "@ultimat3/db": "31.13.0",
56
+ "@ultimat3/entity": "31.13.0",
57
+ "@ultimat3/http": "31.13.0",
58
+ "@ultimat3/i18n": "31.13.0",
59
+ "@ultimat3/jobs": "31.13.0",
60
+ "@ultimat3/mail": "31.13.0",
61
+ "@ultimat3/notify": "31.13.0",
62
+ "@ultimat3/policy": "31.13.0",
63
+ "@ultimat3/pwa": "31.13.0",
64
+ "@ultimat3/query": "31.13.0",
65
+ "@ultimat3/realtime": "31.13.0",
66
+ "@ultimat3/render": "31.13.0",
67
+ "@ultimat3/schema": "31.13.0",
68
+ "@ultimat3/scraping": "31.13.0",
69
+ "@ultimat3/seo": "31.13.0",
70
+ "@ultimat3/time": "31.13.0"
71
71
  }
72
72
  }
@@ -0,0 +1,132 @@
1
+ // What every `JobDriver`'s claim answers besides its rows: when an empty claim's next row falls
2
+ // due (`onEmpty` — what an idle worker rests on) and the run's steps on each claimed row (`steps`).
3
+ // A driver that skipped either compiled and cost a round trip, or a minute of pickup latency.
4
+ // Type-only imports: the barrel never loads `@ultimat3/jobs`.
5
+
6
+ import { expect } from 'bun:test';
7
+ import type { ClaimOptions, JobDriver } from '@ultimat3/jobs';
8
+ import type { JobDriverCheck } from './job-driver-checks';
9
+
10
+ let minted = 0;
11
+
12
+ /** A queue and a job name of this check's own, so checks sharing one store never see each other. */
13
+ const scope = (): { readonly queue: string; readonly name: string } => {
14
+ minted += 1;
15
+ const tag = `${process.pid.toString(36)}-c${minted.toString(36)}`;
16
+ return { queue: `conformance-${tag}`, name: `conformance.job-${tag}` };
17
+ };
18
+
19
+ /** One claim on `queue`, and what its `onEmpty` was told — `'untold'` when it was not called. */
20
+ async function claimHearing(
21
+ driver: JobDriver,
22
+ queue: string,
23
+ extra: Partial<ClaimOptions> = {},
24
+ ): Promise<{ readonly taken: number; readonly told: number | null | 'untold' }> {
25
+ let told: number | null | 'untold' = 'untold';
26
+ const claimed = await driver.claim({
27
+ queues: [queue],
28
+ limit: 10,
29
+ visibilityTimeoutMs: 30_000,
30
+ workerId: 'w-horizon',
31
+ onEmpty: (dueInMs) => {
32
+ told = dueInMs;
33
+ },
34
+ ...extra,
35
+ });
36
+ return { taken: claimed.length, told };
37
+ }
38
+
39
+ /** Slack for the database's clock against this process's, and for the statement's own time. */
40
+ const SKEW_MS = 2_000;
41
+
42
+ export const CLAIM_ANSWER_CHECKS: readonly JobDriverCheck[] = [
43
+ {
44
+ name: 'an empty claim says when its next row is due: none, a delayed row, a held lease',
45
+ async run(driver) {
46
+ const at = scope();
47
+ expect(await claimHearing(driver, at.queue)).toEqual({ taken: 0, told: null });
48
+ // Delayed on the DRIVER's clock — a nack's delay — never this process's `Date`.
49
+ await driver.enqueue({
50
+ name: at.name,
51
+ queue: at.queue,
52
+ input: {},
53
+ idempotencyKey: 'later',
54
+ maxAttempts: 3,
55
+ });
56
+ const [taken] = await driver.claim({
57
+ queues: [at.queue],
58
+ limit: 1,
59
+ visibilityTimeoutMs: 30_000,
60
+ workerId: 'w-delay',
61
+ });
62
+ if (taken === undefined) return expect.unreachable('the row is claimable');
63
+ const by = { workerId: 'w-delay', claim: taken.claim, delayMs: 30_000 };
64
+ expect(await driver.nack(taken.id, by)).toBe(true);
65
+ const delayed = await claimHearing(driver, at.queue);
66
+ expect(delayed.taken).toBe(0);
67
+ expect(delayed.told).toBeGreaterThan(30_000 - SKEW_MS);
68
+ expect(delayed.told).toBeLessThanOrEqual(30_000 + SKEW_MS);
69
+
70
+ const held = scope();
71
+ await driver.enqueue({
72
+ name: held.name,
73
+ queue: held.queue,
74
+ input: {},
75
+ idempotencyKey: 'now',
76
+ maxAttempts: 3,
77
+ });
78
+ // A claim that TOOK something is not empty: nothing is told.
79
+ expect(await claimHearing(driver, held.queue, { visibilityTimeoutMs: 20_000 })).toEqual({
80
+ taken: 1,
81
+ told: 'untold',
82
+ });
83
+ const lease = await claimHearing(driver, held.queue);
84
+ expect(lease.taken).toBe(0);
85
+ expect(lease.told).toBeGreaterThan(20_000 - SKEW_MS);
86
+ expect(lease.told).toBeLessThanOrEqual(20_000 + SKEW_MS);
87
+ },
88
+ },
89
+ {
90
+ name: "a claimed row carries its run's steps: none on a first attempt, the written ones after",
91
+ async run(driver) {
92
+ const at = scope();
93
+ await driver.enqueue({
94
+ name: at.name,
95
+ queue: at.queue,
96
+ input: {},
97
+ idempotencyKey: 'stepped',
98
+ maxAttempts: 3,
99
+ });
100
+ const ask = { queues: [at.queue], limit: 1, visibilityTimeoutMs: 30_000, workerId: 'w-s' };
101
+ const [first] = await driver.claim(ask);
102
+ if (first === undefined) return expect.unreachable('the row is claimable');
103
+ expect(first.steps).toEqual([]);
104
+ const by = { workerId: 'w-s', claim: first.claim };
105
+ await driver.steps.put(
106
+ {
107
+ runId: first.runId,
108
+ name: 'charge',
109
+ status: 'completed',
110
+ output: { cents: 1200 },
111
+ startedAt: 1_000,
112
+ completedAt: 2_000,
113
+ attempts: 1,
114
+ },
115
+ { job: at.name, jobId: first.id, ...by },
116
+ );
117
+ expect(await driver.nack(first.id, { ...by, delayMs: 0 })).toBe(true);
118
+ const [second] = await driver.claim(ask);
119
+ expect(second?.steps).toEqual([
120
+ {
121
+ runId: first.runId,
122
+ name: 'charge',
123
+ status: 'completed',
124
+ output: { cents: 1200 },
125
+ startedAt: 1_000,
126
+ completedAt: 2_000,
127
+ attempts: 1,
128
+ },
129
+ ]);
130
+ },
131
+ },
132
+ ];
@@ -5,6 +5,7 @@
5
5
 
6
6
  import { expect } from 'bun:test';
7
7
  import type { ClaimOptions, JobDriver, JobRecord, QueueStats } from '@ultimat3/jobs';
8
+ import { CLAIM_ANSWER_CHECKS } from './job-driver-checks-claim';
8
9
 
9
10
  export interface JobDriverCheck {
10
11
  readonly name: string;
@@ -174,4 +175,5 @@ export const JOB_DRIVER_CHECKS: readonly JobDriverCheck[] = [
174
175
  expect(await statsOf(driver, lapsed.queue)).toMatchObject({ failed: 1, dead: 0 });
175
176
  },
176
177
  },
178
+ ...CLAIM_ANSWER_CHECKS,
177
179
  ];
@@ -0,0 +1,46 @@
1
+ // The outbox store's idle answer: a claim that took nothing says when the first row a relay holds
2
+ // has its lease lapse (`onEmpty`) — what an idle relay rests on instead of polling every 5 s. A
3
+ // store that never said it left the relay polling; one that said it wrong stranded a dead relay's
4
+ // batch for a minute.
5
+
6
+ import { expect } from 'bun:test';
7
+ import type { OutboxStore } from '@ultimat3/jobs';
8
+ import type { OutboxStoreCheck } from './outbox-store-conformance-subject';
9
+ import { committed, elapse, outboxRecord } from './outbox-store-conformance-subject';
10
+
11
+ /** One claim, and what its `onEmpty` was told — `'untold'` when it was not called. */
12
+ async function hearing(
13
+ store: OutboxStore,
14
+ ): Promise<{ readonly taken: number; readonly told: number | null | 'untold' }> {
15
+ let told: number | null | 'untold' = 'untold';
16
+ const claimed = await store.claim(10, {
17
+ onEmpty: (dueInMs) => {
18
+ told = dueInMs;
19
+ },
20
+ });
21
+ return { taken: claimed.length, told };
22
+ }
23
+
24
+ /** Slack for the database's clock against the statement's own time. */
25
+ const SKEW_MS = 500;
26
+
27
+ export const OUTBOX_STORE_HORIZON_CHECKS: readonly OutboxStoreCheck[] = [
28
+ {
29
+ name: 'an empty claim says when a held row’s lease lapses, and nothing when none is held',
30
+ async run(subject) {
31
+ const [dead, idle] = [subject.relay(), subject.relay()];
32
+ expect(await hearing(idle)).toEqual({ taken: 0, told: null });
33
+ await committed(subject, dead, [outboxRecord(crypto.randomUUID())]);
34
+ // A claim that TOOK rows is not empty: nothing is told.
35
+ expect(await hearing(dead)).toEqual({ taken: 1, told: 'untold' });
36
+ const held = await hearing(idle);
37
+ expect(held.taken).toBe(0);
38
+ expect(held.told).toBeGreaterThan(subject.claimLeaseMs - SKEW_MS);
39
+ expect(held.told).toBeLessThanOrEqual(subject.claimLeaseMs + SKEW_MS);
40
+ await elapse(subject, subject.claimLeaseMs / 2);
41
+ const later = await hearing(idle);
42
+ expect(later.told).toBeLessThanOrEqual(subject.claimLeaseMs / 2 + SKEW_MS);
43
+ expect(later.told).toBeGreaterThan(subject.claimLeaseMs / 2 - SKEW_MS);
44
+ },
45
+ },
46
+ ];
@@ -6,6 +6,7 @@
6
6
  import { expect, test } from 'bun:test';
7
7
  import type { OutboxRecord } from '@ultimat3/jobs';
8
8
  import { OUTBOX_STORE_CLAIM_CHECKS } from './outbox-store-conformance-claims';
9
+ import { OUTBOX_STORE_HORIZON_CHECKS } from './outbox-store-conformance-horizon';
9
10
  import type { OutboxStoreCheck, OutboxStoreSubject } from './outbox-store-conformance-subject';
10
11
  import { committed, outboxRecord } from './outbox-store-conformance-subject';
11
12
  import type { SharedExamples } from './shared-examples';
@@ -58,6 +59,7 @@ const STAGE_CHECKS: readonly OutboxStoreCheck[] = [
58
59
  export const OUTBOX_STORE_CHECKS: readonly OutboxStoreCheck[] = [
59
60
  ...STAGE_CHECKS,
60
61
  ...OUTBOX_STORE_CLAIM_CHECKS,
62
+ ...OUTBOX_STORE_HORIZON_CHECKS,
61
63
  ];
62
64
 
63
65
  export const outboxStoreConformance: SharedExamples<