TestLogQueryErrorRoutesInfraCancelToErrorLevel locks in the alerting invariant: a worker-death cancellation (gRPC Canceled bubbling up while c.ctx is still healthy) must produce slog.LevelError "Query execution errored.", not Info "Query execution failed." — because the latter gets filtered out of a
(t *testing.T)
| 626 | // filtered out of alerting and drove the dev/prod observability blind spot |
| 627 | // reported on 2026-05-04 (PR #516). |
| 628 | func TestLogQueryErrorRoutesInfraCancelToErrorLevel(t *testing.T) { |
| 629 | prevLogger := slog.Default() |
| 630 | defer slog.SetDefault(prevLogger) |
| 631 | |
| 632 | var buf bytes.Buffer |
| 633 | slog.SetDefault(slog.New(slog.NewTextHandler(&buf, &slog.HandlerOptions{Level: slog.LevelDebug}))) |
| 634 | |
| 635 | c := &clientConn{ctx: context.Background(), username: "test"} |
| 636 | infraErr := errors.New("flight execute: rpc error: code = Canceled desc = context canceled") |
| 637 | c.logQueryError("SELECT 1", infraErr) |
| 638 | |
| 639 | out := buf.String() |
| 640 | if !strings.Contains(out, `level=ERROR`) { |
| 641 | t.Errorf("expected ERROR level for infra cancel, got:\n%s", out) |
| 642 | } |
| 643 | if !strings.Contains(out, `Query execution errored.`) { |
| 644 | t.Errorf("expected message 'Query execution errored.', got:\n%s", out) |
| 645 | } |
| 646 | if strings.Contains(out, `Query execution failed.`) { |
| 647 | t.Errorf("infra cancel should NOT emit 'Query execution failed.':\n%s", out) |
| 648 | } |
| 649 | } |
nothing calls this directly
no test coverage detected