@dudousxd/nestjs-durable-testing 0.23.3 → 0.23.5
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 +6 -0
- package/dist/index.js +73 -0
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/dist/index.d.ts
CHANGED
|
@@ -268,6 +268,12 @@ interface StateStoreContext {
|
|
|
268
268
|
* sends none of the step's input.
|
|
269
269
|
*/
|
|
270
270
|
statementLog?: () => string[];
|
|
271
|
+
/**
|
|
272
|
+
* The store's client opens a transaction around every write of its own (Prisma does, even for one
|
|
273
|
+
* `createMany` or `updateMany`). The contract then checks that a run's row is written without a
|
|
274
|
+
* read of it first, but not that no transaction is opened.
|
|
275
|
+
*/
|
|
276
|
+
implicitTransactions?: boolean;
|
|
271
277
|
}
|
|
272
278
|
/** Builds a fresh, empty store for one test. Called once per `it` (in `beforeEach`). */
|
|
273
279
|
type StateStoreFactory = () => Promise<StateStoreContext>;
|
package/dist/index.js
CHANGED
|
@@ -834,6 +834,11 @@ var checkpoint = /* @__PURE__ */ __name((over = {}) => ({
|
|
|
834
834
|
finishedAt: at,
|
|
835
835
|
...over
|
|
836
836
|
}), "checkpoint");
|
|
837
|
+
var ANSI_COLOR = new RegExp(`${String.fromCharCode(27)}\\[[0-9;]*m`, "g");
|
|
838
|
+
function sqlOf(logged) {
|
|
839
|
+
return logged.replace(ANSI_COLOR, "").replace(/^\s*\[query\]\s*/i, "").trim();
|
|
840
|
+
}
|
|
841
|
+
__name(sqlOf, "sqlOf");
|
|
837
842
|
async function loggedSince(log, before) {
|
|
838
843
|
let seen = -1;
|
|
839
844
|
for (let i = 0; i < 50 && log().length !== seen; i += 1) {
|
|
@@ -852,6 +857,7 @@ function runStateStoreContract(name, makeStore) {
|
|
|
852
857
|
let supportsTagFilter = true;
|
|
853
858
|
let statements;
|
|
854
859
|
let statementLog;
|
|
860
|
+
let implicitTransactions = false;
|
|
855
861
|
let skipReason;
|
|
856
862
|
let loggedSkip = false;
|
|
857
863
|
beforeEach(async () => {
|
|
@@ -864,6 +870,7 @@ function runStateStoreContract(name, makeStore) {
|
|
|
864
870
|
supportsTagFilter = ctx.supportsTagFilter ?? true;
|
|
865
871
|
statements = ctx.statements;
|
|
866
872
|
statementLog = ctx.statementLog;
|
|
873
|
+
implicitTransactions = ctx.implicitTransactions ?? false;
|
|
867
874
|
skipReason = void 0;
|
|
868
875
|
} catch (err) {
|
|
869
876
|
if (isUnavailable(err) && !process.env.DURABLE_TEST_REQUIRE_BACKENDS) {
|
|
@@ -1206,6 +1213,34 @@ function runStateStoreContract(name, makeStore) {
|
|
|
1206
1213
|
"c1"
|
|
1207
1214
|
]);
|
|
1208
1215
|
});
|
|
1216
|
+
t("concurrent claims across many runs of one key all answer, one winning", async () => {
|
|
1217
|
+
if (!supportsTagFilter) return;
|
|
1218
|
+
const ids2 = Array.from({
|
|
1219
|
+
length: 24
|
|
1220
|
+
}, (_, i) => `run-${String(i).padStart(2, "0")}`);
|
|
1221
|
+
for (const [i, id] of ids2.entries()) {
|
|
1222
|
+
await store.createRun(run({
|
|
1223
|
+
id,
|
|
1224
|
+
tags: [
|
|
1225
|
+
"singleton:k"
|
|
1226
|
+
],
|
|
1227
|
+
createdAt: new Date(1e3 + i)
|
|
1228
|
+
}));
|
|
1229
|
+
}
|
|
1230
|
+
for (let round = 0; round < 3; round += 1) {
|
|
1231
|
+
const order = [
|
|
1232
|
+
...ids2
|
|
1233
|
+
].sort(() => Math.random() - 0.5);
|
|
1234
|
+
await Promise.all(order.map((id, i) => (i % 2 ? peerStore : store).tryAdmitSingleton?.(id, "singleton:k", "checkout", 1, Date.now() + 1e3)));
|
|
1235
|
+
}
|
|
1236
|
+
const active = await store.listRuns({
|
|
1237
|
+
workflow: "checkout",
|
|
1238
|
+
tag: "singleton:k"
|
|
1239
|
+
});
|
|
1240
|
+
expect3(active.filter((r) => r.tags?.includes(SINGLETON_ADMITTED_TAG)).map((r) => r.id)).toEqual([
|
|
1241
|
+
"run-00"
|
|
1242
|
+
]);
|
|
1243
|
+
});
|
|
1209
1244
|
t("creates a run and reads it back with its JSON input", async () => {
|
|
1210
1245
|
await store.createRun(run());
|
|
1211
1246
|
const loaded = await store.getRun("r1");
|
|
@@ -2701,6 +2736,44 @@ function runStateStoreContract(name, makeStore) {
|
|
|
2701
2736
|
prompt: "p2"
|
|
2702
2737
|
});
|
|
2703
2738
|
});
|
|
2739
|
+
t("createRun of a run without search attributes reads nothing and opens no transaction", async () => {
|
|
2740
|
+
if (!statementLog) return;
|
|
2741
|
+
await store.createRun(run({
|
|
2742
|
+
id: "warm"
|
|
2743
|
+
}));
|
|
2744
|
+
const before = statementLog().length;
|
|
2745
|
+
await store.createRun(run());
|
|
2746
|
+
const sent = await loggedSince(statementLog, before);
|
|
2747
|
+
expect3(sent.length).toBeGreaterThan(0);
|
|
2748
|
+
expect3(sent.map(sqlOf).filter((q) => /^select/i.test(q))).toEqual([]);
|
|
2749
|
+
if (!implicitTransactions) {
|
|
2750
|
+
expect3(sent.map(sqlOf).filter((q) => /^(begin|start transaction)/i.test(q))).toEqual([]);
|
|
2751
|
+
}
|
|
2752
|
+
expect3((await store.getRun("r1"))?.status).toBe(run().status);
|
|
2753
|
+
});
|
|
2754
|
+
t("updateRun with a non-terminal patch is one UPDATE, with no read of the row", async () => {
|
|
2755
|
+
if (!statementLog) return;
|
|
2756
|
+
await store.createRun(run());
|
|
2757
|
+
await store.updateRun("r1", {
|
|
2758
|
+
status: "running",
|
|
2759
|
+
updatedAt: /* @__PURE__ */ new Date()
|
|
2760
|
+
});
|
|
2761
|
+
const before = statementLog().length;
|
|
2762
|
+
await store.updateRun("r1", {
|
|
2763
|
+
status: "suspended",
|
|
2764
|
+
wakeAt: 5e3,
|
|
2765
|
+
updatedAt: /* @__PURE__ */ new Date()
|
|
2766
|
+
});
|
|
2767
|
+
const sent = await loggedSince(statementLog, before);
|
|
2768
|
+
expect3(sent.map(sqlOf).filter((q) => /^update/i.test(q))).toHaveLength(1);
|
|
2769
|
+
expect3(sent.map(sqlOf).filter((q) => /^select/i.test(q))).toEqual([]);
|
|
2770
|
+
if (!implicitTransactions) {
|
|
2771
|
+
expect3(sent.map(sqlOf).filter((q) => /^(begin|start transaction)/i.test(q))).toEqual([]);
|
|
2772
|
+
}
|
|
2773
|
+
const read = await store.getRun("r1");
|
|
2774
|
+
expect3(read?.status).toBe("suspended");
|
|
2775
|
+
expect3(read?.wakeAt).toBe(5e3);
|
|
2776
|
+
});
|
|
2704
2777
|
t("getCheckpointsForSettle reads no input column", async () => {
|
|
2705
2778
|
if (!statementLog || !store.getCheckpointsForSettle) return;
|
|
2706
2779
|
await store.createRun(run());
|