| 117 | export const pgWaitStrategy = () => Wait.forHealthCheck() |
| 118 | |
| 119 | export class PgContainer extends Context.Service<PgContainer>()("test/PgContainer", { |
| 120 | make: Effect.acquireRelease( |
| 121 | Effect.tryPromise({ |
| 122 | try: () => |
| 123 | lifecycle( |
| 124 | "new", |
| 125 | "container-start", |
| 126 | () => |
| 127 | new PostgreSqlContainer("postgres:14-alpine") |
| 128 | // Tests don't require crash durability; skip fsync waits during table setup. |
| 129 | .withCommand(["postgres", "-c", "fsync=off"]) |
| 130 | .withWaitStrategy(pgWaitStrategy()) |
| 131 | .start() |
| 132 | ), |
| 133 | catch: (cause) => new ContainerError({ cause }) |
| 134 | }).pipe(Effect.tap((container) => marker(container.getId(), "container-started"))), |
| 135 | (container) => releasePgContainer(container.getId()) |
| 136 | ) |
| 137 | }) { |
| 138 | static readonly layer = Layer.effect(this)(this.make) |
| 139 | |
| 140 | static layerClient = Layer.unwrap( |
| 141 | Effect.gen(function*() { |
| 142 | const container = yield* PgContainer |
| 143 | return yield* instrumentClient( |
| 144 | "layerClient", |
| 145 | container.getId(), |
| 146 | PgClient.layer({ |
| 147 | url: Redacted.make(container.getConnectionUri()) |
| 148 | }) |
| 149 | ) |
| 150 | }) |
| 151 | ).pipe(Layer.provide(this.layer)) |
| 152 | |
| 153 | static layerMakeClient = Layer.unwrap( |
| 154 | Effect.gen(function*() { |
| 155 | const container = yield* PgContainer |
| 156 | return yield* instrumentClient( |
| 157 | "layerMakeClient", |
| 158 | container.getId(), |
| 159 | PgClient.layerFrom(PgClient.makeClient({ |
| 160 | url: Redacted.make(container.getConnectionUri()) |
| 161 | })) |
| 162 | ) |
| 163 | }) |
| 164 | ).pipe(Layer.provide(this.layer)) |
| 165 | |
| 166 | static layerMakeClientUnprepared = Layer.unwrap( |
| 167 | Effect.gen(function*() { |
| 168 | const container = yield* PgContainer |
| 169 | return yield* instrumentClient( |
| 170 | "layerMakeClientUnprepared", |
| 171 | container.getId(), |
| 172 | PgClient.layerFrom(PgClient.makeClient({ |
| 173 | url: Redacted.make(container.getConnectionUri()), |
| 174 | prepare: false |
| 175 | })) |
| 176 | ) |
nothing calls this directly
no test coverage detected