| 1 | import { Duration, Effect, Schedule } from "effect" |
| 2 | import { sqlCleanupBatchSize } from "effect/internal/persistence" |
| 3 | import { TestClock } from "effect/testing" |
| 4 | |
| 5 | export const expiredEntryCount = sqlCleanupBatchSize + 1 |
| 6 | export const expiredAtEpoch = 0 |
| 7 | export const futureExpiresAt = Number.MAX_SAFE_INTEGER |
| 8 | export const cleanupBatchDelay = Duration.millis(10) |
| 9 | export const testTimeout = 30_000 |
| 10 | |
| 11 | export const waitForCount = <E, R>( |
| 12 | effect: Effect.Effect<number, E, R>, |
| 13 | predicate: (count: number) => boolean |
| 14 | ) => |
| 15 | effect.pipe( |
| 16 | Effect.repeat({ |
| 17 | until: predicate, |
| 18 | schedule: Schedule.spaced(cleanupBatchDelay) |
| 19 | }), |
| 20 | Effect.timeout(Duration.millis(testTimeout)), |
| 21 | TestClock.withLive |
| 22 | ) |