@dudousxd/nestjs-durable-testing 0.22.0 → 0.22.2
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/dist/index.js +168 -5
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -853,7 +853,7 @@ function runStateStoreContract(name, makeStore) {
|
|
|
853
853
|
supportsTagFilter = ctx.supportsTagFilter ?? true;
|
|
854
854
|
skipReason = void 0;
|
|
855
855
|
} catch (err) {
|
|
856
|
-
if (isUnavailable(err)) {
|
|
856
|
+
if (isUnavailable(err) && !process.env.DURABLE_TEST_REQUIRE_BACKENDS) {
|
|
857
857
|
skipReason = err.message;
|
|
858
858
|
if (!loggedSkip) {
|
|
859
859
|
console.warn(`[state-store-contract] SKIPPING "${name}": ${skipReason}`);
|
|
@@ -4393,7 +4393,10 @@ function instances(store, transports, clock) {
|
|
|
4393
4393
|
});
|
|
4394
4394
|
}
|
|
4395
4395
|
__name(instances, "instances");
|
|
4396
|
-
function registerFan(all, fanSize, ran, settle2) {
|
|
4396
|
+
function registerFan(all, fanSize, ran, settle2, spreadWithinMs) {
|
|
4397
|
+
const executors = /* @__PURE__ */ __name(() => new Set([
|
|
4398
|
+
...ran.values()
|
|
4399
|
+
].map(([first]) => first)), "executors");
|
|
4397
4400
|
for (const { name, engine } of all) {
|
|
4398
4401
|
engine.register("child", "1", async (ctx, input) => {
|
|
4399
4402
|
const { i } = input;
|
|
@@ -4402,6 +4405,9 @@ function registerFan(all, fanSize, ran, settle2) {
|
|
|
4402
4405
|
...ran.get(i) ?? [],
|
|
4403
4406
|
name
|
|
4404
4407
|
]);
|
|
4408
|
+
if (spreadWithinMs !== void 0) {
|
|
4409
|
+
await until(() => executors().size >= all.length, spreadWithinMs).catch(() => void 0);
|
|
4410
|
+
}
|
|
4405
4411
|
await pause(15);
|
|
4406
4412
|
return i * 2;
|
|
4407
4413
|
});
|
|
@@ -4427,6 +4433,99 @@ function doubled(fanSize, settle2) {
|
|
|
4427
4433
|
})) : values;
|
|
4428
4434
|
}
|
|
4429
4435
|
__name(doubled, "doubled");
|
|
4436
|
+
function holdingTurn(inner, hold) {
|
|
4437
|
+
let release;
|
|
4438
|
+
const gate = new Promise((resolve) => {
|
|
4439
|
+
release = resolve;
|
|
4440
|
+
});
|
|
4441
|
+
const state = {
|
|
4442
|
+
held: false,
|
|
4443
|
+
release: /* @__PURE__ */ __name(() => release(), "release")
|
|
4444
|
+
};
|
|
4445
|
+
const store = new Proxy(inner, {
|
|
4446
|
+
get(target, prop, receiver) {
|
|
4447
|
+
const value = Reflect.get(target, prop, receiver);
|
|
4448
|
+
if (typeof value !== "function") return value;
|
|
4449
|
+
const fn = value;
|
|
4450
|
+
const holds = /* @__PURE__ */ __name((args) => {
|
|
4451
|
+
if (state.held) return false;
|
|
4452
|
+
if (hold === "suspend" && (prop === "updateRun" || prop === "updateRunIf")) {
|
|
4453
|
+
const patch = prop === "updateRun" ? args[1] : args[2];
|
|
4454
|
+
return args[0] === "p" && patch.status === "suspended";
|
|
4455
|
+
}
|
|
4456
|
+
if (hold === "placeholder" && prop === "saveCheckpoint") {
|
|
4457
|
+
const cp2 = args[0];
|
|
4458
|
+
return cp2.runId === "p" && cp2.status === "running" && cp2.name.startsWith("signal:child:");
|
|
4459
|
+
}
|
|
4460
|
+
return false;
|
|
4461
|
+
}, "holds");
|
|
4462
|
+
return async (...args) => {
|
|
4463
|
+
if (holds(args)) {
|
|
4464
|
+
state.held = true;
|
|
4465
|
+
await gate;
|
|
4466
|
+
}
|
|
4467
|
+
return fn.apply(target, args);
|
|
4468
|
+
};
|
|
4469
|
+
}
|
|
4470
|
+
});
|
|
4471
|
+
return {
|
|
4472
|
+
store,
|
|
4473
|
+
state
|
|
4474
|
+
};
|
|
4475
|
+
}
|
|
4476
|
+
__name(holdingTurn, "holdingTurn");
|
|
4477
|
+
var MID_TURN = [
|
|
4478
|
+
{
|
|
4479
|
+
what: "ctx.child's completion",
|
|
4480
|
+
body: /* @__PURE__ */ __name((ctx) => ctx.child("child", {}), "body"),
|
|
4481
|
+
output: "done",
|
|
4482
|
+
signal: false
|
|
4483
|
+
},
|
|
4484
|
+
{
|
|
4485
|
+
what: "ctx.child's completion, raced against its timeline placeholder",
|
|
4486
|
+
body: /* @__PURE__ */ __name((ctx) => ctx.child("child", {}), "body"),
|
|
4487
|
+
output: "done",
|
|
4488
|
+
signal: false,
|
|
4489
|
+
hold: "placeholder"
|
|
4490
|
+
},
|
|
4491
|
+
{
|
|
4492
|
+
what: "a ctx.all fan's completions",
|
|
4493
|
+
body: /* @__PURE__ */ __name((ctx) => ctx.all("child", [
|
|
4494
|
+
{},
|
|
4495
|
+
{},
|
|
4496
|
+
{}
|
|
4497
|
+
]), "body"),
|
|
4498
|
+
output: [
|
|
4499
|
+
"done",
|
|
4500
|
+
"done",
|
|
4501
|
+
"done"
|
|
4502
|
+
],
|
|
4503
|
+
signal: false
|
|
4504
|
+
},
|
|
4505
|
+
{
|
|
4506
|
+
what: "a ctx.allSettled fan's completions",
|
|
4507
|
+
body: /* @__PURE__ */ __name((ctx) => ctx.allSettled("child", [
|
|
4508
|
+
{},
|
|
4509
|
+
{},
|
|
4510
|
+
{}
|
|
4511
|
+
]), "body"),
|
|
4512
|
+
output: [
|
|
4513
|
+
1,
|
|
4514
|
+
2,
|
|
4515
|
+
3
|
|
4516
|
+
].map(() => ({
|
|
4517
|
+
status: "fulfilled",
|
|
4518
|
+
value: "done"
|
|
4519
|
+
})),
|
|
4520
|
+
signal: false
|
|
4521
|
+
},
|
|
4522
|
+
{
|
|
4523
|
+
what: "a signal",
|
|
4524
|
+
body: /* @__PURE__ */ __name((ctx) => ctx.waitForSignal("go"), "body"),
|
|
4525
|
+
output: "sent",
|
|
4526
|
+
signal: true
|
|
4527
|
+
}
|
|
4528
|
+
];
|
|
4430
4529
|
async function shutdown(all, transports) {
|
|
4431
4530
|
await Promise.allSettled(all.map(({ engine }) => engine.drain(2e3)));
|
|
4432
4531
|
await Promise.allSettled(transports.map((t) => t.close?.()));
|
|
@@ -4490,7 +4589,7 @@ function runRunDispatchContract(name, makeHarness, options = {}) {
|
|
|
4490
4589
|
const store = new InMemoryStateStore4();
|
|
4491
4590
|
const all = instances(store, pair);
|
|
4492
4591
|
const ran = /* @__PURE__ */ new Map();
|
|
4493
|
-
registerFan(all, fanSize, ran, settle2);
|
|
4592
|
+
registerFan(all, fanSize, ran, settle2, timeoutMs / 2);
|
|
4494
4593
|
try {
|
|
4495
4594
|
for (const { engine } of all) engine.consumeRuns();
|
|
4496
4595
|
await all[0]?.engine.start("parent", {}, "p");
|
|
@@ -4532,8 +4631,13 @@ function runRunDispatchContract(name, makeHarness, options = {}) {
|
|
|
4532
4631
|
expect4(turns).toBe(0);
|
|
4533
4632
|
a.failing.on = false;
|
|
4534
4633
|
await engine.runPending();
|
|
4535
|
-
await until(async () =>
|
|
4536
|
-
|
|
4634
|
+
await until(async () => {
|
|
4635
|
+
const [lost, kept] = await Promise.all([
|
|
4636
|
+
store.getRun("lost"),
|
|
4637
|
+
store.getRun("kept")
|
|
4638
|
+
]);
|
|
4639
|
+
return lost?.status === "completed" && kept?.status === "completed";
|
|
4640
|
+
}, timeoutMs);
|
|
4537
4641
|
a.failing.on = true;
|
|
4538
4642
|
await engine.start("wf", {}, "down");
|
|
4539
4643
|
await pause(50);
|
|
@@ -5035,6 +5139,65 @@ function runRunDispatchContract(name, makeHarness, options = {}) {
|
|
|
5035
5139
|
await shutdown(all, pair);
|
|
5036
5140
|
}
|
|
5037
5141
|
}, timeoutMs + 1e4);
|
|
5142
|
+
for (const { what, body, output, signal, hold = "suspend" } of MID_TURN) {
|
|
5143
|
+
it3(`${what}, landing while the parent's turn runs on the other instance, resumes it once that turn ends`, async (ctx) => {
|
|
5144
|
+
const pair = await pairOrSkip(() => ctx.skip());
|
|
5145
|
+
if (!pair) return;
|
|
5146
|
+
const inner = new InMemoryStateStore4();
|
|
5147
|
+
const { store, state } = holdingTurn(inner, hold);
|
|
5148
|
+
const now = Date.now();
|
|
5149
|
+
const [first, second] = pair;
|
|
5150
|
+
const busy = new Proxy(first, {
|
|
5151
|
+
get(target, prop, receiver) {
|
|
5152
|
+
if (prop === "onDispatchedRun") {
|
|
5153
|
+
return (handler, opts) => target.onDispatchedRun?.(handler, {
|
|
5154
|
+
...opts,
|
|
5155
|
+
concurrency: 1
|
|
5156
|
+
});
|
|
5157
|
+
}
|
|
5158
|
+
const value = Reflect.get(target, prop, receiver);
|
|
5159
|
+
return typeof value === "function" ? value.bind(target) : value;
|
|
5160
|
+
}
|
|
5161
|
+
});
|
|
5162
|
+
const engines = [
|
|
5163
|
+
busy,
|
|
5164
|
+
second
|
|
5165
|
+
].map((transport) => new WorkflowEngine5({
|
|
5166
|
+
store,
|
|
5167
|
+
transport,
|
|
5168
|
+
clock: /* @__PURE__ */ __name(() => now, "clock")
|
|
5169
|
+
}));
|
|
5170
|
+
for (const engine of engines) {
|
|
5171
|
+
engine.register("child", "1", async () => "done");
|
|
5172
|
+
engine.register("parent", "1", async (wctx) => body(wctx));
|
|
5173
|
+
}
|
|
5174
|
+
const [holder, other] = engines;
|
|
5175
|
+
try {
|
|
5176
|
+
holder.consumeRuns();
|
|
5177
|
+
await holder.start("parent", {}, "p");
|
|
5178
|
+
await until(() => state.held, timeoutMs);
|
|
5179
|
+
other.consumeRuns();
|
|
5180
|
+
if (signal) await other.signal("go", "sent");
|
|
5181
|
+
else if (hold === "suspend") {
|
|
5182
|
+
const n = Array.isArray(output) ? output.length : 1;
|
|
5183
|
+
await until(async () => (await inner.listRuns({
|
|
5184
|
+
workflow: "child",
|
|
5185
|
+
status: "completed"
|
|
5186
|
+
})).length >= n, timeoutMs);
|
|
5187
|
+
}
|
|
5188
|
+
await pause(2600);
|
|
5189
|
+
state.release();
|
|
5190
|
+
await until(async () => (await inner.getRun("p"))?.status === "completed", timeoutMs);
|
|
5191
|
+
expect4((await inner.getRun("p"))?.output).toEqual(output);
|
|
5192
|
+
} finally {
|
|
5193
|
+
state.release();
|
|
5194
|
+
await shutdown(engines.map((engine, i) => ({
|
|
5195
|
+
name: `instance-${i}`,
|
|
5196
|
+
engine
|
|
5197
|
+
})), pair);
|
|
5198
|
+
}
|
|
5199
|
+
}, timeoutMs + 2e4);
|
|
5200
|
+
}
|
|
5038
5201
|
});
|
|
5039
5202
|
}
|
|
5040
5203
|
__name(runRunDispatchContract, "runRunDispatchContract");
|