@rikalabs/akter 0.1.0-alpha.0 → 0.1.0-alpha.3

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.
Files changed (308) hide show
  1. package/CHANGELOG.md +46 -3
  2. package/README.md +2 -2
  3. package/dist/actor/definition.d.ts +13 -9
  4. package/dist/actor/descriptor.d.ts +2 -2
  5. package/dist/actor/descriptor.js +4 -4
  6. package/dist/client/calls.js +1 -1
  7. package/dist/client/index.d.ts +1 -1
  8. package/dist/client/index.js +1 -1
  9. package/dist/errors/actor.d.ts +12 -42
  10. package/dist/errors/actor.js +13 -42
  11. package/dist/index.d.ts +1 -1
  12. package/dist/index.js +1 -1
  13. package/dist/members/payload.d.ts +1 -1
  14. package/dist/protocol/inspection.d.ts +221 -1
  15. package/dist/protocol/inspection.js +151 -2
  16. package/dist/protocol/wire.d.ts +6 -49
  17. package/dist/protocol/wire.js +1 -10
  18. package/dist/runtime/actors.d.ts +3 -0
  19. package/dist/runtime/adoption/backfill.js +1 -1
  20. package/dist/runtime/adoption/enforce.js +2 -2
  21. package/dist/runtime/adoption/observe.js +1 -1
  22. package/dist/runtime/adoption/plan.d.ts +1 -1
  23. package/dist/runtime/adoption/startup.js +1 -1
  24. package/dist/runtime/adoption/status.d.ts +1 -1
  25. package/dist/runtime/app.d.ts +65 -0
  26. package/dist/runtime/app.js +38 -0
  27. package/dist/runtime/connections/holder.d.ts +11 -1
  28. package/dist/runtime/connections/holder.js +8 -4
  29. package/dist/runtime/connections/streams.d.ts +4 -4
  30. package/dist/runtime/content/store.js +15 -11
  31. package/dist/runtime/database/bounded.d.ts +4 -18
  32. package/dist/runtime/database/bounded.js +36 -22
  33. package/dist/runtime/database/coordination.d.ts +12 -3
  34. package/dist/runtime/database/coordination.js +29 -36
  35. package/dist/runtime/database/migrations.d.ts +61 -29
  36. package/dist/runtime/database/migrations.js +375 -139
  37. package/dist/runtime/database/replica.d.ts +4 -1
  38. package/dist/runtime/database/replica.js +4 -1
  39. package/dist/runtime/database/schema.d.ts +13 -0
  40. package/dist/runtime/database/schema.js +13 -0
  41. package/dist/runtime/database/shards.d.ts +31 -13
  42. package/dist/runtime/database/shards.js +38 -26
  43. package/dist/runtime/entity/register.d.ts +8 -1
  44. package/dist/runtime/entity/register.js +58 -7
  45. package/dist/runtime/fleet/checks.js +4 -4
  46. package/dist/runtime/fleet/maintainer.d.ts +1 -1
  47. package/dist/runtime/fleet/maintainer.js +1 -1
  48. package/dist/runtime/index.d.ts +2 -0
  49. package/dist/runtime/index.js +1 -0
  50. package/dist/runtime/inspector/layer.d.ts +20 -0
  51. package/dist/runtime/inspector/layer.js +224 -5
  52. package/dist/runtime/inspector/queries.d.ts +54 -8
  53. package/dist/runtime/inspector/queries.js +84 -15
  54. package/dist/runtime/layer.d.ts +48 -39
  55. package/dist/runtime/layer.js +124 -56
  56. package/dist/runtime/operators/audit.d.ts +3 -0
  57. package/dist/runtime/operators/audit.js +6 -2
  58. package/dist/runtime/operators/repair.js +30 -10
  59. package/dist/runtime/operators/seed.js +4 -2
  60. package/dist/runtime/payloads/versions.d.ts +4 -4
  61. package/dist/runtime/payloads/versions.js +24 -15
  62. package/dist/runtime/queries.js +4 -2
  63. package/dist/runtime/registration.d.ts +5 -2
  64. package/dist/runtime/registration.js +3 -3
  65. package/dist/runtime/runner.d.ts +12 -0
  66. package/dist/runtime/runner.js +12 -0
  67. package/dist/runtime/storage/codec.d.ts +19 -7
  68. package/dist/runtime/storage/codec.js +23 -7
  69. package/dist/runtime/storage/placements.d.ts +6 -1
  70. package/dist/runtime/storage/placements.js +98 -6
  71. package/dist/runtime/storage/retention.d.ts +6 -0
  72. package/dist/runtime/storage/retention.js +25 -13
  73. package/dist/runtime/subscriptions/relay.js +47 -44
  74. package/dist/runtime/subscriptions/storage.d.ts +3 -2
  75. package/dist/runtime/subscriptions/storage.js +9 -6
  76. package/dist/runtime/telemetry/live.d.ts +255 -0
  77. package/dist/runtime/telemetry/live.js +540 -0
  78. package/dist/runtime/telemetry/metrics.d.ts +2 -0
  79. package/dist/runtime/telemetry/metrics.js +4 -1
  80. package/dist/runtime/telemetry/sampler.js +33 -13
  81. package/dist/runtime/telemetry/spans.d.ts +1 -1
  82. package/dist/runtime/telemetry/spans.js +1 -1
  83. package/dist/runtime/topology/locks.d.ts +6 -3
  84. package/dist/runtime/topology/locks.js +27 -4
  85. package/dist/runtime/turn/execute.d.ts +2 -0
  86. package/dist/runtime/turn/execute.js +5 -2
  87. package/dist/runtime/turn/pipeline.d.ts +5 -12
  88. package/dist/runtime/turn/pipeline.js +11 -11
  89. package/dist/runtime/turn/relay.d.ts +13 -3
  90. package/dist/runtime/turn/relay.js +27 -14
  91. package/dist/runtime/turn/rows.js +4 -4
  92. package/dist/runtime/workflows/compatibility.d.ts +1 -1
  93. package/dist/runtime/workflows/compatibility.js +85 -31
  94. package/dist/runtime/workflows/engine.js +20 -17
  95. package/dist/serve/layer.js +3 -2
  96. package/dist/tables/owned.d.ts +1 -1
  97. package/dist/tables/owned.js +1 -1
  98. package/dist/testing/actor-test.d.ts +2 -24
  99. package/dist/testing/actor-test.js +1 -27
  100. package/dist/testing/index.d.ts +0 -12
  101. package/dist/testing/index.js +0 -6
  102. package/package.json +1 -1
  103. package/dist/runtime/database/neki/migrations.d.ts +0 -31
  104. package/dist/runtime/database/neki/migrations.js +0 -276
  105. package/dist/runtime/database/neki/session.d.ts +0 -23
  106. package/dist/runtime/database/neki/session.js +0 -31
  107. package/dist/testing/cluster.d.ts +0 -93
  108. package/dist/testing/cluster.js +0 -296
  109. package/dist/testing/conformance/access.d.ts +0 -5
  110. package/dist/testing/conformance/access.js +0 -531
  111. package/dist/testing/conformance/admission.d.ts +0 -11
  112. package/dist/testing/conformance/admission.js +0 -182
  113. package/dist/testing/conformance/adoption.d.ts +0 -2
  114. package/dist/testing/conformance/adoption.js +0 -1019
  115. package/dist/testing/conformance/assertions.d.ts +0 -202
  116. package/dist/testing/conformance/assertions.js +0 -849
  117. package/dist/testing/conformance/batches.d.ts +0 -41
  118. package/dist/testing/conformance/batches.js +0 -388
  119. package/dist/testing/conformance/blobs.d.ts +0 -14
  120. package/dist/testing/conformance/blobs.js +0 -405
  121. package/dist/testing/conformance/capacity.d.ts +0 -8
  122. package/dist/testing/conformance/capacity.js +0 -433
  123. package/dist/testing/conformance/client.d.ts +0 -5
  124. package/dist/testing/conformance/client.js +0 -719
  125. package/dist/testing/conformance/cold-serve.d.ts +0 -16
  126. package/dist/testing/conformance/cold-serve.js +0 -254
  127. package/dist/testing/conformance/connections/actors.d.ts +0 -1143
  128. package/dist/testing/conformance/connections/actors.js +0 -180
  129. package/dist/testing/conformance/connections/harness.d.ts +0 -1754
  130. package/dist/testing/conformance/connections/harness.js +0 -142
  131. package/dist/testing/conformance/connections/holders.d.ts +0 -4
  132. package/dist/testing/conformance/connections/holders.js +0 -165
  133. package/dist/testing/conformance/connections/lifecycle.d.ts +0 -4
  134. package/dist/testing/conformance/connections/lifecycle.js +0 -113
  135. package/dist/testing/conformance/connections/limits.d.ts +0 -4
  136. package/dist/testing/conformance/connections/limits.js +0 -127
  137. package/dist/testing/conformance/connections/reauthorization.d.ts +0 -4
  138. package/dist/testing/conformance/connections/reauthorization.js +0 -170
  139. package/dist/testing/conformance/connections/resync.d.ts +0 -4
  140. package/dist/testing/conformance/connections/resync.js +0 -360
  141. package/dist/testing/conformance/connections/takeover.d.ts +0 -4
  142. package/dist/testing/conformance/connections/takeover.js +0 -287
  143. package/dist/testing/conformance/connections.d.ts +0 -4
  144. package/dist/testing/conformance/connections.js +0 -15
  145. package/dist/testing/conformance/content-blobs.d.ts +0 -16
  146. package/dist/testing/conformance/content-blobs.js +0 -534
  147. package/dist/testing/conformance/counter.d.ts +0 -16
  148. package/dist/testing/conformance/counter.js +0 -813
  149. package/dist/testing/conformance/cron.d.ts +0 -5
  150. package/dist/testing/conformance/cron.js +0 -665
  151. package/dist/testing/conformance/drain.d.ts +0 -26
  152. package/dist/testing/conformance/drain.js +0 -540
  153. package/dist/testing/conformance/effect-control.d.ts +0 -38
  154. package/dist/testing/conformance/effect-control.js +0 -1059
  155. package/dist/testing/conformance/effects.d.ts +0 -23
  156. package/dist/testing/conformance/effects.js +0 -432
  157. package/dist/testing/conformance/events.d.ts +0 -28
  158. package/dist/testing/conformance/events.js +0 -335
  159. package/dist/testing/conformance/export.d.ts +0 -2
  160. package/dist/testing/conformance/export.js +0 -368
  161. package/dist/testing/conformance/fleet.d.ts +0 -444
  162. package/dist/testing/conformance/fleet.js +0 -1009
  163. package/dist/testing/conformance/groups.d.ts +0 -7
  164. package/dist/testing/conformance/groups.js +0 -353
  165. package/dist/testing/conformance/heap.d.ts +0 -3
  166. package/dist/testing/conformance/heap.js +0 -149
  167. package/dist/testing/conformance/http.d.ts +0 -2809
  168. package/dist/testing/conformance/http.js +0 -1234
  169. package/dist/testing/conformance/inspection-views.d.ts +0 -8
  170. package/dist/testing/conformance/inspection-views.js +0 -272
  171. package/dist/testing/conformance/inspector.d.ts +0 -7
  172. package/dist/testing/conformance/inspector.js +0 -650
  173. package/dist/testing/conformance/mint.d.ts +0 -58
  174. package/dist/testing/conformance/mint.js +0 -692
  175. package/dist/testing/conformance/multi-runner.d.ts +0 -8
  176. package/dist/testing/conformance/multi-runner.js +0 -403
  177. package/dist/testing/conformance/neki/plan.d.ts +0 -19
  178. package/dist/testing/conformance/neki/plan.js +0 -30
  179. package/dist/testing/conformance/observability.d.ts +0 -3
  180. package/dist/testing/conformance/observability.js +0 -343
  181. package/dist/testing/conformance/offline.d.ts +0 -4
  182. package/dist/testing/conformance/offline.js +0 -474
  183. package/dist/testing/conformance/operator-harness.d.ts +0 -57
  184. package/dist/testing/conformance/operator-harness.js +0 -78
  185. package/dist/testing/conformance/operator.d.ts +0 -3
  186. package/dist/testing/conformance/operator.js +0 -379
  187. package/dist/testing/conformance/outbox-cross-shard.d.ts +0 -14
  188. package/dist/testing/conformance/outbox-cross-shard.js +0 -160
  189. package/dist/testing/conformance/outbox.d.ts +0 -36
  190. package/dist/testing/conformance/outbox.js +0 -437
  191. package/dist/testing/conformance/payload-migrations.d.ts +0 -3
  192. package/dist/testing/conformance/payload-migrations.js +0 -612
  193. package/dist/testing/conformance/pipeline.d.ts +0 -3
  194. package/dist/testing/conformance/pipeline.js +0 -1040
  195. package/dist/testing/conformance/placement.d.ts +0 -22
  196. package/dist/testing/conformance/placement.js +0 -539
  197. package/dist/testing/conformance/platform.d.ts +0 -40
  198. package/dist/testing/conformance/platform.js +0 -101
  199. package/dist/testing/conformance/progress.d.ts +0 -39
  200. package/dist/testing/conformance/progress.js +0 -666
  201. package/dist/testing/conformance/properties.d.ts +0 -6
  202. package/dist/testing/conformance/properties.js +0 -295
  203. package/dist/testing/conformance/protocols.d.ts +0 -4
  204. package/dist/testing/conformance/protocols.js +0 -618
  205. package/dist/testing/conformance/provider/advertise.d.ts +0 -21
  206. package/dist/testing/conformance/provider/advertise.js +0 -44
  207. package/dist/testing/conformance/read-your-writes.d.ts +0 -20
  208. package/dist/testing/conformance/read-your-writes.js +0 -192
  209. package/dist/testing/conformance/reducers.d.ts +0 -8
  210. package/dist/testing/conformance/reducers.js +0 -258
  211. package/dist/testing/conformance/relay.d.ts +0 -42
  212. package/dist/testing/conformance/relay.js +0 -1115
  213. package/dist/testing/conformance/restore.d.ts +0 -43
  214. package/dist/testing/conformance/restore.js +0 -341
  215. package/dist/testing/conformance/retention.d.ts +0 -14
  216. package/dist/testing/conformance/retention.js +0 -463
  217. package/dist/testing/conformance/rls.d.ts +0 -24
  218. package/dist/testing/conformance/rls.js +0 -576
  219. package/dist/testing/conformance/simulation.d.ts +0 -31
  220. package/dist/testing/conformance/simulation.js +0 -167
  221. package/dist/testing/conformance/single-shard.d.ts +0 -2
  222. package/dist/testing/conformance/single-shard.js +0 -125
  223. package/dist/testing/conformance/singleton.d.ts +0 -3
  224. package/dist/testing/conformance/singleton.js +0 -293
  225. package/dist/testing/conformance/statements.d.ts +0 -60
  226. package/dist/testing/conformance/statements.js +0 -108
  227. package/dist/testing/conformance/streams.d.ts +0 -7
  228. package/dist/testing/conformance/streams.js +0 -280
  229. package/dist/testing/conformance/subscriptions/access.d.ts +0 -4
  230. package/dist/testing/conformance/subscriptions/access.js +0 -98
  231. package/dist/testing/conformance/subscriptions/actors.d.ts +0 -4910
  232. package/dist/testing/conformance/subscriptions/actors.js +0 -372
  233. package/dist/testing/conformance/subscriptions/cluster.d.ts +0 -4
  234. package/dist/testing/conformance/subscriptions/cluster.js +0 -89
  235. package/dist/testing/conformance/subscriptions/delivery.d.ts +0 -4
  236. package/dist/testing/conformance/subscriptions/delivery.js +0 -253
  237. package/dist/testing/conformance/subscriptions/deploys.d.ts +0 -4
  238. package/dist/testing/conformance/subscriptions/deploys.js +0 -162
  239. package/dist/testing/conformance/subscriptions/epochs.d.ts +0 -4
  240. package/dist/testing/conformance/subscriptions/epochs.js +0 -169
  241. package/dist/testing/conformance/subscriptions/failures.d.ts +0 -4
  242. package/dist/testing/conformance/subscriptions/failures.js +0 -108
  243. package/dist/testing/conformance/subscriptions/feeds.d.ts +0 -4
  244. package/dist/testing/conformance/subscriptions/feeds.js +0 -218
  245. package/dist/testing/conformance/subscriptions/harness.d.ts +0 -124
  246. package/dist/testing/conformance/subscriptions/harness.js +0 -143
  247. package/dist/testing/conformance/subscriptions/operator.d.ts +0 -4
  248. package/dist/testing/conformance/subscriptions/operator.js +0 -128
  249. package/dist/testing/conformance/subscriptions/retention.d.ts +0 -4
  250. package/dist/testing/conformance/subscriptions/retention.js +0 -288
  251. package/dist/testing/conformance/subscriptions/routing.d.ts +0 -4
  252. package/dist/testing/conformance/subscriptions/routing.js +0 -179
  253. package/dist/testing/conformance/subscriptions.d.ts +0 -4
  254. package/dist/testing/conformance/subscriptions.js +0 -19
  255. package/dist/testing/conformance/tables.d.ts +0 -125
  256. package/dist/testing/conformance/tables.js +0 -664
  257. package/dist/testing/conformance/transports/actors.d.ts +0 -1907
  258. package/dist/testing/conformance/transports/actors.js +0 -163
  259. package/dist/testing/conformance/transports/client.d.ts +0 -3
  260. package/dist/testing/conformance/transports/client.js +0 -237
  261. package/dist/testing/conformance/transports/feeds.d.ts +0 -3
  262. package/dist/testing/conformance/transports/feeds.js +0 -232
  263. package/dist/testing/conformance/transports/harness.d.ts +0 -93
  264. package/dist/testing/conformance/transports/harness.js +0 -84
  265. package/dist/testing/conformance/transports/streams.d.ts +0 -3
  266. package/dist/testing/conformance/transports/streams.js +0 -96
  267. package/dist/testing/conformance/transports/websocket.d.ts +0 -3
  268. package/dist/testing/conformance/transports/websocket.js +0 -384
  269. package/dist/testing/conformance/transports/wire.d.ts +0 -141
  270. package/dist/testing/conformance/transports/wire.js +0 -204
  271. package/dist/testing/conformance/transports.d.ts +0 -3
  272. package/dist/testing/conformance/transports.js +0 -11
  273. package/dist/testing/conformance/watch.d.ts +0 -59
  274. package/dist/testing/conformance/watch.js +0 -879
  275. package/dist/testing/conformance/workflow-engine.d.ts +0 -97
  276. package/dist/testing/conformance/workflow-engine.js +0 -253
  277. package/dist/testing/conformance/workflow-versions.d.ts +0 -3
  278. package/dist/testing/conformance/workflow-versions.js +0 -545
  279. package/dist/testing/conformance/workflows/access.d.ts +0 -4
  280. package/dist/testing/conformance/workflows/access.js +0 -147
  281. package/dist/testing/conformance/workflows/actors.d.ts +0 -2317
  282. package/dist/testing/conformance/workflows/actors.js +0 -305
  283. package/dist/testing/conformance/workflows/basics.d.ts +0 -4
  284. package/dist/testing/conformance/workflows/basics.js +0 -144
  285. package/dist/testing/conformance/workflows/engine.d.ts +0 -4
  286. package/dist/testing/conformance/workflows/engine.js +0 -80
  287. package/dist/testing/conformance/workflows/guards.d.ts +0 -4
  288. package/dist/testing/conformance/workflows/guards.js +0 -172
  289. package/dist/testing/conformance/workflows/harness.d.ts +0 -14
  290. package/dist/testing/conformance/workflows/harness.js +0 -44
  291. package/dist/testing/conformance/workflows/recovery.d.ts +0 -4
  292. package/dist/testing/conformance/workflows/recovery.js +0 -181
  293. package/dist/testing/conformance/workflows/starts.d.ts +0 -4
  294. package/dist/testing/conformance/workflows/starts.js +0 -57
  295. package/dist/testing/conformance/workflows/suspension.d.ts +0 -4
  296. package/dist/testing/conformance/workflows/suspension.js +0 -106
  297. package/dist/testing/conformance/workflows/waits.d.ts +0 -4
  298. package/dist/testing/conformance/workflows/waits.js +0 -284
  299. package/dist/testing/conformance/workflows.d.ts +0 -4
  300. package/dist/testing/conformance/workflows.js +0 -19
  301. package/dist/testing/conformance.d.ts +0 -330
  302. package/dist/testing/conformance.js +0 -364
  303. package/dist/testing/foundation.d.ts +0 -41
  304. package/dist/testing/foundation.js +0 -517
  305. package/dist/testing/simulate-cluster.d.ts +0 -112
  306. package/dist/testing/simulate-cluster.js +0 -257
  307. package/dist/testing/simulate.d.ts +0 -90
  308. package/dist/testing/simulate.js +0 -127
