@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,7 +0,0 @@
1
- import type { ConformanceCase } from "../conformance.ts";
2
- /**
3
- * Group commit cases: warm turns of different actors share one transaction,
4
- * and each keeps its own fence, receipt, failure, interruption and statement
5
- * outcome.
6
- */
7
- export declare const groupsConformance: ReadonlyArray<ConformanceCase>;
@@ -1,353 +0,0 @@
1
- import { Cause, Clock, Crypto, Deferred, Duration, Option, Effect, Exit, Fiber, Layer, Redacted, Schedule, Schema, } from "effect";
2
- import { SqlClient } from "effect/sql";
3
- import { Actor, Actors } from "../../index.js";
4
- import { TurnGroupSettings } from "../../runtime/turn/group.js";
5
- import { ActorTest } from "../actor-test.js";
6
- import { transactions } from "./batches.js";
7
- class Refused extends Schema.TaggedError()("GroupRefused", {}) {
8
- }
9
- const Add = Actor.command("Add", { payload: Schema.Finite, success: Schema.Finite });
10
- const Refuse = Actor.command("Refuse", { payload: Schema.Finite, error: Refused });
11
- const Explode = Actor.command("Explode", { payload: Schema.Finite });
12
- /**
13
- * Warm actors without owned tables, so concurrent turns of different ones
14
- * share a group. A short execution timeout lets a case interrupt one member.
15
- */
16
- const Tally = Actor.make("GroupTally", {
17
- key: Schema.String,
18
- state: Actor.state({ count: Schema.Finite.pipe(Schema.withDecodingDefault(Effect.succeed(0))) }),
19
- api: { Add, Refuse, Explode },
20
- policy: { executionTimeout: "2 seconds" },
21
- });
22
- /** Handler runs per actor id. */
23
- const runs = new Map();
24
- const ran = Effect.gen(function* () {
25
- const turn = yield* Tally.Turn;
26
- runs.set(turn.id, (runs.get(turn.id) ?? 0) + 1);
27
- return turn;
28
- });
29
- const tallyLive = Tally.toLayer(Effect.succeed({
30
- Add: Effect.fnUntraced(function* (amount) {
31
- const turn = yield* ran;
32
- yield* turn.state.set({ count: turn.state.count + amount });
33
- return turn.state.count;
34
- }),
35
- Refuse: Effect.fnUntraced(function* (amount) {
36
- const turn = yield* ran;
37
- yield* turn.state.set({ count: turn.state.count + amount });
38
- return yield* Refused.make({});
39
- }),
40
- Explode: Effect.fnUntraced(function* (amount) {
41
- const turn = yield* ran;
42
- yield* turn.state.set({ count: turn.state.count + amount });
43
- return yield* Effect.die(new Error("Group member defect"));
44
- }),
45
- }));
46
- /** Runs `body` on a runner over a fresh database whose closed groups wait `wait` for members. */
47
- const withGroups = (environment, wait, body) => environment.run(Effect.service(Crypto.Crypto)).then((crypto) => Effect.runPromise(Effect.gen(function* () {
48
- yield* Effect.acquireRelease(environment.stop, () => environment.restart);
49
- const database = yield* environment.freshDatabase;
50
- if (!Redacted.isRedacted(database))
51
- return yield* Effect.die(new Error("The group cases need a Postgres database"));
52
- const context = yield* Layer.build(tallyLive.pipe(Layer.provideMerge(ActorTest.layer({ database })), Layer.provide(Layer.succeed(TurnGroupSettings, { wait: Duration.fromInputUnsafe(wait) }))));
53
- return yield* body.pipe(Effect.provideContext(context));
54
- }).pipe(Effect.scoped, Effect.provideService(Crypto.Crypto, crypto))));
55
- /**
56
- * Warms each actor with one `Add(1)`, then sends every call at once and holds
57
- * each turn before its handler until all of them reached it, so they joined
58
- * one group before any member handed over its writes.
59
- */
60
- const together = Effect.fnUntraced(function* (calls) {
61
- const test = yield* ActorTest;
62
- for (const { id } of calls) {
63
- const warm = yield* (yield* Tally.get(id)).Add(1);
64
- if (warm !== 1)
65
- return yield* Effect.die(new Error(`Warming ${id} returned ${warm}`));
66
- }
67
- const pauses = yield* Effect.forEach(calls, ({ commandId }) => test.pauseNext("beforeHandler", { commandId }));
68
- const fibers = yield* Effect.forEach(calls, ({ id, commandId, call }) => Effect.flatMap(Tally.get(id), (tally) => Effect.forkChild(call(tally).pipe(Actor.commandId(commandId), Effect.exit))));
69
- yield* Effect.forEach(pauses, ({ reached }) => reached, { concurrency: "unbounded" });
70
- return { fibers, release: Effect.forEach(pauses, ({ release }) => release, { discard: true }) };
71
- });
72
- const mintAll = Effect.fnUntraced(function* (count) {
73
- const actors = yield* Actors;
74
- return yield* Effect.forEach(Array.from({ length: count }), () => actors.mintCommandId);
75
- });
76
- /** The transaction that committed `commandId` on actor `id`, if it committed. */
77
- const committedIn = Effect.fnUntraced(function* (id, commandId) {
78
- return (yield* transactions((yield* Tally.get(id)).ref)).get(commandId);
79
- });
80
- /**
81
- * Waits until a turn waits for a generation row lock, which only a group
82
- * still holding a departed member's fenced read can hold here.
83
- */
84
- const lockWaiter = Effect.gen(function* () {
85
- const sql = yield* SqlClient.SqlClient;
86
- const [row] = yield* sql `SELECT count(*)::int AS waiting
87
- FROM pg_stat_activity WHERE wait_event_type = 'Lock' AND datname = current_database()`;
88
- if (row.waiting === 0)
89
- return yield* Effect.fail("no lock waiter yet");
90
- }).pipe(Effect.retry(Schedule.spaced("20 millis")), Effect.orDie);
91
- const stateOf = Effect.fnUntraced(function* (id) {
92
- const test = yield* ActorTest;
93
- return (yield* test.inspect((yield* Tally.get(id)).ref)).state;
94
- });
95
- /**
96
- * Group commit cases: warm turns of different actors share one transaction,
97
- * and each keeps its own fence, receipt, failure, interruption and statement
98
- * outcome.
99
- */
100
- export const groupsConformance = [
101
- {
102
- name: "group commit: concurrent warm turns commit in one transaction; a declared failure keeps only its receipt and a defect leaves only itself out",
103
- requiresIndependentConnections: true,
104
- requiresFreshDatabase: true,
105
- timeoutMs: 60_000,
106
- run: ({ expect, environment }) => withGroups(environment, "10 seconds", Effect.gen(function* () {
107
- const [a, b, refused, exploded, e] = yield* mintAll(5);
108
- const ids = ["one", "two", "refused", "exploded", "five"].map((id) => `group-${id}`);
109
- const { fibers, release } = yield* together([
110
- { id: ids[0], commandId: a, call: (tally) => tally.Add(10) },
111
- { id: ids[1], commandId: b, call: (tally) => tally.Add(20) },
112
- { id: ids[2], commandId: refused, call: (tally) => tally.Refuse(30) },
113
- { id: ids[3], commandId: exploded, call: (tally) => tally.Explode(40) },
114
- { id: ids[4], commandId: e, call: (tally) => tally.Add(50) },
115
- ]);
116
- runs.clear();
117
- yield* release;
118
- const [one, two, refusal, defect, five] = yield* Effect.forEach(fibers, Fiber.join);
119
- expect([one, two, five]).toEqual([Exit.succeed(11), Exit.succeed(21), Exit.succeed(51)]);
120
- expect(Exit.isFailure(refusal) && Cause.squash(refusal.cause)).toBeInstanceOf(Refused);
121
- expect(Exit.isFailure(defect) && Cause.hasDies(defect.cause)).toBe(true);
122
- const shared = yield* committedIn(ids[0], a);
123
- expect(shared).not.toBe(undefined);
124
- expect(yield* committedIn(ids[1], b)).toBe(shared);
125
- expect(yield* committedIn(ids[2], refused)).toBe(shared);
126
- expect(yield* committedIn(ids[4], e)).toBe(shared);
127
- expect(yield* committedIn(ids[3], exploded)).toBe(undefined);
128
- expect(yield* stateOf(ids[2])).toEqual({ count: 1 });
129
- expect(yield* stateOf(ids[3])).toEqual({ count: 1 });
130
- expect(ids.map((id) => runs.get(id))).toEqual([1, 1, 1, 1, 1]);
131
- })),
132
- },
133
- {
134
- name: "group commit: a member fenced by a newer generation leaves its group before its handler runs, runs again alone, and its neighbours commit together",
135
- requiresIndependentConnections: true,
136
- requiresFreshDatabase: true,
137
- timeoutMs: 60_000,
138
- run: ({ expect, environment }) => withGroups(environment, "10 seconds", Effect.gen(function* () {
139
- const sql = yield* SqlClient.SqlClient;
140
- const test = yield* ActorTest;
141
- const [a, fenced, c] = yield* mintAll(3);
142
- const ids = ["group-left", "group-fenced", "group-right"];
143
- for (const id of ids)
144
- expect(yield* (yield* Tally.get(id)).Add(1)).toBe(1);
145
- yield* sql `UPDATE actor_generations SET generation = generation + 1
146
- WHERE actor_type = 'GroupTally' AND actor_id = ${ids[1]}`;
147
- const pauses = yield* Effect.forEach([a, c], (commandId) => test.pauseNext("beforeHandler", { commandId }));
148
- runs.clear();
149
- const fibers = yield* Effect.forEach([
150
- [ids[0], a],
151
- [ids[1], fenced],
152
- [ids[2], c],
153
- ], ([id, commandId]) => Effect.flatMap(Tally.get(id), (tally) => Effect.forkChild(tally.Add(1).pipe(Actor.commandId(commandId)))));
154
- yield* Effect.forEach(pauses, ({ reached }) => reached, { concurrency: "unbounded" });
155
- yield* lockWaiter;
156
- expect(runs.size).toBe(0);
157
- yield* Effect.forEach(pauses, ({ release }) => release, { discard: true });
158
- expect(yield* Effect.forEach(fibers, Fiber.join)).toEqual([2, 2, 2]);
159
- const shared = yield* committedIn(ids[0], a);
160
- expect(yield* committedIn(ids[2], c)).toBe(shared);
161
- expect(yield* committedIn(ids[1], fenced)).not.toBe(shared);
162
- expect(ids.map((id) => runs.get(id))).toEqual([1, 1, 1]);
163
- expect(yield* test.receiptsFor((yield* Tally.get(ids[1])).ref, "Add")).toBe(2);
164
- })),
165
- },
166
- {
167
- name: "group commit: a member interrupted after handing over its writes is withdrawn, and the group commits its neighbour",
168
- requiresIndependentConnections: true,
169
- requiresFreshDatabase: true,
170
- timeoutMs: 60_000,
171
- run: ({ expect, environment }) => withGroups(environment, "30 seconds", Effect.gen(function* () {
172
- const test = yield* ActorTest;
173
- const [early, late] = yield* mintAll(2);
174
- const ids = ["group-early", "group-late"];
175
- for (const id of ids)
176
- expect(yield* (yield* Tally.get(id)).Add(1)).toBe(1);
177
- const lateHeld = yield* test.pauseNext("beforeHandler", { commandId: late });
178
- const earlyHeld = yield* test.pauseNext("beforeHandler", { commandId: early });
179
- runs.clear();
180
- const earlyCall = yield* Effect.forkChild((yield* Tally.get(ids[0])).Add(10).pipe(Actor.commandId(early)));
181
- yield* earlyHeld.reached;
182
- yield* Effect.sleep("1 second");
183
- const lateCall = yield* Effect.forkChild((yield* Tally.get(ids[1])).Add(20).pipe(Actor.commandId(late)));
184
- yield* lateHeld.reached;
185
- yield* earlyHeld.release;
186
- yield* lockWaiter;
187
- expect(runs.get(ids[0])).toBe(1);
188
- expect(yield* committedIn(ids[0], early)).toBe(undefined);
189
- expect(yield* stateOf(ids[0])).toEqual({ count: 1 });
190
- yield* lateHeld.release;
191
- expect(yield* Fiber.join(lateCall)).toBe(21);
192
- expect(yield* Fiber.join(earlyCall)).toBe(11);
193
- expect(runs.get(ids[0])).toBe(2);
194
- expect(runs.get(ids[1])).toBe(1);
195
- expect(yield* committedIn(ids[0], early)).not.toBe(yield* committedIn(ids[1], late));
196
- expect(yield* stateOf(ids[0])).toEqual({ count: 11 });
197
- })),
198
- },
199
- {
200
- name: "group commit: a member still running when the group's wait ends is evicted, runs again alone, and commits once",
201
- requiresIndependentConnections: true,
202
- requiresFreshDatabase: true,
203
- timeoutMs: 60_000,
204
- run: ({ expect, environment }) => withGroups(environment, "50 millis", Effect.gen(function* () {
205
- const test = yield* ActorTest;
206
- const [quick, slow] = yield* mintAll(2);
207
- const ids = ["group-quick", "group-slow"];
208
- const { fibers, release } = yield* together([
209
- { id: ids[0], commandId: quick, call: (tally) => tally.Add(10) },
210
- { id: ids[1], commandId: slow, call: (tally) => tally.Add(20) },
211
- ]);
212
- const slowHeld = yield* test.pauseNext("beforeCommit", { commandId: slow });
213
- runs.clear();
214
- yield* release;
215
- yield* slowHeld.reached;
216
- expect(yield* Fiber.join(fibers[0])).toEqual(Exit.succeed(11));
217
- expect(yield* committedIn(ids[1], slow)).toBe(undefined);
218
- yield* Effect.sleep("200 millis");
219
- yield* slowHeld.release;
220
- expect(yield* Fiber.join(fibers[1])).toEqual(Exit.succeed(21));
221
- expect(runs.get(ids[0])).toBe(1);
222
- expect(runs.get(ids[1])).toBe(2);
223
- expect(yield* committedIn(ids[1], slow)).not.toBe(yield* committedIn(ids[0], quick));
224
- expect(yield* test.receiptsFor((yield* Tally.get(ids[1])).ref, "Add")).toBe(2);
225
- expect(yield* stateOf(ids[1])).toEqual({ count: 21 });
226
- })),
227
- },
228
- {
229
- name: "group commit: a statement error in one member's writes rolls the group back; that member fails and its neighbours commit alone, once each",
230
- requiresIndependentConnections: true,
231
- requiresFreshDatabase: true,
232
- timeoutMs: 60_000,
233
- run: ({ expect, environment }) => withGroups(environment, "10 seconds", Effect.gen(function* () {
234
- const sql = yield* SqlClient.SqlClient;
235
- const [poisoned, b, c] = yield* mintAll(3);
236
- const ids = ["group-poisoned", "group-b", "group-c"];
237
- yield* sql.unsafe(`CREATE FUNCTION group_poison() RETURNS trigger LANGUAGE plpgsql AS $$
238
- BEGIN
239
- IF NEW.command_id = '${poisoned}' THEN RAISE EXCEPTION 'poisoned receipt'; END IF;
240
- RETURN NEW;
241
- END $$`);
242
- yield* sql.unsafe(`CREATE TRIGGER group_poison BEFORE INSERT ON actor_receipts
243
- FOR EACH ROW EXECUTE FUNCTION group_poison()`);
244
- const { fibers, release } = yield* together([
245
- { id: ids[0], commandId: poisoned, call: (tally) => tally.Add(10) },
246
- { id: ids[1], commandId: b, call: (tally) => tally.Add(20) },
247
- { id: ids[2], commandId: c, call: (tally) => tally.Add(30) },
248
- ]);
249
- runs.clear();
250
- yield* release;
251
- const [failed, second, third] = yield* Effect.forEach(fibers, Fiber.join);
252
- expect(Exit.isFailure(failed) && Cause.hasDies(failed.cause)).toBe(true);
253
- expect([second, third]).toEqual([Exit.succeed(21), Exit.succeed(31)]);
254
- expect(runs.get(ids[1])).toBe(2);
255
- expect(runs.get(ids[2])).toBe(2);
256
- expect(yield* committedIn(ids[0], poisoned)).toBe(undefined);
257
- expect(yield* committedIn(ids[1], b)).not.toBe(yield* committedIn(ids[2], c));
258
- expect(yield* stateOf(ids[0])).toEqual({ count: 1 });
259
- expect(yield* stateOf(ids[1])).toEqual({ count: 21 });
260
- })),
261
- },
262
- {
263
- name: "group commit: a member whose next batch rides behind the COMMIT, interrupted while that COMMIT runs, never gets the session back with its chained transaction open",
264
- requiresIndependentConnections: true,
265
- requiresFreshDatabase: true,
266
- timeoutMs: 60_000,
267
- run: ({ expect, environment }) => withGroups(environment, "30 seconds", Effect.gen(function* () {
268
- const sql = yield* SqlClient.SqlClient;
269
- const test = yield* ActorTest;
270
- const [a1, a2, b1] = yield* mintAll(3);
271
- const ids = ["group-handoff", "group-neighbour"];
272
- for (const id of ids)
273
- expect(yield* (yield* Tally.get(id)).Add(1)).toBe(1);
274
- yield* sql.unsafe(`CREATE FUNCTION group_slow_commit() RETURNS trigger LANGUAGE plpgsql AS $$
275
- BEGIN PERFORM pg_sleep(1.4); RETURN NULL; END $$`);
276
- yield* sql.unsafe(`CREATE CONSTRAINT TRIGGER group_slow_commit AFTER INSERT ON actor_receipts
277
- DEFERRABLE INITIALLY DEFERRED FOR EACH ROW WHEN (NEW.command_id = '${a1}')
278
- EXECUTE FUNCTION group_slow_commit()`);
279
- const a1Held = yield* test.pauseNext("beforeHandler", { commandId: a1 });
280
- const b1Held = yield* test.pauseNext("beforeHandler", { commandId: b1 });
281
- const handoff = yield* Tally.get(ids[0]);
282
- const first = yield* Effect.forkChild(handoff.Add(10).pipe(Actor.commandId(a1), Effect.exit));
283
- yield* a1Held.reached;
284
- const second = yield* Effect.forkChild(handoff.Add(100).pipe(Actor.commandId(a2), Effect.exit));
285
- yield* Effect.sleep("900 millis");
286
- const neighbour = yield* Effect.forkChild((yield* Tally.get(ids[1])).Add(20).pipe(Actor.commandId(b1), Effect.exit));
287
- yield* b1Held.reached;
288
- yield* a1Held.release;
289
- yield* b1Held.release;
290
- expect(yield* Fiber.join(neighbour)).toEqual(Exit.succeed(21));
291
- const seen = [];
292
- const deadline = (yield* Clock.currentTimeMillis) + 4_000;
293
- while ((yield* Clock.currentTimeMillis) < deadline) {
294
- const rows = yield* sql `
295
- SELECT pid, state, wait_event_type AS waiting FROM pg_stat_activity
296
- WHERE datname = current_database() AND pid <> pg_backend_pid()
297
- AND clock_timestamp() - state_change > interval '300 milliseconds'
298
- AND (state = 'idle in transaction' OR wait_event_type = 'Lock')`;
299
- for (const row of rows)
300
- seen.push(`${row.pid}:${row.state}:${row.waiting}`);
301
- yield* Effect.sleep("25 millis");
302
- }
303
- expect([...new Set(seen)]).toEqual([]);
304
- expect(yield* Fiber.join(first)).toEqual(Exit.succeed(11));
305
- expect(yield* Fiber.join(second)).toEqual(Exit.succeed(111));
306
- expect(yield* stateOf(ids[0])).toEqual({ count: 111 });
307
- expect(yield* test.receiptsFor(handoff.ref, "Add")).toBe(3);
308
- })),
309
- },
310
- {
311
- name: "group commit: a member whose generation row another transaction holds is skipped, and its neighbours commit together without waiting for that lock",
312
- requiresIndependentConnections: true,
313
- requiresFreshDatabase: true,
314
- timeoutMs: 60_000,
315
- run: ({ expect, environment }) => withGroups(environment, "10 seconds", Effect.gen(function* () {
316
- const sql = yield* SqlClient.SqlClient;
317
- const test = yield* ActorTest;
318
- const [l, x, y] = yield* mintAll(3);
319
- const ids = ["group-locked", "group-x", "group-y"];
320
- for (const id of ids)
321
- expect(yield* (yield* Tally.get(id)).Add(1)).toBe(1);
322
- const locked = Deferred.makeUnsafe();
323
- const unlock = Deferred.makeUnsafe();
324
- const holder = yield* Effect.forkChild(sql.withTransaction(Effect.gen(function* () {
325
- yield* sql `SELECT 1 FROM actor_generations
326
- WHERE actor_type = 'GroupTally' AND actor_id = ${ids[0]} FOR UPDATE`;
327
- yield* Deferred.succeed(locked, undefined);
328
- yield* Deferred.await(unlock);
329
- })));
330
- yield* Deferred.await(locked);
331
- const pauses = yield* Effect.forEach([x, y], (commandId) => test.pauseNext("beforeHandler", { commandId }));
332
- runs.clear();
333
- const lockedCall = yield* Effect.forkChild((yield* Tally.get(ids[0])).Add(5).pipe(Actor.commandId(l), Effect.exit));
334
- yield* Effect.sleep("20 millis");
335
- const others = yield* Effect.forEach([
336
- [ids[1], x],
337
- [ids[2], y],
338
- ], ([id, commandId]) => Effect.flatMap(Tally.get(id), (tally) => Effect.forkChild(tally.Add(5).pipe(Actor.commandId(commandId), Effect.exit))));
339
- const reached = yield* Effect.forEach(pauses, ({ reached }) => reached, {
340
- concurrency: "unbounded",
341
- }).pipe(Effect.timeoutOption("1500 millis"));
342
- expect(reached._tag).toBe("Some");
343
- yield* Effect.forEach(pauses, ({ release }) => release, { discard: true });
344
- const answered = yield* Effect.forEach(others, Fiber.join).pipe(Effect.timeoutOption("1500 millis"));
345
- expect(answered).toEqual(Option.some([Exit.succeed(6), Exit.succeed(6)]));
346
- expect(yield* committedIn(ids[1], x)).toBe(yield* committedIn(ids[2], y));
347
- yield* Deferred.succeed(unlock, undefined);
348
- yield* Fiber.join(holder);
349
- expect(yield* Fiber.join(lockedCall)).toEqual(Exit.succeed(6));
350
- expect(yield* committedIn(ids[0], l)).not.toBe(yield* committedIn(ids[1], x));
351
- })),
352
- },
353
- ];
@@ -1,3 +0,0 @@
1
- import type { ConformanceCase } from "../conformance.ts";
2
- /** Heap cases: bounded retained heap once activations hibernate and once Cluster forgets processed request ids. */
3
- export declare const heapConformance: ReadonlyArray<ConformanceCase>;
@@ -1,149 +0,0 @@
1
- import { Crypto, Effect, Layer, ManagedRuntime, Schedule, Schema } from "effect";
2
- import { Actor, Actors } from "../../index.js";
3
- import { ActorTest } from "../actor-test.js";
4
- import { onBun } from "./platform.js";
5
- const Touch = Actor.command("Touch", { success: Schema.Finite });
6
- const Sleeper = Actor.make("HeapSleeper", {
7
- key: Schema.String,
8
- state: Actor.state({ count: Schema.Finite.pipe(Schema.withDecodingDefault(Effect.succeed(0))) }),
9
- api: { Touch },
10
- policy: { hibernateAfter: "250 millis" },
11
- });
12
- const SleeperLive = Sleeper.toLayer(Effect.succeed({
13
- Touch: Effect.fnUntraced(function* () {
14
- const turn = yield* Sleeper.Turn;
15
- yield* turn.state.set({ count: turn.state.count + 1 });
16
- return turn.state.count;
17
- }),
18
- }));
19
- const ACTORS = 1000;
20
- const COMMANDS = 4_096;
21
- const HOT_ACTORS = 32;
22
- let cachedGc;
23
- /**
24
- * Node's collector, made reachable once: building its vm realm allocates, so
25
- * doing that for each sample would charge the realm to the heap it measures.
26
- */
27
- const nodeGc = Effect.gen(function* () {
28
- if (cachedGc !== undefined)
29
- return cachedGc;
30
- const v8 = yield* Effect.promise(() => import("node:v8"));
31
- const vm = yield* Effect.promise(() => import("node:vm"));
32
- v8.setFlagsFromString("--expose-gc");
33
- cachedGc = vm.runInNewContext("gc");
34
- return cachedGc;
35
- });
36
- /**
37
- * Live JavaScript heap after a full collection. ArrayBuffer memory is left
38
- * out: an in-process database keeps its pages there, and they grow with
39
- * stored rows rather than with anything the runtime retains. Bun counts every
40
- * live cell; V8 counts the objects that inherit `Object.prototype`, which is
41
- * every object but a null-prototype one, so the two counts differ in scale
42
- * but each rises with each object the runtime retains. The count is taken
43
- * before the byte size so counting is not charged to the sample. `bun:jsc` and `node:v8`
44
- * are loaded only when the case runs, so importing the testing entry needs
45
- * neither runtime's helpers.
46
- */
47
- const retained = Effect.gen(function* () {
48
- if (!onBun) {
49
- const v8 = yield* Effect.promise(() => import("node:v8"));
50
- const gc = yield* nodeGc;
51
- gc({ type: "major" });
52
- gc({ type: "major" });
53
- const objects = v8.queryObjects(Object, { format: "count" });
54
- return { bytes: v8.getHeapStatistics().used_heap_size, objects };
55
- }
56
- const { heapStats } = yield* Effect.promise(() => import("bun:jsc"));
57
- Bun.gc(true);
58
- const stats = heapStats();
59
- return { bytes: stats.heapSize - stats.extraMemorySize, objects: stats.objectCount };
60
- });
61
- /**
62
- * Samples the heap once a second until two samples agree to within one object
63
- * per actor, or 60 seconds pass. Cluster's reaper sweeps every 5 seconds and
64
- * releases a whole sweep's activations at once, so a settled heap means the
65
- * sweeps have run.
66
- */
67
- const settled = Effect.gen(function* () {
68
- let previous = yield* retained;
69
- return yield* Effect.gen(function* () {
70
- const next = yield* retained;
71
- const done = Math.abs(previous.objects - next.objects) < ACTORS;
72
- previous = next;
73
- return done ? next : yield* Effect.fail("unsettled");
74
- }).pipe(Effect.delay("1 second"), Effect.retry({ schedule: Schedule.recurs(60) }), Effect.orElseSucceed(() => previous));
75
- });
76
- const perActor = (before, after) => ({
77
- objects: (after.objects - before.objects) / ACTORS,
78
- bytes: (after.bytes - before.bytes) / ACTORS,
79
- });
80
- /** Heap cases: bounded retained heap once activations hibernate and once Cluster forgets processed request ids. */
81
- export const heapConformance = [
82
- {
83
- name: "retains bounded heap for touched actors once every activation hibernates",
84
- timeoutMs: 120_000,
85
- run: ({ expect, environment }) => environment.run(Effect.gen(function* () {
86
- const database = yield* environment.freshDatabase;
87
- const runtime = yield* Effect.acquireRelease(Effect.map(Crypto.Crypto, (crypto) => ManagedRuntime.make(SleeperLive.pipe(Layer.provideMerge(ActorTest.layer({ database })), Layer.provide(Layer.succeed(Crypto.Crypto, crypto)), Layer.orDie))), (runtime) => Effect.promise(() => runtime.dispose()));
88
- const touch = (id) => Sleeper.get(id).pipe(Effect.flatMap((sleeper) => sleeper.Touch()));
89
- const touchAll = (prefix) => Effect.forEach(Array.from({ length: ACTORS }, (_, index) => `${prefix}-${index}`), touch, { concurrency: 32, discard: true });
90
- const hibernate = Effect.andThen(Effect.sleep("6 seconds"), settled);
91
- const { growth, generations } = yield* Effect.promise(() => runtime.runPromise(Effect.gen(function* () {
92
- yield* touchAll("warm");
93
- const before = yield* hibernate;
94
- yield* touchAll("actor");
95
- const growth = perActor(before, yield* hibernate);
96
- const test = yield* ActorTest;
97
- const generations = yield* Effect.forEach([0, 250, 500, 750, 999], (index) => Effect.gen(function* () {
98
- const sample = yield* Sleeper.get(`actor-${index}`);
99
- yield* sample.Touch();
100
- return (yield* test.inspect(sample.ref)).generation;
101
- }));
102
- return { growth, generations };
103
- })));
104
- expect(generations).toEqual(["2", "2", "2", "2", "2"]);
105
- expect({ ...growth, bounded: growth.objects < 10 && growth.bytes < 1024 }).toMatchObject({
106
- bounded: true,
107
- });
108
- })),
109
- },
110
- {
111
- name: "retains bounded heap per command once Cluster forgets processed request ids",
112
- requiresIndependentConnections: true,
113
- timeoutMs: 120_000,
114
- run: ({ expect, environment }) => environment.run(Effect.gen(function* () {
115
- const database = yield* environment.freshDatabase;
116
- const runtime = yield* Effect.acquireRelease(Effect.map(Crypto.Crypto, (crypto) => ManagedRuntime.make(SleeperLive.pipe(Layer.provideMerge(ActorTest.layer({ database })), Layer.provide(Layer.succeed(Crypto.Crypto, crypto)), Layer.orDie))), (runtime) => Effect.promise(() => runtime.dispose()));
117
- const touch = (id) => Sleeper.get(id).pipe(Effect.flatMap((sleeper) => sleeper.Touch()));
118
- const touchMany = Effect.forEach(Array.from({ length: COMMANDS }, (_, index) => `hot-${index % HOT_ACTORS}`), touch, { concurrency: HOT_ACTORS, discard: true });
119
- const forget = Effect.andThen(Effect.sleep("11 seconds"), retained);
120
- const { growth, first, replayed, count } = yield* Effect.promise(() => runtime.runPromise(Effect.gen(function* () {
121
- const id = yield* (yield* Actors).mintCommandId;
122
- const saved = Sleeper.get("hot-0").pipe(Effect.flatMap((sleeper) => sleeper.Touch().pipe(Actor.commandId(id))));
123
- const first = yield* saved;
124
- yield* touchMany;
125
- yield* forget;
126
- yield* touchMany;
127
- const before = yield* forget;
128
- yield* touchMany;
129
- const after = yield* forget;
130
- const replayed = yield* saved;
131
- const count = yield* touch("hot-0");
132
- return {
133
- growth: {
134
- objects: (after.objects - before.objects) / COMMANDS,
135
- bytes: (after.bytes - before.bytes) / COMMANDS,
136
- },
137
- first,
138
- replayed,
139
- count,
140
- };
141
- })));
142
- expect({ first, replayed }).toEqual({ first: 1, replayed: 1 });
143
- expect(count).toBe((3 * COMMANDS) / HOT_ACTORS + 2);
144
- expect({ ...growth, bounded: growth.objects < 0.5 && growth.bytes < 64 }).toMatchObject({
145
- bounded: true,
146
- });
147
- })),
148
- },
149
- ];