@dudousxd/nestjs-durable-testing 0.25.1 → 0.26.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.
- package/dist/index.d.ts +4 -0
- package/dist/index.js +207 -0
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/dist/index.d.ts
CHANGED
|
@@ -76,6 +76,8 @@ declare const DURABLE_CANONICAL_COLUMNS: {
|
|
|
76
76
|
readonly priority: "priority";
|
|
77
77
|
readonly origin: "origin";
|
|
78
78
|
readonly namespace: "namespace";
|
|
79
|
+
readonly tenantId: "tenant_id";
|
|
80
|
+
readonly tenantKind: "tenant_kind";
|
|
79
81
|
readonly createdAt: "created_at";
|
|
80
82
|
readonly updatedAt: "updated_at";
|
|
81
83
|
};
|
|
@@ -135,6 +137,8 @@ declare const DURABLE_CANONICAL_COLUMNS: {
|
|
|
135
137
|
readonly tags: "tags";
|
|
136
138
|
readonly spec: "spec";
|
|
137
139
|
readonly state: "state";
|
|
140
|
+
readonly tenantId: "tenant_id";
|
|
141
|
+
readonly tenantKind: "tenant_kind";
|
|
138
142
|
readonly createdAt: "created_at";
|
|
139
143
|
readonly updatedAt: "updated_at";
|
|
140
144
|
};
|
package/dist/index.js
CHANGED
|
@@ -238,6 +238,10 @@ var DURABLE_CANONICAL_COLUMNS = {
|
|
|
238
238
|
// now that all four adapters carry the column — see the note above, which used to
|
|
239
239
|
// name this as the standing example of a capability gap the map cannot express.
|
|
240
240
|
namespace: "namespace",
|
|
241
|
+
// The CUSTOMER (tenancy) a run belongs to — distinct from `namespace`. Two words each, so a
|
|
242
|
+
// `preserve` adapter and a `snake_case` one disagree, and each must say which it is.
|
|
243
|
+
tenantId: "tenant_id",
|
|
244
|
+
tenantKind: "tenant_kind",
|
|
241
245
|
createdAt: "created_at",
|
|
242
246
|
updatedAt: "updated_at"
|
|
243
247
|
},
|
|
@@ -305,6 +309,8 @@ var DURABLE_CANONICAL_COLUMNS = {
|
|
|
305
309
|
tags: "tags",
|
|
306
310
|
spec: "spec",
|
|
307
311
|
state: "state",
|
|
312
|
+
tenantId: "tenant_id",
|
|
313
|
+
tenantKind: "tenant_kind",
|
|
308
314
|
createdAt: "created_at",
|
|
309
315
|
updatedAt: "updated_at"
|
|
310
316
|
}
|
|
@@ -3903,6 +3909,116 @@ function runStateStoreContract(name, makeStore) {
|
|
|
3903
3909
|
"d"
|
|
3904
3910
|
]);
|
|
3905
3911
|
});
|
|
3912
|
+
t("round-trips a run tenant and filters by tenantId / tenantIds (null = no tenant)", async () => {
|
|
3913
|
+
await store.createRun(run({
|
|
3914
|
+
id: "a",
|
|
3915
|
+
tenantId: "acme",
|
|
3916
|
+
tenantKind: "organization"
|
|
3917
|
+
}));
|
|
3918
|
+
await store.createRun(run({
|
|
3919
|
+
id: "b",
|
|
3920
|
+
tenantId: "globex"
|
|
3921
|
+
}));
|
|
3922
|
+
await store.createRun(run({
|
|
3923
|
+
id: "c"
|
|
3924
|
+
}));
|
|
3925
|
+
const a = await store.getRun("a");
|
|
3926
|
+
expect3(a?.tenantId).toBe("acme");
|
|
3927
|
+
expect3(a?.tenantKind).toBe("organization");
|
|
3928
|
+
expect3((await store.getRun("b"))?.tenantKind ?? void 0).toBeUndefined();
|
|
3929
|
+
const c = await store.getRun("c");
|
|
3930
|
+
expect3(c?.tenantId ?? void 0).toBeUndefined();
|
|
3931
|
+
expect3(c?.tenantKind ?? void 0).toBeUndefined();
|
|
3932
|
+
const ids2 = /* @__PURE__ */ __name(async (q) => (await store.listRuns(q)).map((r) => r.id).sort(), "ids");
|
|
3933
|
+
expect3(await ids2({
|
|
3934
|
+
tenantId: "acme"
|
|
3935
|
+
})).toEqual([
|
|
3936
|
+
"a"
|
|
3937
|
+
]);
|
|
3938
|
+
expect3(await ids2({
|
|
3939
|
+
tenantId: null
|
|
3940
|
+
})).toEqual([
|
|
3941
|
+
"c"
|
|
3942
|
+
]);
|
|
3943
|
+
expect3(await ids2({
|
|
3944
|
+
tenantIds: [
|
|
3945
|
+
"acme"
|
|
3946
|
+
]
|
|
3947
|
+
})).toEqual([
|
|
3948
|
+
"a"
|
|
3949
|
+
]);
|
|
3950
|
+
expect3(await ids2({
|
|
3951
|
+
tenantIds: [
|
|
3952
|
+
"acme",
|
|
3953
|
+
null
|
|
3954
|
+
]
|
|
3955
|
+
})).toEqual([
|
|
3956
|
+
"a",
|
|
3957
|
+
"c"
|
|
3958
|
+
]);
|
|
3959
|
+
expect3(await ids2({
|
|
3960
|
+
tenantIds: [
|
|
3961
|
+
null
|
|
3962
|
+
]
|
|
3963
|
+
})).toEqual([
|
|
3964
|
+
"c"
|
|
3965
|
+
]);
|
|
3966
|
+
expect3(await ids2({
|
|
3967
|
+
tenantIds: []
|
|
3968
|
+
})).toEqual([]);
|
|
3969
|
+
expect3(await ids2({})).toEqual([
|
|
3970
|
+
"a",
|
|
3971
|
+
"b",
|
|
3972
|
+
"c"
|
|
3973
|
+
]);
|
|
3974
|
+
expect3(await ids2({
|
|
3975
|
+
tenantIds: [
|
|
3976
|
+
"acme",
|
|
3977
|
+
null
|
|
3978
|
+
],
|
|
3979
|
+
tenantId: "acme"
|
|
3980
|
+
})).toEqual([
|
|
3981
|
+
"a"
|
|
3982
|
+
]);
|
|
3983
|
+
expect3(await ids2({
|
|
3984
|
+
tenantIds: [
|
|
3985
|
+
"acme",
|
|
3986
|
+
"globex"
|
|
3987
|
+
],
|
|
3988
|
+
workflow: "nope"
|
|
3989
|
+
})).toEqual([]);
|
|
3990
|
+
await store.updateRun("c", {
|
|
3991
|
+
tenantId: "acme",
|
|
3992
|
+
tenantKind: "organization"
|
|
3993
|
+
});
|
|
3994
|
+
expect3(await ids2({
|
|
3995
|
+
tenantId: "acme"
|
|
3996
|
+
})).toEqual([
|
|
3997
|
+
"a",
|
|
3998
|
+
"c"
|
|
3999
|
+
]);
|
|
4000
|
+
await store.updateRun("c", {
|
|
4001
|
+
tenantId: null,
|
|
4002
|
+
tenantKind: null
|
|
4003
|
+
});
|
|
4004
|
+
expect3(await ids2({
|
|
4005
|
+
tenantId: null
|
|
4006
|
+
})).toEqual([
|
|
4007
|
+
"c"
|
|
4008
|
+
]);
|
|
4009
|
+
await store.updateRun("a", {
|
|
4010
|
+
status: "completed"
|
|
4011
|
+
});
|
|
4012
|
+
expect3((await store.getRun("a"))?.tenantId).toBe("acme");
|
|
4013
|
+
if (store.runFacets) {
|
|
4014
|
+
const facets = await store.runFacets({
|
|
4015
|
+
tenantIds: [
|
|
4016
|
+
"acme"
|
|
4017
|
+
]
|
|
4018
|
+
});
|
|
4019
|
+
expect3(facets.reduce((n, f) => n + f.count, 0)).toBe(1);
|
|
4020
|
+
}
|
|
4021
|
+
});
|
|
3906
4022
|
t("counts runs by (status, origin) without returning them", async () => {
|
|
3907
4023
|
if (!store.runFacets) return;
|
|
3908
4024
|
await store.createRun(run({
|
|
@@ -4850,6 +4966,60 @@ function runStateStoreContract(name, makeStore) {
|
|
|
4850
4966
|
expect3(await store.deleteSchedule?.("s1")).toBe(false);
|
|
4851
4967
|
expect3(await store.getSchedule?.("s1")).toBeNull();
|
|
4852
4968
|
});
|
|
4969
|
+
t("round-trips a schedule tenant and filters listSchedules by it", async () => {
|
|
4970
|
+
if (!store.saveSchedule || !store.listSchedules) return;
|
|
4971
|
+
await store.saveSchedule(schedule({
|
|
4972
|
+
id: "s1",
|
|
4973
|
+
tenantId: "acme",
|
|
4974
|
+
tenantKind: "organization"
|
|
4975
|
+
}));
|
|
4976
|
+
await store.saveSchedule(schedule({
|
|
4977
|
+
id: "s2"
|
|
4978
|
+
}));
|
|
4979
|
+
const s1 = await store.getSchedule?.("s1");
|
|
4980
|
+
expect3(s1?.tenantId).toBe("acme");
|
|
4981
|
+
expect3(s1?.tenantKind).toBe("organization");
|
|
4982
|
+
expect3((await store.getSchedule?.("s2"))?.tenantId ?? void 0).toBeUndefined();
|
|
4983
|
+
const ids2 = /* @__PURE__ */ __name(async (q) => (await store.listSchedules?.(q) ?? []).map((r) => r.id).sort(), "ids");
|
|
4984
|
+
expect3(await ids2({
|
|
4985
|
+
tenantId: "acme"
|
|
4986
|
+
})).toEqual([
|
|
4987
|
+
"s1"
|
|
4988
|
+
]);
|
|
4989
|
+
expect3(await ids2({
|
|
4990
|
+
tenantIds: [
|
|
4991
|
+
null
|
|
4992
|
+
]
|
|
4993
|
+
})).toEqual([
|
|
4994
|
+
"s2"
|
|
4995
|
+
]);
|
|
4996
|
+
expect3(await ids2({
|
|
4997
|
+
tenantIds: [
|
|
4998
|
+
"acme",
|
|
4999
|
+
null
|
|
5000
|
+
]
|
|
5001
|
+
})).toEqual([
|
|
5002
|
+
"s1",
|
|
5003
|
+
"s2"
|
|
5004
|
+
]);
|
|
5005
|
+
expect3(await ids2({
|
|
5006
|
+
tenantIds: []
|
|
5007
|
+
})).toEqual([]);
|
|
5008
|
+
expect3(await ids2({
|
|
5009
|
+
tenantId: "acme",
|
|
5010
|
+
dueBy: NOW + 12e4
|
|
5011
|
+
})).toEqual([
|
|
5012
|
+
"s1"
|
|
5013
|
+
]);
|
|
5014
|
+
expect3(await store.updateSchedule?.("s2", {
|
|
5015
|
+
tenantId: "globex"
|
|
5016
|
+
})).toBe(true);
|
|
5017
|
+
expect3(await ids2({
|
|
5018
|
+
tenantId: "globex"
|
|
5019
|
+
})).toEqual([
|
|
5020
|
+
"s2"
|
|
5021
|
+
]);
|
|
5022
|
+
});
|
|
4853
5023
|
t("updateSchedule patches, and compare-and-sets on nextFireAt", async () => {
|
|
4854
5024
|
await store.saveSchedule?.(schedule());
|
|
4855
5025
|
expect3(await store.updateSchedule?.("s1", {
|
|
@@ -5962,6 +6132,43 @@ function runStateStoreContract(name, makeStore) {
|
|
|
5962
6132
|
expect3(resumed.output).toBe(15);
|
|
5963
6133
|
expect3(aRuns).toBe(1);
|
|
5964
6134
|
});
|
|
6135
|
+
t("retries a failed run whose lease is still held, once the holder releases it or it expires", async () => {
|
|
6136
|
+
const engine = new WorkflowEngine3({
|
|
6137
|
+
store
|
|
6138
|
+
});
|
|
6139
|
+
const failing = /* @__PURE__ */ new Set([
|
|
6140
|
+
"held",
|
|
6141
|
+
"expiring"
|
|
6142
|
+
]);
|
|
6143
|
+
engine.register("wf", "1", async (ctx) => {
|
|
6144
|
+
const a = await ctx.localStep("a", async () => 10);
|
|
6145
|
+
return ctx.localStep("b", async () => {
|
|
6146
|
+
if (failing.delete(ctx.runId)) throw new Error("boom");
|
|
6147
|
+
return a + 5;
|
|
6148
|
+
});
|
|
6149
|
+
});
|
|
6150
|
+
for (const id of [
|
|
6151
|
+
"held",
|
|
6152
|
+
"expiring"
|
|
6153
|
+
]) {
|
|
6154
|
+
await engine.start("wf", {}, id);
|
|
6155
|
+
expect3((await engine.waitForRun(id)).status).toBe("failed");
|
|
6156
|
+
}
|
|
6157
|
+
expect3(await store.tryLockRun("held", "holder", Date.now() + 6e4, Date.now())).toBe(true);
|
|
6158
|
+
const held = engine.resume("held");
|
|
6159
|
+
setTimeout(() => void store.releaseRunLock("held", "holder"), 150);
|
|
6160
|
+
expect3(await held).toMatchObject({
|
|
6161
|
+
status: "completed",
|
|
6162
|
+
output: 15
|
|
6163
|
+
});
|
|
6164
|
+
expect3(await store.tryLockRun("expiring", "gone", Date.now() + 200, Date.now())).toBe(true);
|
|
6165
|
+
expect3(await engine.resume("expiring")).toMatchObject({
|
|
6166
|
+
status: "completed",
|
|
6167
|
+
output: 15
|
|
6168
|
+
});
|
|
6169
|
+
expect3((await store.getRun("expiring"))?.status).toBe("completed");
|
|
6170
|
+
await engine.drain();
|
|
6171
|
+
});
|
|
5965
6172
|
t("starts the version the caller pinned, and refuses one that is not registered", async () => {
|
|
5966
6173
|
const engine = new WorkflowEngine3({
|
|
5967
6174
|
store
|