@@ -1,108 +0,0 @@
1
- import { Effect } from "effect";
2
- import { ActorTest } from "../../actor-test.js";
3
- import { CLAIM_LEASE } from "../outbox.js";
4
- import { SubFollower, SubOrder } from "./actors.js";
5
- import { drain, followerLog, handlerRuns, logOf, run, sourceRows } from "./harness.js";
6
- /** Blocking, ordering, and backoff of failing subscription deliveries. */
7
- export const subscriptionFailureConformance = [
8
- {
9
- name: "holds later events behind a failing one on the same row only, and interleaves two sources",
10
- run: ({ expect, environment, fixture }) => run(environment, fixture, Effect.gen(function* () {
11
- const test = yield* ActorTest;
12
- const follower = yield* SubFollower.get("hold-follower");
13
- yield* follower.Follow({ source: "hold-a" });
14
- yield* follower.Follow({ source: "hold-b" });
15
- yield* drain;
16
- fixture.behave = (entry) => (entry.includes("/hold-a#1:") ? "defect" : "apply");
17
- yield* (yield* SubOrder.get("hold-a")).PlaceMany({ customerId: "h", count: 2 });
18
- yield* (yield* SubOrder.get("hold-b")).PlaceMany({ customerId: "h", count: 2 });
19
- yield* drain;
20
- expect(yield* followerLog("hold-follower")).toEqual([
21
- "hold-b#1:OrderPlaced",
22
- "hold-b#2:OrderPlaced",
23
- ]);
24
- const [held] = yield* sourceRows("hold-a");
25
- expect(held).toMatchObject({ delivered: "0", attempts: 1 });
26
- expect(held.last_error?.includes("Handler defect")).toBe(true);
27
- fixture.behave = () => "apply";
28
- yield* test.advance(CLAIM_LEASE);
29
- expect(yield* followerLog("hold-follower")).toEqual([
30
- "hold-b#1:OrderPlaced",
31
- "hold-b#2:OrderPlaced",
32
- "hold-a#1:OrderPlaced",
33
- "hold-a#2:OrderPlaced",
34
- ]);
35
- })),
36
- },
37
- {
38
- name: "holds a routed source's later events for every routed subscriber while one is blocked, and lets other subscriptions of the same source proceed",
39
- run: ({ expect, environment, fixture }) => run(environment, fixture, Effect.gen(function* () {
40
- const test = yield* ActorTest;
41
- const order = yield* SubOrder.get("blocked-order");
42
- fixture.behave = (entry) => entry.startsWith("SubSummary/blocked-first/") ? "defect" : "apply";
43
- yield* order.Place({ customerId: "blocked-first", amount: 1 });
44
- yield* order.Place({ customerId: "blocked-second", amount: 1 });
45
- yield* drain;
46
- expect(yield* logOf("SubSummary", "blocked-first")).toEqual([]);
47
- expect(yield* logOf("SubSummary", "blocked-second")).toEqual([]);
48
- expect(yield* logOf("SubAuditor", "blocked-first")).toEqual([
49
- "blocked-order#1:OrderPlaced",
50
- ]);
51
- expect(yield* logOf("SubAuditor", "blocked-second")).toEqual([
52
- "blocked-order#2:OrderPlaced",
53
- ]);
54
- const [summary] = yield* sourceRows("blocked-order", "SubSummary");
55
- expect(summary.attempts).toBe(1);
56
- expect(summary.last_error?.includes("Handler defect")).toBe(true);
57
- fixture.behave = () => "apply";
58
- yield* test.advance(CLAIM_LEASE);
59
- expect(yield* logOf("SubSummary", "blocked-first")).toEqual([
60
- "blocked-order#1:OrderPlaced",
61
- ]);
62
- expect(yield* logOf("SubSummary", "blocked-second")).toEqual([
63
- "blocked-order#2:OrderPlaced",
64
- ]);
65
- })),
66
- },
67
- {
68
- name: "retries a defecting delivery with capped backoff and records last_error",
69
- run: ({ expect, environment, fixture }) => run(environment, fixture, Effect.gen(function* () {
70
- const test = yield* ActorTest;
71
- yield* (yield* SubFollower.get("poison-follower")).Follow({ source: "poison-order" });
72
- yield* drain;
73
- fixture.behave = (entry) => entry.startsWith("SubFollower/poison-follower/") ? "defect" : "apply";
74
- yield* (yield* SubOrder.get("poison-order")).Place({ customerId: "p", amount: 1 });
75
- yield* drain;
76
- for (let attempt = 1; attempt <= 3; attempt++) {
77
- const [row] = yield* sourceRows("poison-order");
78
- expect(row).toMatchObject({ attempts: attempt, delivered: "0", due: true });
79
- expect(row.last_error?.includes("Handler defect on poison-order#1")).toBe(true);
80
- yield* test.advance(CLAIM_LEASE);
81
- }
82
- expect(handlerRuns(fixture, "SubFollower/poison-follower")).toBe(4);
83
- expect(yield* followerLog("poison-follower")).toEqual([]);
84
- fixture.behave = () => "apply";
85
- yield* test.advance("300 seconds");
86
- expect(yield* followerLog("poison-follower")).toEqual(["poison-order#1:OrderPlaced"]);
87
- expect(yield* sourceRows("poison-order")).toMatchObject([
88
- { attempts: 0, last_error: null, delivered: "1" },
89
- ]);
90
- })),
91
- },
92
- {
93
- name: "backs a routed row off with last_error when route returns an id the key schema rejects",
94
- run: ({ expect, environment, fixture }) => run(environment, fixture, Effect.gen(function* () {
95
- const test = yield* ActorTest;
96
- const order = yield* SubOrder.get("badroute-order");
97
- yield* order.Place({ customerId: "", amount: 1 });
98
- yield* order.Place({ customerId: "badroute-ok", amount: 1 });
99
- yield* drain;
100
- const [summary] = yield* sourceRows("badroute-order", "SubSummary");
101
- expect(summary.delivered).toBe("0");
102
- expect(summary.last_error?.startsWith("Route failed")).toBe(true);
103
- expect(yield* logOf("SubSummary", "badroute-ok")).toEqual([]);
104
- yield* test.advance(CLAIM_LEASE);
105
- expect(yield* logOf("SubSummary", "badroute-ok")).toEqual([]);
106
- })),
107
- },
108
- ];
@@ -1,4 +0,0 @@
1
- import type { ConformanceCase } from "../../conformance.ts";
2
- import { type SubscriptionsFixture } from "./actors.ts";
3
- /** Feed rows, the tag summary, and wake-ups of event subscriptions. */
4
- export declare const subscriptionFeedConformance: ReadonlyArray<ConformanceCase<SubscriptionsFixture>>;
@@ -1,218 +0,0 @@
1
- import { Deferred, Effect, Fiber, Schema } from "effect";
2
- import { SqlClient } from "effect/sql";
3
- import { ActorTest } from "../../actor-test.js";
4
- import { CLAIM_LEASE, ExplainOutput, planNodes } from "../outbox.js";
5
- import { SubFollower, SubOrder } from "./actors.js";
6
- import { crashOnce, drain, followerLog, handlerRuns, outboxOf, query, run, sourceRows, tagMismatches, } from "./harness.js";
7
- /** Feed rows, the tag summary, and wake-ups of event subscriptions. */
8
- export const subscriptionFeedConformance = [
9
- {
10
- name: "reactivates a subscription over its tombstone, so the source's next event is delivered",
11
- run: ({ expect, environment, fixture }) => run(environment, fixture, Effect.gen(function* () {
12
- const follower = yield* SubFollower.get("revive-follower");
13
- yield* follower.Follow({ source: "revive-order" });
14
- yield* drain;
15
- yield* follower.Unfollow("revive-order");
16
- yield* drain;
17
- expect(yield* sourceRows("revive-order")).toMatchObject([
18
- { subscriber_id: "revive-follower", epoch: "2", active: false, due: false },
19
- ]);
20
- expect(yield* tagMismatches).toEqual([]);
21
- yield* follower.Follow({ source: "revive-order" });
22
- yield* drain;
23
- yield* (yield* SubOrder.get("revive-order")).Place({ customerId: "r", amount: 1 });
24
- yield* drain;
25
- expect(yield* followerLog("revive-follower")).toEqual(["revive-order#1:OrderPlaced"]);
26
- expect(yield* sourceRows("revive-order")).toMatchObject([
27
- { subscriber_id: "revive-follower", epoch: "3", active: true, delivered: "1" },
28
- ]);
29
- expect(yield* tagMismatches).toEqual([]);
30
- })),
31
- },
32
- {
33
- name: "tombstones a caught-up row and delivers Rejected when a resubscribe names a cursor above the source's head",
34
- run: ({ expect, environment, fixture }) => run(environment, fixture, Effect.gen(function* () {
35
- const follower = yield* SubFollower.get("above-follower");
36
- const order = yield* SubOrder.get("above-order");
37
- yield* follower.Follow({ source: "above-order" });
38
- yield* drain;
39
- yield* order.Place({ customerId: "a", amount: 1 });
40
- yield* drain;
41
- expect(yield* sourceRows("above-order")).toMatchObject([
42
- { epoch: "1", active: true, delivered: "1", due: false },
43
- ]);
44
- yield* follower.Follow({ source: "above-order", from: "9" });
45
- yield* drain;
46
- yield* order.Place({ customerId: "a", amount: 2 });
47
- yield* drain;
48
- expect(yield* followerLog("above-follower")).toEqual([
49
- "above-order#1:OrderPlaced",
50
- "above-order!rejected:9",
51
- ]);
52
- expect(yield* sourceRows("above-order")).toMatchObject([
53
- { subscriber_id: "above-follower", epoch: "2", active: false, due: false },
54
- ]);
55
- expect(yield* tagMismatches).toEqual([]);
56
- })),
57
- },
58
- {
59
- name: "expands a feed row once its lease ends when the relay dies after claiming it",
60
- run: ({ expect, environment, fixture }) => run(environment, fixture, Effect.gen(function* () {
61
- const test = yield* ActorTest;
62
- yield* (yield* SubFollower.get("feeddie-follower")).Follow({ source: "feeddie-order" });
63
- yield* drain;
64
- const crash = crashOnce(fixture, "afterClaim", (request) => request.command === "$feed" && request.ref.id === "feeddie-order");
65
- yield* (yield* SubOrder.get("feeddie-order")).Place({ customerId: "f", amount: 1 });
66
- yield* drain;
67
- expect(crash.crashed).toBe(true);
68
- expect(yield* followerLog("feeddie-follower")).toEqual([]);
69
- expect(yield* outboxOf("SubOrder", "feeddie-order", "feed")).toBe(1);
70
- yield* test.advance(CLAIM_LEASE);
71
- expect(yield* followerLog("feeddie-follower")).toEqual(["feeddie-order#1:OrderPlaced"]);
72
- expect(handlerRuns(fixture, "SubFollower/feeddie-follower")).toBe(1);
73
- expect(yield* outboxOf("SubOrder", "feeddie-order", "feed")).toBe(0);
74
- })),
75
- },
76
- {
77
- name: "writes one feed row per publishing turn whatever the subscriber count",
78
- run: ({ expect, environment, fixture }) => run(environment, fixture, Effect.gen(function* () {
79
- const test = yield* ActorTest;
80
- for (const [source, followers] of [
81
- ["feed-one", 1],
82
- ["feed-many", 12],
83
- ]) {
84
- for (let index = 0; index < followers; index++)
85
- yield* (yield* SubFollower.get(`${source}-f${index}`)).Follow({ source });
86
- yield* drain;
87
- const pause = yield* test.pauseNext("afterClaim");
88
- yield* (yield* SubOrder.get(source)).PlaceMany({ customerId: "f", count: 3 });
89
- const draining = yield* drain.pipe(Effect.forkChild);
90
- yield* pause.reached;
91
- expect(yield* outboxOf("SubOrder", source, "feed")).toBe(1);
92
- expect((yield* test.inspect({ tenant: test.tenant, actor: "SubOrder", id: source })).outbox).toBe(0);
93
- yield* pause.release;
94
- yield* Fiber.join(draining);
95
- expect(yield* outboxOf("SubOrder", source, "feed")).toBe(0);
96
- for (let index = 0; index < followers; index++)
97
- expect((yield* followerLog(`${source}-f${index}`)).length).toBe(3);
98
- }
99
- })),
100
- },
101
- {
102
- name: "writes no feed row for an actor with no subscriptions",
103
- run: ({ expect, environment, fixture }) => run(environment, fixture, Effect.gen(function* () {
104
- yield* (yield* SubOrder.get("quiet-order")).Note("nobody listens");
105
- expect(yield* outboxOf("SubOrder", "quiet-order", "feed")).toBe(0);
106
- expect(yield* sourceRows("quiet-order")).toEqual([]);
107
- })),
108
- },
109
- {
110
- name: "probes the tag summary by key with 10^5 non-matching rows",
111
- requiresIndependentConnections: true,
112
- timeoutMs: 120_000,
113
- run: ({ expect, environment, fixture }) => run(environment, fixture, Effect.gen(function* () {
114
- const test = yield* ActorTest;
115
- const sql = yield* SqlClient.SqlClient;
116
- const routingKey = "1";
117
- yield* sql `INSERT INTO actor_generations (routing_key, tenant_id, actor_type, actor_id)
118
- SELECT ${routingKey}::bigint, ${test.tenant}, 'SubProbe', 'p' || n
119
- FROM generate_series(1, 100000) AS n`.pipe(Effect.orDie);
120
- yield* sql `INSERT INTO actor_subscription_tags (routing_key, tenant_id, source_type, source_id, event, rows)
121
- SELECT ${routingKey}::bigint, ${test.tenant}, 'SubProbe', 'p' || n, 'OrderPlaced', 1
122
- FROM generate_series(1, 100000) AS n`.pipe(Effect.orDie);
123
- yield* sql `ANALYZE actor_subscription_tags`.pipe(Effect.orDie);
124
- const [row] = yield* sql `EXPLAIN (ANALYZE, BUFFERS, FORMAT JSON)
125
- SELECT 1 FROM actor_subscription_tags t
126
- WHERE t.routing_key = ${routingKey}::bigint AND t.tenant_id = ${test.tenant}
127
- AND t.source_type = 'SubProbe' AND t.source_id = 'missing' AND t.event IN ('OrderPlaced', 'OrderCancelled')`.pipe(Effect.orDie);
128
- const [explained] = yield* Schema.decodeUnknownEffect(ExplainOutput)(row["QUERY PLAN"]).pipe(Effect.orDie);
129
- const nodes = planNodes(explained.Plan);
130
- expect(nodes.some((node) => node["Index Name"] === "actor_subscription_tags_pkey")).toBe(true);
131
- expect(nodes.some((node) => node["Node Type"] === "Seq Scan")).toBe(false);
132
- expect(explained.Plan["Actual Rows"]).toBe(0);
133
- expect(nodes.reduce((sum, node) => sum + node["Shared Hit Blocks"] + node["Shared Read Blocks"], 0) < 16).toBe(true);
134
- yield* sql `DELETE FROM actor_subscription_tags WHERE source_type = 'SubProbe'`.pipe(Effect.orDie);
135
- yield* sql `DELETE FROM actor_generations WHERE actor_type = 'SubProbe'`.pipe(Effect.orDie);
136
- })),
137
- },
138
- {
139
- name: "leases the rows an expansion makes due and starts their delivery without a claim pass",
140
- run: ({ expect, environment, fixture }) => run(environment, fixture, Effect.gen(function* () {
141
- yield* (yield* SubFollower.get("lease-follower")).Follow({ source: "lease-order" });
142
- yield* drain;
143
- const order = [];
144
- const claimed = yield* Deferred.make();
145
- fixture.hook = (point, request) => {
146
- if (point === "afterClaim" && request.commandId === "lease-follower") {
147
- order.push("delivery");
148
- return Deferred.succeed(claimed, undefined).pipe(Effect.asVoid);
149
- }
150
- if (point === "afterExpand" && request.ref.id === "lease-order")
151
- return Deferred.await(claimed).pipe(Effect.timeout("2 seconds"), Effect.ignore, Effect.andThen(Effect.sync(() => order.push("expanded"))));
152
- return Effect.void;
153
- };
154
- yield* (yield* SubOrder.get("lease-order")).Place({ customerId: "l", amount: 1 });
155
- yield* drain;
156
- expect(order).toEqual(["delivery", "expanded"]);
157
- expect(yield* followerLog("lease-follower")).toEqual(["lease-order#1:OrderPlaced"]);
158
- expect(yield* sourceRows("lease-order")).toMatchObject([
159
- { delivered: "1", due: false, attempts: 0 },
160
- ]);
161
- })),
162
- },
163
- {
164
- name: "loses no wake when a commit races a settle or an expansion",
165
- run: ({ expect, environment, fixture }) => run(environment, fixture, Effect.gen(function* () {
166
- const test = yield* ActorTest;
167
- const order = yield* SubOrder.get("race-order");
168
- yield* (yield* SubFollower.get("race-follower")).Follow({ source: "race-order" });
169
- yield* drain;
170
- const pause = yield* test.pauseNext("afterSettleSnapshot");
171
- yield* order.Place({ customerId: "r", amount: 1 });
172
- const draining = yield* drain.pipe(Effect.forkChild);
173
- yield* pause.reached;
174
- yield* order.Place({ customerId: "r", amount: 2 });
175
- for (;;) {
176
- if ((yield* outboxOf("SubOrder", "race-order", "feed")) === 0)
177
- break;
178
- yield* Effect.sleep("20 millis");
179
- }
180
- yield* pause.release;
181
- yield* Fiber.join(draining);
182
- yield* drain;
183
- expect(yield* followerLog("race-follower")).toEqual([
184
- "race-order#1:OrderPlaced",
185
- "race-order#2:OrderPlaced",
186
- ]);
187
- expect(yield* sourceRows("race-order")).toMatchObject([{ delivered: "2", due: false }]);
188
- })),
189
- },
190
- {
191
- name: "keeps a backing-off row's due time when new commits expand the feed",
192
- run: ({ expect, environment, fixture }) => run(environment, fixture, Effect.gen(function* () {
193
- const test = yield* ActorTest;
194
- const order = yield* SubOrder.get("backoff-order");
195
- yield* (yield* SubFollower.get("backoff-follower")).Follow({ source: "backoff-order" });
196
- yield* drain;
197
- fixture.behave = (entry) => entry.startsWith("SubFollower/backoff-follower/") ? "defect" : "apply";
198
- yield* order.Place({ customerId: "b", amount: 1 });
199
- yield* drain;
200
- const due = () => query((sql) => sql `SELECT due_at_ms::text AS due_at_ms
201
- FROM actor_subscriptions WHERE tenant_id = ${test.tenant}
202
- AND source_id = 'backoff-order' AND subscriber_id = 'backoff-follower'`).pipe(Effect.map((rows) => rows[0].due_at_ms));
203
- const backingOff = yield* due();
204
- yield* order.Place({ customerId: "b", amount: 2 });
205
- yield* drain;
206
- expect(yield* due()).toBe(backingOff);
207
- const [backedOff] = yield* sourceRows("backoff-order");
208
- expect(backedOff).toMatchObject({ delivered: "0", attempts: 1 });
209
- expect(backedOff.last_error?.includes("Handler defect")).toBe(true);
210
- fixture.behave = () => "apply";
211
- yield* test.advance(CLAIM_LEASE);
212
- expect(yield* followerLog("backoff-follower")).toEqual([
213
- "backoff-order#1:OrderPlaced",
214
- "backoff-order#2:OrderPlaced",
215
- ]);
216
- })),
217
- },
218
- ];
@@ -1,124 +0,0 @@
1
- import { Effect, Schema } from "effect";
2
- import { SqlClient, type SqlError } from "effect/sql";
3
- import { InternalActors } from "../../../runtime/actors.ts";
4
- import { Request } from "../../../runtime/request.ts";
5
- import { type TurnPoint } from "../../../runtime/turn/hooks.ts";
6
- import { ActorTest } from "../../actor-test.ts";
7
- import type { ConformanceEnvironment, ConformanceServices } from "../../conformance.ts";
8
- import { type SubscriptionsFixture } from "./actors.ts";
9
- export declare const LogState: Schema.Struct<{
10
- readonly log: Schema.optional<Schema.$Array<Schema.String>>;
11
- }>;
12
- export declare const logOf: (actor: string, id: string) => Effect.Effect<readonly string[], never, ActorTest>;
13
- export declare const query: <A>(statement: (sql: SqlClient.SqlClient) => Effect.Effect<A, SqlError.SqlError>) => Effect.Effect<A, never, SqlClient.SqlClient>;
14
- /** The source-side rows of one order in the test tenant, of one subscriber type. */
15
- export declare const sourceRows: (sourceId: string, subscriberType?: string) => Effect.Effect<readonly {
16
- subscriber_type: string;
17
- subscription: string;
18
- subscriber_id: string;
19
- epoch: string;
20
- active: boolean;
21
- delivered: string;
22
- due: boolean;
23
- attempts: number;
24
- last_error: string | null;
25
- }[], never, ActorTest | SqlClient.SqlClient>;
26
- /** The subscriber-side cursor rows of one follower in the test tenant. */
27
- export declare const cursorRows: (actor: string, id: string) => Effect.Effect<readonly {
28
- subscription: string;
29
- source_id: string;
30
- epoch: string;
31
- active: boolean;
32
- applied: string;
33
- }[], never, ActorTest | SqlClient.SqlClient>;
34
- /** Outbox rows of one kind an actor of the test tenant holds. */
35
- export declare const outboxOf: (actor: string, id: string, kind: "feed" | "control") => Effect.Effect<number, never, ActorTest | SqlClient.SqlClient>;
36
- /**
37
- * Tag summary rows that disagree with the active rows carrying each tag. A
38
- * missed increment loses wakes, and a missed decrement costs feed writes forever.
39
- */
40
- export declare const tagMismatches: Effect.Effect<readonly {
41
- event: string;
42
- counted: number | null;
43
- summary: number | null;
44
- }[], never, SqlClient.SqlClient>;
45
- export declare const drain: Effect.Effect<void, never, ActorTest>;
46
- /** Makes the first `point` that `match` accepts die, as a crash there would; later ones pass. */
47
- export declare const crashOnce: (fixture: SubscriptionsFixture, point: TurnPoint, match: (request: Request) => boolean) => {
48
- crashed: boolean;
49
- };
50
- /** Holds the first `point` that `match` accepts until `release`. */
51
- export declare const pauseOnce: (fixture: SubscriptionsFixture, point: TurnPoint, match: (request: Request) => boolean) => Effect.Effect<{
52
- reached: Effect.Effect<void, never, never>;
53
- release: Effect.Effect<void, never, never>;
54
- }, never, never>;
55
- /** A fault point of one subscription row's work: its tag and its subscriber, or the delivery command. */
56
- export declare const subscriber: (id: string) => (request: Request) => boolean;
57
- /** A follower's committed log, as entries of one source. */
58
- export declare const followerLog: (id: string) => Effect.Effect<readonly string[], never, ActorTest>;
59
- export declare const handlerRuns: (fixture: SubscriptionsFixture, prefix: string) => number;
60
- /** Builds a relay delivery request, as a runner would, for cases that play a stale runner. */
61
- export declare const deliveryRequest: (options: {
62
- readonly subscriber: string;
63
- readonly source: string;
64
- readonly epoch: string;
65
- readonly cursor: string;
66
- /** Re-encodes the delivery with a field a newer schema added. */
67
- readonly extra?: boolean;
68
- /** The subscriber type, its subscription, its handler, and the source type; `SubFollower`'s `FollowedOrders` of `SubOrder` by default. */
69
- readonly route?: {
70
- readonly actor: string;
71
- readonly subscription: string;
72
- readonly command: string;
73
- readonly source: string;
74
- };
75
- }) => Effect.Effect<{
76
- readonly ref: {
77
- readonly tenant: string;
78
- readonly actor: string;
79
- readonly id: string;
80
- };
81
- readonly caller: {
82
- readonly _tag: "Anonymous";
83
- } | {
84
- readonly _tag: "System";
85
- readonly source: "actor" | "cron" | "job" | "process" | "subscription" | "timer" | "workflow";
86
- readonly ref?: {
87
- readonly tenant: string;
88
- readonly actor: string;
89
- readonly id: string;
90
- } | undefined;
91
- readonly onBehalfOf?: {
92
- readonly subject: string;
93
- } | undefined;
94
- readonly mint?: {
95
- readonly commandId: string;
96
- readonly ordinal: number;
97
- } | undefined;
98
- } | {
99
- readonly _tag: "User";
100
- readonly subject: string;
101
- };
102
- readonly command: string;
103
- readonly commandId: string;
104
- readonly payload: string;
105
- readonly external?: boolean | undefined;
106
- readonly clockOffset?: number | undefined;
107
- readonly redelivered?: boolean | undefined;
108
- readonly intent?: {
109
- readonly tenant: string;
110
- readonly actor: string;
111
- readonly id: string;
112
- } | undefined;
113
- readonly delivery?: {
114
- readonly subscription: string;
115
- readonly sourceType: string;
116
- readonly sourceId: string;
117
- readonly epoch: string;
118
- readonly kind: "event" | "gap" | "rejected";
119
- readonly position: string;
120
- } | undefined;
121
- readonly queuedAtMs?: number | undefined;
122
- readonly usageToken?: string | undefined;
123
- }, Schema.SchemaError, ActorTest | InternalActors | SqlClient.SqlClient>;
124
- export declare const run: <A, E>(environment: ConformanceEnvironment, fixture: SubscriptionsFixture, body: Effect.Effect<A, E, ConformanceServices>) => Promise<A>;
@@ -1,143 +0,0 @@
1
- import { DateTime, Deferred, Effect, Schema } from "effect";
2
- import { SqlClient } from "effect/sql";
3
- import { InternalActors } from "../../../runtime/actors.js";
4
- import { Request } from "../../../runtime/request.js";
5
- import { System } from "../../../identity/caller.js";
6
- import { deliveryCommandId } from "../../../runtime/subscriptions/identity.js";
7
- import { RetryTurn } from "../../../runtime/turn/hooks.js";
8
- import { ActorTest } from "../../actor-test.js";
9
- import { OrderDelivery, OrderPlaced, reset } from "./actors.js";
10
- export const LogState = Schema.Struct({ log: Schema.optional(Schema.Array(Schema.String)) });
11
- export const logOf = Effect.fnUntraced(function* (actor, id) {
12
- const test = yield* ActorTest;
13
- const { state } = yield* test.inspect({ tenant: test.tenant, actor, id });
14
- return (yield* Schema.decodeUnknownEffect(LogState)(state).pipe(Effect.orDie)).log ?? [];
15
- });
16
- export const query = (statement) => Effect.gen(function* () {
17
- return yield* statement(yield* SqlClient.SqlClient);
18
- }).pipe(Effect.orDie);
19
- /** The source-side rows of one order in the test tenant, of one subscriber type. */
20
- export const sourceRows = (sourceId, subscriberType = "SubFollower") => Effect.gen(function* () {
21
- const test = yield* ActorTest;
22
- return yield* query((sql) => sql `SELECT subscriber_type, subscription, subscriber_id, epoch::text AS epoch, active,
23
- delivered::text AS delivered, due_at_ms IS NOT NULL AS due, attempts, last_error
24
- FROM actor_subscriptions WHERE tenant_id = ${test.tenant} AND source_type = 'SubOrder'
25
- AND source_id = ${sourceId} AND subscriber_type = ${subscriberType}
26
- ORDER BY subscription, subscriber_id`);
27
- });
28
- /** The subscriber-side cursor rows of one follower in the test tenant. */
29
- export const cursorRows = (actor, id) => Effect.gen(function* () {
30
- const test = yield* ActorTest;
31
- return yield* query((sql) => sql `SELECT subscription, source_id, epoch::text AS epoch, active, applied::text AS applied
32
- FROM actor_subscription_cursors WHERE tenant_id = ${test.tenant} AND actor_type = ${actor}
33
- AND actor_id = ${id}
34
- ORDER BY subscription, source_id`);
35
- });
36
- /** Outbox rows of one kind an actor of the test tenant holds. */
37
- export const outboxOf = (actor, id, kind) => Effect.gen(function* () {
38
- const test = yield* ActorTest;
39
- return (yield* query((sql) => sql `SELECT count(*)::int AS count FROM actor_outbox
40
- WHERE tenant_id = ${test.tenant} AND actor_type = ${actor} AND actor_id = ${id}
41
- AND kind = ${kind}`))[0].count;
42
- });
43
- /**
44
- * Tag summary rows that disagree with the active rows carrying each tag. A
45
- * missed increment loses wakes, and a missed decrement costs feed writes forever.
46
- */
47
- export const tagMismatches = query((sql) => sql `
48
- SELECT event, a.rows AS counted, t.rows AS summary FROM (
49
- SELECT routing_key, tenant_id, source_type, source_id, x.tag AS event, count(*)::int AS rows
50
- FROM actor_subscriptions, unnest(events) AS x(tag)
51
- WHERE active GROUP BY routing_key, tenant_id, source_type, source_id, x.tag
52
- ) a FULL JOIN actor_subscription_tags t USING (routing_key, tenant_id, source_type, source_id, event)
53
- WHERE a.rows IS DISTINCT FROM t.rows`);
54
- export const drain = ActorTest.use((test) => test.advance(0));
55
- /** Makes the first `point` that `match` accepts die, as a crash there would; later ones pass. */
56
- export const crashOnce = (fixture, point, match) => {
57
- const state = { crashed: false };
58
- fixture.hook = (reached, request) => {
59
- if (state.crashed || reached !== point || !match(request))
60
- return Effect.void;
61
- state.crashed = true;
62
- return Effect.die(RetryTurn.make({ message: `Injected ${point} crash` }));
63
- };
64
- return state;
65
- };
66
- /** Holds the first `point` that `match` accepts until `release`. */
67
- export const pauseOnce = Effect.fnUntraced(function* (fixture, point, match) {
68
- const reached = yield* Deferred.make();
69
- const release = yield* Deferred.make();
70
- let paused = false;
71
- fixture.hook = (at, request) => {
72
- if (paused || at !== point || !match(request))
73
- return Effect.void;
74
- paused = true;
75
- return Deferred.succeed(reached, undefined).pipe(Effect.andThen(Deferred.await(release)));
76
- };
77
- return {
78
- reached: Deferred.await(reached),
79
- release: Deferred.succeed(release, undefined).pipe(Effect.asVoid),
80
- };
81
- });
82
- /** A fault point of one subscription row's work: its tag and its subscriber, or the delivery command. */
83
- export const subscriber = (id) => (request) => request.commandId === id || request.ref.id === id;
84
- /** A follower's committed log, as entries of one source. */
85
- export const followerLog = (id) => logOf("SubFollower", id);
86
- export const handlerRuns = (fixture, prefix) => fixture.runs.filter((run) => run.startsWith(prefix)).length;
87
- const DeliveredOrder = OrderDelivery.members[0];
88
- const encodeDelivery = Schema.encodeEffect(Schema.fromJsonString(Schema.toCodecJson(Schema.Struct({ value: OrderDelivery }))));
89
- const encodeWithExtra = Schema.encodeEffect(Schema.fromJsonString(Schema.toCodecJson(Schema.Struct({ value: OrderDelivery, extra: Schema.Boolean }))));
90
- /** Builds a relay delivery request, as a runner would, for cases that play a stale runner. */
91
- export const deliveryRequest = Effect.fnUntraced(function* (options) {
92
- const test = yield* ActorTest;
93
- const internal = yield* InternalActors;
94
- const route = options.route ?? {
95
- actor: "SubFollower",
96
- subscription: "FollowedOrders",
97
- command: "OnOrder",
98
- source: "SubOrder",
99
- };
100
- const subscriber = { tenant: test.tenant, actor: route.actor, id: options.subscriber };
101
- const source = { tenant: test.tenant, actor: route.source, id: options.source };
102
- const envelope = {
103
- subscription: route.subscription,
104
- sourceType: route.source,
105
- sourceId: options.source,
106
- epoch: options.epoch,
107
- kind: "event",
108
- position: options.cursor,
109
- };
110
- const [event] = yield* query((sql) => sql `
111
- SELECT emitted_at_ms::text AS emitted_at_ms, command_id FROM actor_events
112
- WHERE tenant_id = ${test.tenant} AND actor_type = ${route.source} AND actor_id = ${options.source}
113
- AND sequence = ${options.cursor}`);
114
- const value = DeliveredOrder.make({
115
- subscription: route.subscription,
116
- source,
117
- cursor: options.cursor,
118
- event: OrderPlaced.make({ customerId: "c", amount: 1 }),
119
- commandId: event.command_id,
120
- timestamp: DateTime.makeUnsafe(Number(event.emitted_at_ms)),
121
- });
122
- return Request.make({
123
- ref: subscriber,
124
- caller: System.make({ source: "subscription", ref: source }),
125
- command: route.command,
126
- commandId: yield* deliveryCommandId({
127
- subscriber,
128
- envelope,
129
- issuedAt: Number(event.emitted_at_ms),
130
- retryWindowMs: internal.retryWindowMs,
131
- }),
132
- payload: options.extra === true
133
- ? yield* encodeWithExtra({ value, extra: true })
134
- : yield* encodeDelivery({ value }),
135
- delivery: envelope,
136
- });
137
- });
138
- export const run = (environment, fixture, body) => environment.run(Effect.gen(function* () {
139
- yield* reset(fixture);
140
- const result = yield* body;
141
- yield* reset(fixture);
142
- return result;
143
- }));
@@ -1,4 +0,0 @@
1
- import type { ConformanceCase } from "../../conformance.ts";
2
- import { type SubscriptionsFixture } from "./actors.ts";
3
- /** Operator skip and listing of stuck subscription rows. */
4
- export declare const subscriptionOperatorConformance: ReadonlyArray<ConformanceCase<SubscriptionsFixture>>;