1import type * as Effect from "effect/Effect";
2import * as Semaphore from "effect/Semaphore";
3
4/**
5 * The testing project allows 5 Kafka clusters (and 5 Connect clusters) per
6 * region and one cluster create request per minute per region. Every test
7 * that creates a cluster holds one of these slots for as long as its cluster
8 * exists, so the suite never exceeds the regional cluster quota; the
9 * providers retry the per-minute `TooManyRequests` throttle. A test's timeout
10 * includes the time it waits for a slot, so these tests use long timeouts.
11 */
12const slots = Semaphore.makeUnsafe(4);
13
14/** Run a cluster-creating Managed Kafka test body while holding one slot. */
15export const withKafkaClusterSlot = <A, E, R>(
16 self: Effect.Effect<A, E, R>,
17): Effect.Effect<A, E, R> => slots.withPermits(1)(self);
18
19/**
20 * Take a slot for a shared stack whose cluster outlives one test body
21 * (`beforeAll` deploy → `afterAll` destroy). Pair with
22 * {@link releaseKafkaClusterSlot} at the end of `afterAll`.
23 */
24export const takeKafkaClusterSlot: Effect.Effect<number> = slots.take(1);
25
26/** Release a slot taken with {@link takeKafkaClusterSlot}. */
27export const releaseKafkaClusterSlot: Effect.Effect<number> = slots.release(1);