@dudousxd/nestjs-durable-testing 0.1.0 → 0.1.1
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.
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"transport-conformance.d.ts","sourceRoot":"","sources":["../src/transport-conformance.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,KAAK,SAAS,EAEf,MAAM,+BAA+B,CAAC;AAGvC,oFAAoF;AACpF,MAAM,MAAM,mBAAmB,GAAG,SAAS,GAAG;IAC5C,MAAM,CAAC,IAAI,EAAE,MAAM,EAAE,EAAE,EAAE,CAAC,KAAK,EAAE,OAAO,KAAK,OAAO,CAAC,OAAO,CAAC,GAAG,IAAI,CAAC;IACrE,KAAK,CAAC,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;CACzB,CAAC;
|
|
1
|
+
{"version":3,"file":"transport-conformance.d.ts","sourceRoot":"","sources":["../src/transport-conformance.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,KAAK,SAAS,EAEf,MAAM,+BAA+B,CAAC;AAGvC,oFAAoF;AACpF,MAAM,MAAM,mBAAmB,GAAG,SAAS,GAAG;IAC5C,MAAM,CAAC,IAAI,EAAE,MAAM,EAAE,EAAE,EAAE,CAAC,KAAK,EAAE,OAAO,KAAK,OAAO,CAAC,OAAO,CAAC,GAAG,IAAI,CAAC;IACrE,KAAK,CAAC,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;CACzB,CAAC;AAyBF;;;;;;;GAOG;AACH,wBAAsB,0BAA0B,CAC9C,SAAS,EAAE,mBAAmB,EAC9B,QAAQ,SAAS,GAChB,OAAO,CAAC,IAAI,CAAC,CA+Bf"}
|
|
@@ -10,6 +10,21 @@ const echo = {
|
|
|
10
10
|
output: zod_1.z.object({ doubled: zod_1.z.number() }),
|
|
11
11
|
__remote: true,
|
|
12
12
|
};
|
|
13
|
+
/**
|
|
14
|
+
* A durable `ctx.call` suspends the run; the worker result resumes it asynchronously (on whatever
|
|
15
|
+
* tick/poll the transport delivers on). Poll the store until the run reaches a terminal state —
|
|
16
|
+
* with a generous budget so a poll-based transport (DB/SQS) has time to round-trip.
|
|
17
|
+
*/
|
|
18
|
+
async function settle(store, runId, timeoutMs = 15_000) {
|
|
19
|
+
const deadline = Date.now() + timeoutMs;
|
|
20
|
+
while (Date.now() < deadline) {
|
|
21
|
+
const run = await store.getRun(runId);
|
|
22
|
+
if (run && run.status !== 'running' && run.status !== 'suspended')
|
|
23
|
+
return run;
|
|
24
|
+
await new Promise((r) => setTimeout(r, 25));
|
|
25
|
+
}
|
|
26
|
+
throw new Error(`run ${runId} did not settle within ${timeoutMs}ms`);
|
|
27
|
+
}
|
|
13
28
|
/**
|
|
14
29
|
* The contract every `Transport` must satisfy: a remote step dispatched through it round-trips to a
|
|
15
30
|
* worker and back (success), and a throwing handler surfaces as a failed run (failure). Point it at
|
|
@@ -20,24 +35,27 @@ const echo = {
|
|
|
20
35
|
*/
|
|
21
36
|
async function assertTransportConformance(transport, idPrefix = 'conf') {
|
|
22
37
|
try {
|
|
38
|
+
// One engine/store/transport — a durable remote step routes its result back to this engine,
|
|
39
|
+
// which resumes the run. (Two engines on one transport would fight over the result stream.)
|
|
40
|
+
const store = new nestjs_durable_core_1.InMemoryStateStore();
|
|
41
|
+
const engine = new nestjs_durable_core_1.WorkflowEngine({ store, transport });
|
|
42
|
+
engine.register('conf-ok', '1', async (ctx) => (await ctx.call(echo, { n: 21 })).doubled);
|
|
43
|
+
engine.register('conf-fail', '1', async (ctx) => ctx.call(echo, { n: 1 }));
|
|
23
44
|
// success: the worker doubles the input
|
|
24
45
|
transport.handle('conformance.echo', async (input) => ({
|
|
25
46
|
doubled: input.n * 2,
|
|
26
47
|
}));
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
const ok = await engine.start('conf-ok', {}, `${idPrefix}-ok`);
|
|
48
|
+
await engine.start('conf-ok', {}, `${idPrefix}-ok`);
|
|
49
|
+
const ok = await settle(store, `${idPrefix}-ok`);
|
|
30
50
|
if (ok.status !== 'completed' || ok.output !== 42) {
|
|
31
51
|
throw new Error(`expected completed/42, got ${JSON.stringify(ok)}`);
|
|
32
52
|
}
|
|
33
|
-
// failure: a throwing handler
|
|
34
|
-
|
|
35
|
-
failTransport.handle('conformance.echo', async () => {
|
|
53
|
+
// failure: a throwing handler surfaces as a failed run (re-register the same step to throw)
|
|
54
|
+
transport.handle('conformance.echo', async () => {
|
|
36
55
|
throw new Error('handler boom');
|
|
37
56
|
});
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
const failed = await failEngine.start('conf-fail', {}, `${idPrefix}-fail`);
|
|
57
|
+
await engine.start('conf-fail', {}, `${idPrefix}-fail`);
|
|
58
|
+
const failed = await settle(store, `${idPrefix}-fail`);
|
|
41
59
|
if (failed.status !== 'failed') {
|
|
42
60
|
throw new Error(`expected failed, got ${JSON.stringify(failed)}`);
|
|
43
61
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"transport-conformance.js","sourceRoot":"","sources":["../src/transport-conformance.ts"],"names":[],"mappings":";;
|
|
1
|
+
{"version":3,"file":"transport-conformance.js","sourceRoot":"","sources":["../src/transport-conformance.ts"],"names":[],"mappings":";;AA6CA,gEAkCC;AA/ED,uEAKuC;AACvC,6BAAwB;AAQxB,MAAM,IAAI,GAAsD;IAC9D,IAAI,EAAE,kBAAkB;IACxB,KAAK,EAAE,aAAa;IACpB,KAAK,EAAE,OAAC,CAAC,MAAM,CAAC,EAAE,CAAC,EAAE,OAAC,CAAC,MAAM,EAAE,EAAE,CAAC;IAClC,MAAM,EAAE,OAAC,CAAC,MAAM,CAAC,EAAE,OAAO,EAAE,OAAC,CAAC,MAAM,EAAE,EAAE,CAAC;IACzC,QAAQ,EAAE,IAAI;CACf,CAAC;AAEF;;;;GAIG;AACH,KAAK,UAAU,MAAM,CAAC,KAAyB,EAAE,KAAa,EAAE,SAAS,GAAG,MAAM;IAChF,MAAM,QAAQ,GA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a test engine harness, crash/flaky-step injection, and replay assertions",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "Davide Carvalho",
|
|
@@ -20,7 +20,7 @@
|
|
|
20
20
|
},
|
|
21
21
|
"devDependencies": {
|
|
22
22
|
"typescript": "5.9.3",
|
|
23
|
-
"@dudousxd/nestjs-durable-core": "^0.
|
|
23
|
+
"@dudousxd/nestjs-durable-core": "^0.2.0"
|
|
24
24
|
},
|
|
25
25
|
"scripts": {
|
|
26
26
|
"build": "tsc -p tsconfig.json",
|