@dudousxd/nestjs-durable-testing 0.23.4 → 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.js CHANGED
@@ -1213,6 +1213,34 @@ function runStateStoreContract(name, makeStore) {
1213
1213
  "c1"
1214
1214
  ]);
1215
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
+ });
1216
1244
  t("creates a run and reads it back with its JSON input", async () => {
1217
1245
  await store.createRun(run());
1218
1246
  const loaded = await store.getRun("r1");