@rotorsoft/act-tck 1.35.0 → 1.36.0

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
@@ -908,6 +908,7 @@ var opArb = fc.oneof(
908
908
  var events = (count) => Array.from({ length: count }, () => inc(1));
909
909
  var runStorePropertyTck = (options) => {
910
910
  const numRuns = options.numRuns ?? 100;
911
+ const timeout = options.timeoutMs ?? 5e3;
911
912
  describe7(`TCK / Store properties / ${options.name}`, () => {
912
913
  let store;
913
914
  beforeAll3(async () => {
@@ -947,7 +948,8 @@ var runStorePropertyTck = (options) => {
947
948
  expect7(e.version).toBe(i);
948
949
  });
949
950
  }
950
- }
951
+ },
952
+ timeout
951
953
  );
952
954
  test.prop([fc.array(commitArb, { minLength: 1, maxLength: 20 })], {
953
955
  numRuns
@@ -974,7 +976,8 @@ var runStorePropertyTck = (options) => {
974
976
  ).rejects.toThrow();
975
977
  const after = await collect(store, { stream, stream_exact: true });
976
978
  expect7(after.length).toBe(before.length);
977
- }
979
+ },
980
+ timeout
978
981
  );
979
982
  });
980
983
  describe7("claim/lease lifecycle invariants", () => {
@@ -1021,7 +1024,8 @@ var runStorePropertyTck = (options) => {
1021
1024
  }
1022
1025
  }
1023
1026
  expect7(totalResolved + pending.length).toBe(totalClaims);
1024
- }
1027
+ },
1028
+ timeout
1025
1029
  );
1026
1030
  test.prop(
1027
1031
  [
@@ -1064,35 +1068,40 @@ var runStorePropertyTck = (options) => {
1064
1068
  watermark1.get(lease.stream)
1065
1069
  );
1066
1070
  }
1067
- }
1071
+ },
1072
+ timeout
1068
1073
  );
1069
1074
  test.prop([fc.array(claimStreamArb, { minLength: 1, maxLength: 5 })], {
1070
1075
  numRuns
1071
- })("blocked streams cannot be claimed again", async (commits) => {
1072
- await reset2();
1073
- const streams = [...new Set(commits)];
1074
- await store.subscribe(streams.map((stream) => ({ stream })));
1075
- for (const stream of commits) {
1076
+ })(
1077
+ "blocked streams cannot be claimed again",
1078
+ async (commits) => {
1079
+ await reset2();
1080
+ const streams = [...new Set(commits)];
1081
+ await store.subscribe(streams.map((stream) => ({ stream })));
1082
+ for (const stream of commits) {
1083
+ await store.commit(
1084
+ stream,
1085
+ [inc(1)],
1086
+ make_meta({ stream })
1087
+ );
1088
+ }
1089
+ await mark_all2(store);
1090
+ const claimed = await store.claim(10, 10, "worker", 6e4);
1091
+ await store.block(claimed.map((l) => ({ ...l, error: "test" })));
1092
+ const blockedSet = new Set(claimed.map((l) => l.stream));
1093
+ await store.subscribe([{ stream: "ctrl" }]);
1076
1094
  await store.commit(
1077
- stream,
1095
+ "ctrl",
1078
1096
  [inc(1)],
1079
- make_meta({ stream })
1097
+ make_meta({ stream: "ctrl" })
1080
1098
  );
1081
- }
1082
- await mark_all2(store);
1083
- const claimed = await store.claim(10, 10, "worker", 6e4);
1084
- await store.block(claimed.map((l) => ({ ...l, error: "test" })));
1085
- const blockedSet = new Set(claimed.map((l) => l.stream));
1086
- await store.subscribe([{ stream: "ctrl" }]);
1087
- await store.commit(
1088
- "ctrl",
1089
- [inc(1)],
1090
- make_meta({ stream: "ctrl" })
1091
- );
1092
- await mark_all2(store);
1093
- const reclaim = await store.claim(10, 10, "worker2", 6e4);
1094
- for (const l of reclaim) expect7(blockedSet.has(l.stream)).toBe(false);
1095
- });
1099
+ await mark_all2(store);
1100
+ const reclaim = await store.claim(10, 10, "worker2", 6e4);
1101
+ for (const l of reclaim) expect7(blockedSet.has(l.stream)).toBe(false);
1102
+ },
1103
+ timeout
1104
+ );
1096
1105
  });
1097
1106
  });
1098
1107
  };
@@ -4149,6 +4158,103 @@ var runStoreTck = (options) => {
4149
4158
  }
