| 459 | // Runs a statement whose checkout opens the pool's first session, answers the |
| 460 | // connect after 40 ms, then runs a second statement on the same session. |
| 461 | const firstCheckout = ( |
| 462 | checkout: (pool: PgPool.PgPool) => Effect.Effect<unknown, SqlError, Scope.Scope>, |
| 463 | options: { |
| 464 | readonly acquireTimeout?: Duration.Input | undefined |
| 465 | readonly propagate?: boolean |
| 466 | readonly timing?: boolean |
| 467 | } = {} |
| 468 | ) => { |
| 469 | const { isRoot, named, tracer } = recording() |
| 470 | return Effect.scoped(Effect.gen(function*() { |
| 471 | const server = yield* heldServer |
| 472 | const pool = yield* PgPool.make({ |
| 473 | username: "test", |
| 474 | maxConnections: 1, |
| 475 | acquireTimeout: options.acquireTimeout, |
| 476 | stream: server.stream |
| 477 | }).pipe(Effect.withSpan("pool startup")) |
| 478 | const first = yield* Effect.forkChild(Effect.scoped(checkout(pool)).pipe(Effect.withSpan("first statement"))) |
| 479 | const answer = yield* Queue.take(server.startups) |
| 480 | yield* TestClock.adjust("40 millis") |
| 481 | yield* answer |
| 482 | yield* Fiber.join(first) |
| 483 | yield* Effect.scoped(pool.get).pipe(Effect.withSpan("second statement")) |
| 484 | return { |
| 485 | attempts: named("sql.connect"), |
| 486 | connects: named("db.connect"), |
| 487 | first: named("first statement")[0], |
| 488 | isRoot |
| 489 | } |
| 490 | })).pipe( |
| 491 | Effect.provideService(References.TracerTimingEnabled, options.timing ?? true), |
| 492 | (effect) => traced(effect, tracer, options.propagate ?? true) |
| 493 | ) |
| 494 | } |
| 495 | |
| 496 | it.effect("reports the connect a statement waited for under its span, only with propagation and timing", () => |
| 497 | Effect.gen(function*() { |