@rotorsoft/act-tck 0.3.0 → 0.4.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.cjs CHANGED
@@ -916,6 +916,169 @@ var runStoreTck = (options) => {
916
916
  (0, import_vitest3.expect)(got2.priority).toBe(5);
917
917
  });
918
918
  });
919
+ (0, import_vitest3.describe)("lanes", () => {
920
+ (0, import_vitest3.it)("subscribe defaults lane to 'default' when omitted", async () => {
921
+ const s = `lane-default-${uid()}`;
922
+ await store.subscribe([{ stream: s }]);
923
+ const seen = [];
924
+ await store.query_streams((p) => seen.push(p.lane), {
925
+ stream: s,
926
+ stream_exact: true
927
+ });
928
+ (0, import_vitest3.expect)(seen).toEqual(["default"]);
929
+ });
930
+ (0, import_vitest3.it)("subscribe records the lane passed in", async () => {
931
+ const s = `lane-set-${uid()}`;
932
+ await store.subscribe([{ stream: s, lane: "slow" }]);
933
+ const seen = [];
934
+ await store.query_streams((p) => seen.push(p.lane), {
935
+ stream: s,
936
+ stream_exact: true
937
+ });
938
+ (0, import_vitest3.expect)(seen).toEqual(["slow"]);
939
+ });
940
+ (0, import_vitest3.it)("subscribe re-lanes existing streams on subsequent calls", async () => {
941
+ const s = `lane-upsert-${uid()}`;
942
+ await store.subscribe([{ stream: s, lane: "slow" }]);
943
+ await store.subscribe([{ stream: s, lane: "fast" }]);
944
+ const seen = [];
945
+ await store.query_streams((p) => seen.push(p.lane), {
946
+ stream: s,
947
+ stream_exact: true
948
+ });
949
+ (0, import_vitest3.expect)(seen).toEqual(["fast"]);
950
+ });
951
+ (0, import_vitest3.it)("claim() filters by lane when supplied and returns lane on the Lease", async () => {
952
+ const tag = uid();
953
+ const src1 = `lane-claim-src1-${tag}`;
954
+ const src2 = `lane-claim-src2-${tag}`;
955
+ const subDefault = `lane-claim-def-${tag}`;
956
+ const subSlow = `lane-claim-slow-${tag}`;
957
+ await store.commit(
958
+ src1,
959
+ [inc(1)],
960
+ makeMeta({ stream: src1 })
961
+ );
962
+ await store.commit(
963
+ src2,
964
+ [inc(1)],
965
+ makeMeta({ stream: src2 })
966
+ );
967
+ await store.subscribe([
968
+ { stream: subDefault, source: src1 },
969
+ { stream: subSlow, source: src2, lane: "slow" }
970
+ ]);
971
+ const slow = await store.claim(50, 0, `w-slow-${tag}`, 1e3, "slow");
972
+ const slowMine = slow.filter(
973
+ (l) => l.stream === subDefault || l.stream === subSlow
974
+ );
975
+ (0, import_vitest3.expect)(slowMine.map((l) => l.stream)).toEqual([subSlow]);
976
+ (0, import_vitest3.expect)(slowMine[0]?.lane).toBe("slow");
977
+ await store.ack(slowMine.map((l) => ({ ...l, at: l.at + 1 })));
978
+ const all = await store.claim(50, 0, `w-all-${tag}`, 1e3);
979
+ const allMine = all.filter((l) => l.stream === subDefault || l.stream === subSlow).map((l) => ({ stream: l.stream, lane: l.lane }));
980
+ (0, import_vitest3.expect)(allMine).toEqual(
981
+ import_vitest3.expect.arrayContaining([
982
+ { stream: subDefault, lane: "default" },
983
+ { stream: subSlow, lane: "slow" }
984
+ ])
985
+ );
986
+ });
987
+ (0, import_vitest3.it)("query_streams filters by lane", async () => {
988
+ const tag = uid();
989
+ const a = `lane-q-a-${tag}`;
990
+ const b = `lane-q-b-${tag}`;
991
+ const c = `lane-q-c-${tag}`;
992
+ await store.subscribe([
993
+ { stream: a, lane: "qslow" },
994
+ { stream: b, lane: "qfast" },
995
+ { stream: c, lane: "qslow" }
996
+ ]);
997
+ const seen = [];
998
+ await store.query_streams((p) => seen.push(p.stream), {
999
+ lane: "qslow",
1000
+ stream: `lane-q-.*-${tag}`,
1001
+ limit: 100
1002
+ });
1003
+ (0, import_vitest3.expect)(seen.sort()).toEqual([a, c]);
1004
+ });
1005
+ (0, import_vitest3.it)("prioritize filters by lane", async () => {
1006
+ const tag = uid();
1007
+ const a = `lane-pri-a-${tag}`;
1008
+ const b = `lane-pri-b-${tag}`;
1009
+ await store.subscribe([
1010
+ { stream: a, lane: `pslow-${tag}` },
1011
+ { stream: b, lane: `pfast-${tag}` }
1012
+ ]);
1013
+ const updated = await store.prioritize({ lane: `pslow-${tag}` }, 7);
1014
+ (0, import_vitest3.expect)(updated).toBe(1);
1015
+ const seen = /* @__PURE__ */ new Map();
1016
+ await store.query_streams((p) => seen.set(p.stream, p.priority), {
1017
+ stream: `lane-pri-.*-${tag}`,
1018
+ limit: 100
1019
+ });
1020
+ (0, import_vitest3.expect)(seen.get(a)).toBe(7);
1021
+ (0, import_vitest3.expect)(seen.get(b)).toBe(0);
1022
+ });
1023
+ (0, import_vitest3.it)("reset filters by lane", async () => {
1024
+ const tag = uid();
1025
+ const src = `lane-reset-src-${tag}`;
1026
+ const a = `lane-reset-a-${tag}`;
1027
+ const b = `lane-reset-b-${tag}`;
1028
+ await store.commit(
1029
+ src,
1030
+ [inc(1)],
1031
+ makeMeta({ stream: src })
1032
+ );
1033
+ await store.subscribe([
1034
+ { stream: a, source: src, lane: `rslow-${tag}` },
1035
+ { stream: b, source: src, lane: `rfast-${tag}` }
1036
+ ]);
1037
+ const leases = await store.claim(50, 0, `w-${tag}`, 5e3);
1038
+ const mine = leases.filter((l) => l.stream === a || l.stream === b);
1039
+ await store.ack(mine.map((l) => ({ ...l, at: l.at + 1 })));
1040
+ const count = await store.reset({ lane: `rslow-${tag}` });
1041
+ (0, import_vitest3.expect)(count).toBe(1);
1042
+ const ats = /* @__PURE__ */ new Map();
1043
+ for (const name of [a, b]) {
1044
+ await store.query_streams((p) => ats.set(p.stream, p.at), {
1045
+ stream: name,
1046
+ stream_exact: true
1047
+ });
1048
+ }
1049
+ (0, import_vitest3.expect)(ats.get(a)).toBe(-1);
1050
+ (0, import_vitest3.expect)(ats.get(b)).toBeGreaterThanOrEqual(0);
1051
+ });
1052
+ (0, import_vitest3.it)("unblock filters by lane", async () => {
1053
+ const tag = uid();
1054
+ const src = `lane-ub-src-${tag}`;
1055
+ const a = `lane-ub-a-${tag}`;
1056
+ const b = `lane-ub-b-${tag}`;
1057
+ await store.commit(
1058
+ src,
1059
+ [inc(1)],
1060
+ makeMeta({ stream: src })
1061
+ );
1062
+ await store.subscribe([
1063
+ { stream: a, source: src, lane: `uslow-${tag}` },
1064
+ { stream: b, source: src, lane: `ufast-${tag}` }
1065
+ ]);
1066
+ const leases = await store.claim(50, 0, `w-${tag}`, 5e3);
1067
+ const mine = leases.filter((l) => l.stream === a || l.stream === b);
1068
+ await store.block(mine.map((l) => ({ ...l, error: "boom" })));
1069
+ const count = await store.unblock({ lane: `uslow-${tag}` });
1070
+ (0, import_vitest3.expect)(count).toBe(1);
1071
+ const blocked = /* @__PURE__ */ new Map();
1072
+ for (const name of [a, b]) {
1073
+ await store.query_streams((p) => blocked.set(p.stream, p.blocked), {
1074
+ stream: name,
1075
+ stream_exact: true
1076
+ });
1077
+ }
1078
+ (0, import_vitest3.expect)(blocked.get(a)).toBe(false);
1079
+ (0, import_vitest3.expect)(blocked.get(b)).toBe(true);
1080
+ });
1081
+ });
919
1082
  (0, import_vitest3.describe)("truncate", () => {
920
1083
  (0, import_vitest3.it)("seeds a tombstone when no snapshot is provided", async () => {
921
1084
  const s = `trunc-tomb-${uid()}`;