4150
4159
  });
4151
4160
  });
4161
+ describe8.skipIf(!caps.lease_correlation)(
4162
+ "correlation lease via subscribe (capability)",
4163
+ () => {
4164
+ const by = () => `corr-${uid()}`;
4165
+ const key = () => `key-${uid()}`;
4166
+ const take = (k, who, millis = 1e4) => store.subscribe([], void 0, { key: k, by: who, millis });
4167
+ const release = async (k, who) => {
4168
+ await take(k, who, 1);
4169
+ await new Promise((r) => setTimeout(r, 20));
4170
+ };
4171
+ it7("grants the lease to the first caller", async () => {
4172
+ const k = key();
4173
+ const who = by();
4174
+ expect8((await take(k, who)).correlating).toBe(true);
4175
+ await release(k, who);
4176
+ });
4177
+ it7("answers undefined when no correlator is supplied", async () => {
4178
+ expect8(await store.subscribe([])).not.toHaveProperty("correlating");
4179
+ });
4180
+ it7("refuses a second holder while the lease is live", async () => {
4181
+ const k = key();
4182
+ const who = by();
4183
+ expect8((await take(k, who)).correlating).toBe(true);
4184
+ expect8((await take(k, by())).correlating).toBe(false);
4185
+ await release(k, who);
4186
+ });
4187
+ it7("lets the same holder renew rather than failing", async () => {
4188
+ const k = key();
4189
+ const who = by();
4190
+ expect8((await take(k, who)).correlating).toBe(true);
4191
+ expect8((await take(k, who)).correlating).toBe(true);
4192
+ await release(k, who);
4193
+ });
4194
+ it7("becomes available again once the lease expires", async () => {
4195
+ const k = key();
4196
+ expect8((await take(k, by(), 1)).correlating).toBe(true);
4197
+ await new Promise((r) => setTimeout(r, 30));
4198
+ const next = by();
4199
+ expect8((await take(k, next)).correlating).toBe(true);
4200
+ await release(k, next);
4201
+ });
4202
+ it7("keys leases independently, so one correlator cannot starve another", async () => {
4203
+ const a = key();
4204
+ const b = key();
4205
+ const holder_a = by();
4206
+ const holder_b = by();
4207
+ expect8((await take(a, holder_a)).correlating).toBe(true);
4208
+ expect8((await take(b, holder_b)).correlating).toBe(true);
4209
+ await release(a, holder_a);
4210
+ await release(b, holder_b);
4211
+ });
4212
+ it7("still advances the checkpoint for a caller that loses the lease", async () => {
4213
+ const k = key();
4214
+ const holder = by();
4215
+ expect8((await take(k, holder)).correlating).toBe(true);
4216
+ const loser = await store.subscribe([], 7777, {
4217
+ key: k,
4218
+ by: by(),
4219
+ millis: 1e4
4220
+ });
4221
+ expect8(loser.correlating).toBe(false);
4222
+ expect8(loser.correlated_at).toBeGreaterThanOrEqual(7777);
4223
+ await release(k, holder);
4224
+ });
4225
+ it7("seeds a new key from the shared floor, then lets it diverge", async () => {
4226
+ const a = key();
4227
+ const holder_a = by();
4228
+ const first = await store.subscribe([], 4100, {
4229
+ key: a,
4230
+ by: holder_a,
4231
+ millis: 1e4
4232
+ });
4233
+ expect8(first.correlated_at).toBeGreaterThanOrEqual(4100);
4234
+ const b = key();
4235
+ const holder_b = by();
4236
+ const second = await store.subscribe([], void 0, {
4237
+ key: b,
4238
+ by: holder_b,
4239
+ millis: 1e4
4240
+ });
4241
+ expect8(second.correlated_at).toBeGreaterThanOrEqual(4100);
4242
+ await store.subscribe([], 9e3, {
4243
+ key: a,
4244
+ by: holder_a,
4245
+ millis: 1e4
4246
+ });
4247
+ const b_again = await store.subscribe([], void 0, {
4248
+ key: b,
4249
+ by: holder_b,
4250
+ millis: 1e4
4251
+ });
4252
+ expect8(b_again.correlated_at).toBe(second.correlated_at);
4253
+ await release(a, holder_a);
4254
+ await release(b, holder_b);
4255
+ });
4256
+ }
4257
+ );
4152
4258
  describe8.skipIf(!caps.restore)("restore (capability)", () => {
4153
4259
  beforeEach(async () => {
4154
4260
  await store.drop();