| 1 | import { assert, describe, it } from "@effect/vitest" |
| 2 | import { Effect } from "effect" |
| 3 | import { Runner, RunnerAddress, RunnerStorage, ShardId } from "effect/cluster" |
| 4 | |
| 5 | describe("RunnerStorage", () => { |
| 6 | it.effect("tracks runner health in memory", () => |
| 7 | Effect.gen(function*() { |
| 8 | const storage = yield* RunnerStorage.makeMemory |
| 9 | const address = RunnerAddress.make("localhost", 41001) |
| 10 | yield* storage.register(Runner.make({ address, groups: ["default"], weight: 1 }), false) |
| 11 | assert.strictEqual((yield* storage.getRunners)[0][1], false) |
| 12 | yield* storage.setRunnerHealth(address, true) |
| 13 | assert.strictEqual((yield* storage.getRunners)[0][1], true) |
| 14 | })) |
| 15 | |
| 16 | it.effect("memory acquire accepts a one-shot iterable", () => |
| 17 | Effect.gen(function*() { |
| 18 | const storage = yield* RunnerStorage.makeMemory |
| 19 | const address = RunnerAddress.make("localhost", 1234) |
| 20 | const shards = [ShardId.make("default", 1), ShardId.make("default", 2)] |
| 21 | const acquired = yield* storage.acquire( |
| 22 | address, |
| 23 | (function*() { |
| 24 | yield* shards |
| 25 | })() |
| 26 | ) |
| 27 | |
| 28 | assert.deepStrictEqual(acquired, shards) |
| 29 | assert.deepStrictEqual(yield* storage.refresh(address, []), shards) |
| 30 | })) |
| 31 | }) |