MCPcopy Create free account
hub / github.com/erpc/erpc / TestClassifyDbError

Function TestClassifyDbError

auth/strategy_database_test.go:101–199  ·  view source on GitHub ↗

TestClassifyDbError pins down the bounded set of telemetry labels. The new "db_not_ready" label is the operational signal that distinguishes "our PostgreSQLConnector is mid-reconnect — wait and retry" from "pgbouncer/postgres is actually unreachable — call ops". Before 2026-05-13 both rolled up int

(t *testing.T)

Source from the content-addressed store, hash-verified

99// 2026-05-13 both rolled up into "db_connection", which made the reconnect
100// cascade look identical to a real outage on the dashboard.
101func TestClassifyDbError(t *testing.T) {
102 t.Parallel()
103
104 s := &DatabaseStrategy{}
105
106 tests := []struct {
107 name string
108 err error
109 want string
110 }{
111 {
112 name: "nil",
113 err: nil,
114 want: "db_query_error",
115 },
116
117 // --- db_not_ready: our own connector signalling mid-reconnect ---
118 {
119 name: "ErrConnectorNotReady direct",
120 err: data.ErrConnectorNotReady,
121 want: "db_not_ready",
122 },
123 {
124 name: "ErrConnectorNotReady wrapped",
125 err: fmt.Errorf("auth get failed: %w", data.ErrConnectorNotReady),
126 want: "db_not_ready",
127 },
128
129 // --- db_timeout ---
130 {
131 name: "context deadline exceeded",
132 err: context.DeadlineExceeded,
133 want: "db_timeout",
134 },
135 {
136 name: "wrapped deadline exceeded",
137 err: fmt.Errorf("query: %w", context.DeadlineExceeded),
138 want: "db_timeout",
139 },
140 {
141 name: "substring: timeout",
142 err: errors.New("operation timeout: server did not respond"),
143 want: "db_timeout",
144 },
145
146 // --- db_connection: real transport failures ---
147 {
148 name: "substring: connection refused",
149 err: errors.New("dial tcp: connection refused"),
150 want: "db_connection",
151 },
152 {
153 name: "substring: connection reset",
154 err: errors.New("write tcp: connection reset by peer"),
155 want: "db_connection",
156 },
157 {
158 name: "substring: broken pipe",

Callers

nothing calls this directly

Calls 3

classifyDbErrorMethod · 0.95
ErrorfMethod · 0.80
RunMethod · 0.65

Tested by

no test coverage detected