@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.js CHANGED
@@ -875,6 +875,169 @@ var runStoreTck = (options) => {
875
875
  expect3(got2.priority).toBe(5);
876
876
  });
877
877
  });
878
+ describe3("lanes", () => {
879
+ it3("subscribe defaults lane to 'default' when omitted", async () => {
880
+ const s = `lane-default-${uid()}`;
881
+ await store.subscribe([{ stream: s }]);
882
+ const seen = [];
883
+ await store.query_streams((p) => seen.push(p.lane), {
884
+ stream: s,
885
+ stream_exact: true
886
+ });
887
+ expect3(seen).toEqual(["default"]);
888
+ });
889
+ it3("subscribe records the lane passed in", async () => {
890
+ const s = `lane-set-${uid()}`;
891
+ await store.subscribe([{ stream: s, lane: "slow" }]);
892
+ const seen = [];
893
+ await store.query_streams((p) => seen.push(p.lane), {
894
+ stream: s,
895
+ stream_exact: true
896
+ });
897
+ expect3(seen).toEqual(["slow"]);
898
+ });
899
+ it3("subscribe re-lanes existing streams on subsequent calls", async () => {
900
+ const s = `lane-upsert-${uid()}`;
901
+ await store.subscribe([{ stream: s, lane: "slow" }]);
902
+ await store.subscribe([{ stream: s, lane: "fast" }]);
903
+ const seen = [];
904
+ await store.query_streams((p) => seen.push(p.lane), {
905
+ stream: s,
906
+ stream_exact: true
907
+ });
908
+ expect3(seen).toEqual(["fast"]);
909
+ });
910
+ it3("claim() filters by lane when supplied and returns lane on the Lease", async () => {
911
+ const tag = uid();
912
+ const src1 = `lane-claim-src1-${tag}`;
913
+ const src2 = `lane-claim-src2-${tag}`;
914
+ const subDefault = `lane-claim-def-${tag}`;
915
+ const subSlow = `lane-claim-slow-${tag}`;
916
+ await store.commit(
917
+ src1,
918
+ [inc(1)],
919
+ makeMeta({ stream: src1 })
920
+ );
921
+ await store.commit(
922
+ src2,
923
+ [inc(1)],
924
+ makeMeta({ stream: src2 })
925
+ );
926
+ await store.subscribe([
927
+ { stream: subDefault, source: src1 },
928
+ { stream: subSlow, source: src2, lane: "slow" }
929
+ ]);
930
+ const slow = await store.claim(50, 0, `w-slow-${tag}`, 1e3, "slow");
931
+ const slowMine = slow.filter(
932
+ (l) => l.stream === subDefault || l.stream === subSlow
933
+ );
934
+ expect3(slowMine.map((l) => l.stream)).toEqual([subSlow]);
935
+ expect3(slowMine[0]?.lane).toBe("slow");
936
+ await store.ack(slowMine.map((l) => ({ ...l, at: l.at + 1 })));
937
+ const all = await store.claim(50, 0, `w-all-${tag}`, 1e3);
938
+ const allMine = all.filter((l) => l.stream === subDefault || l.stream === subSlow).map((l) => ({ stream: l.stream, lane: l.lane }));
939
+ expect3(allMine).toEqual(
940
+ expect3.arrayContaining([
941
+ { stream: subDefault, lane: "default" },
942
+ { stream: subSlow, lane: "slow" }
943
+ ])
944
+ );
945
+ });
946
+ it3("query_streams filters by lane", async () => {
947
+ const tag = uid();
948
+ const a = `lane-q-a-${tag}`;
949
+ const b = `lane-q-b-${tag}`;
950
+ const c = `lane-q-c-${tag}`;
951
+ await store.subscribe([
952
+ { stream: a, lane: "qslow" },
953
+ { stream: b, lane: "qfast" },
954
+ { stream: c, lane: "qslow" }
955
+ ]);
956
+ const seen = [];
957
+ await store.query_streams((p) => seen.push(p.stream), {
958
+ lane: "qslow",
959
+ stream: `lane-q-.*-${tag}`,
960
+ limit: 100
961
+ });
962
+ expect3(seen.sort()).toEqual([a, c]);
963
+ });
964
+ it3("prioritize filters by lane", async () => {
965
+ const tag = uid();
966
+ const a = `lane-pri-a-${tag}`;
967
+ const b = `lane-pri-b-${tag}`;
968
+ await store.subscribe([
969
+ { stream: a, lane: `pslow-${tag}` },
970
+ { stream: b, lane: `pfast-${tag}` }
971
+ ]);
972
+ const updated = await store.prioritize({ lane: `pslow-${tag}` }, 7);
973
+ expect3(updated).toBe(1);
974
+ const seen = /* @__PURE__ */ new Map();
975
+ await store.query_streams((p) => seen.set(p.stream, p.priority), {
976
+ stream: `lane-pri-.*-${tag}`,
977
+ limit: 100
978
+ });
979
+ expect3(seen.get(a)).toBe(7);
980
+ expect3(seen.get(b)).toBe(0);
981
+ });
982
+ it3("reset filters by lane", async () => {
983
+ const tag = uid();
984
+ const src = `lane-reset-src-${tag}`;
985
+ const a = `lane-reset-a-${tag}`;
986
+ const b = `lane-reset-b-${tag}`;
987
+ await store.commit(
988
+ src,
989
+ [inc(1)],
990
+ makeMeta({ stream: src })
991
+ );
992
+ await store.subscribe([
993
+ { stream: a, source: src, lane: `rslow-${tag}` },
994
+ { stream: b, source: src, lane: `rfast-${tag}` }
995
+ ]);
996
+ const leases = await store.claim(50, 0, `w-${tag}`, 5e3);
997
+ const mine = leases.filter((l) => l.stream === a || l.stream === b);
998
+ await store.ack(mine.map((l) => ({ ...l, at: l.at + 1 })));
999
+ const count = await store.reset({ lane: `rslow-${tag}` });
1000
+ expect3(count).toBe(1);
1001
+ const ats = /* @__PURE__ */ new Map();
1002
+ for (const name of [a, b]) {
1003
+ await store.query_streams((p) => ats.set(p.stream, p.at), {
1004
+ stream: name,
1005
+ stream_exact: true
1006
+ });
1007
+ }
1008
+ expect3(ats.get(a)).toBe(-1);
1009
+ expect3(ats.get(b)).toBeGreaterThanOrEqual(0);
1010
+ });
1011
+ it3("unblock filters by lane", async () => {
1012
+ const tag = uid();
1013
+ const src = `lane-ub-src-${tag}`;
1014
+ const a = `lane-ub-a-${tag}`;
1015
+ const b = `lane-ub-b-${tag}`;
1016
+ await store.commit(
1017
+ src,
1018
+ [inc(1)],
1019
+ makeMeta({ stream: src })
1020
+ );
1021
+ await store.subscribe([
1022
+ { stream: a, source: src, lane: `uslow-${tag}` },
1023
+ { stream: b, source: src, lane: `ufast-${tag}` }
1024
+ ]);
1025
+ const leases = await store.claim(50, 0, `w-${tag}`, 5e3);
1026
+ const mine = leases.filter((l) => l.stream === a || l.stream === b);
1027
+ await store.block(mine.map((l) => ({ ...l, error: "boom" })));
1028
+ const count = await store.unblock({ lane: `uslow-${tag}` });
1029
+ expect3(count).toBe(1);
1030
+ const blocked = /* @__PURE__ */ new Map();
1031
+ for (const name of [a, b]) {
1032
+ await store.query_streams((p) => blocked.set(p.stream, p.blocked), {
1033
+ stream: name,
1034
+ stream_exact: true
1035
+ });
1036
+ }
1037
+ expect3(blocked.get(a)).toBe(false);
1038
+ expect3(blocked.get(b)).toBe(true);
1039
+ });
1040
+ });
878
1041
  describe3("truncate", () => {
879
1042
  it3("seeds a tombstone when no snapshot is provided", async () => {
880
1043
  const s = `trunc-tomb-${uid()}`;