Skip to content

test(coverage): drive pool, telemetry, ctxkeys to >=95%#21

Closed
mastermanas805 wants to merge 1 commit into
masterfrom
coverage/prov-pool-telemetry-95
Closed

test(coverage): drive pool, telemetry, ctxkeys to >=95%#21
mastermanas805 wants to merge 1 commit into
masterfrom
coverage/prov-pool-telemetry-95

Conversation

@mastermanas805
Copy link
Copy Markdown
Member

Summary

  • Drives internal/pool from 26.3% -> 99.3%, internal/telemetry from 80.4% -> 100%, internal/ctxkeys to vacuously 100% (const-only package).
  • pool tests use a real Postgres via TEST_DATABASE_URL + per-test schemas; mock Backend impls (compile-time interface assertions) keep them fast (~3s).
  • Adds postgres service container to coverage.yml so CI exercises the full surface; tests skip cleanly when TEST_DATABASE_URL is unset.

Production-code changes (minimal)

  • pool.runTickInterval extracted as a package-private var so a unit test can shrink the maintenance-loop tick from 30s -> 50ms. Production cadence unchanged.
  • telemetry.newResource is a package-private var aliasing resource.New. Lets a test force the defensive resource_failed fallback without touching OTel SDK internals.

Test plan

  • make gate green (build + vet + go test ./... -short -count=1)
  • go test -race -count=1 clean on all three packages
  • go test -count=1 x3 — no flakes
  • Final coverage: pool 99.3% / telemetry 100% / ctxkeys [no statements]

🤖 Generated with Claude Code

Coverage after:
  - internal/pool       99.3% (was 26.3%)
  - internal/telemetry  100%  (was 80.4%)
  - internal/ctxkeys    [no statements; const-only]

pool/
  Adds manager_db_test.go gated on TEST_DATABASE_URL. Each test uses a
  per-test schema (search_path=pooltest_*) so a shared CI postgres isn't
  polluted across test/suite runs. Mock backends mirror the production
  Backend interfaces (compile-time _ = assertions) and run zero-latency
  so the integration tests stay fast.

  Covered:
    Start, Shutdown, migrate (incl. idempotency + exec-failure), Claim
    (empty + hit + decrypt-error + scan-error), Stats (empty + populated
    + query-failure), fillPool (top-up + at-target + target=0 +
    count-failure), provisionOneItem (success + backend-error +
    insert-failure), provisionItemsConcurrently (backend-failure logged
    + needed<=0), provisionOneItemBackend (all 4 happy paths + unknown
    type + encrypt-error per type), triggerRefill (coalesce-when-full),
    run (ticker arm + refillCh arm), NewWithConfig (factory).

  One tiny production-code change: extract `runTickInterval` as a
  package-level var so a unit test can shrink it from 30s -> 50ms to
  exercise the ticker arm of the run select without a 30s sleep.
  Production behaviour unchanged.

telemetry/
  Adds NR-license-header path, sentinel-key collapse, plaintext endpoint,
  OTEL_SERVICE_NAME override, :443 TLS, http:// scheme forces plaintext,
  whitespace endpoint, exporter-construction failure (NUL in endpoint
  triggers url.Parse error), shutdown-with-cancelled-ctx, and
  resource.New failure via an injected `newResource` var (the only
  feasible way to exercise the defensive fallback without modifying OTel
  SDK internals).

ctxkeys/
  Round-trip, empty-means-anonymous, no-string-collision, nested
  override, and iota-stability guard. Package has no statements so
  coverage is vacuously 100%; tests guard the public contract.

ci/
  coverage.yml gains a postgres:16-alpine service container + sets
  TEST_DATABASE_URL. The pool integration tests skip cleanly when the
  var is unset so contributors without a local postgres still see green
  `go test ./...`. Same pattern as api/coverage.yml and
  worker/coverage.yml. Comment block updated to reflect the new policy.

Verified: gate green, race clean, no flakes across 3 consecutive runs.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@mastermanas805
Copy link
Copy Markdown
Member Author

Superseded by #27 (pool+root+circuit+telemetry to ≥95%; merged).

@mastermanas805 mastermanas805 deleted the coverage/prov-pool-telemetry-95 branch May 22, 2026 03:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant