TestDisconnectLabel tests the disconnect label metric plumbing. Separately, e2e tests are more exhaustive and check for all disconnect reasons.
(t *testing.T)
| 300 | // TestDisconnectLabel tests the disconnect label metric plumbing. |
| 301 | // Separately, e2e tests are more exhaustive and check for all disconnect reasons. |
| 302 | func (s) TestDisconnectLabel(t *testing.T) { |
| 303 | // This subtest verifies the "GOAWAY NO_ERROR" label when the server shuts |
| 304 | // down gracefully. Since runDisconnectLabelTest performs a unary RPC which |
| 305 | // completes before the triggerFunc is invoked, there are no active streams. |
| 306 | // GracefulStop sends a GOAWAY with active streams = 0, which results in a |
| 307 | // NO_ERROR code. |
| 308 | t.Run("GoAway", func(t *testing.T) { |
| 309 | runDisconnectLabelTest(t, "GOAWAY NO_ERROR", func(ss *stubserver.StubServer, _ *controllableConn) { |
| 310 | ss.S.GracefulStop() |
| 311 | }) |
| 312 | }) |
| 313 | |
| 314 | // This subtest verifies the "connection reset" label when the connection is |
| 315 | // reset by the peer. It injects a syscall.ECONNRESET error into the transport |
| 316 | // read to simulate this scenario. |
| 317 | t.Run("ConnectionReset", func(t *testing.T) { |
| 318 | runDisconnectLabelTest(t, "connection reset", func(_ *stubserver.StubServer, cc *controllableConn) { |
| 319 | cc.breakWith(syscall.ECONNRESET) |
| 320 | }) |
| 321 | }) |
| 322 | |
| 323 | // This subtest verifies that an io.EOF error injected into the transport read |
| 324 | // maps to the "unknown" label. |
| 325 | t.Run("EOF", func(t *testing.T) { |
| 326 | runDisconnectLabelTest(t, "unknown", func(_ *stubserver.StubServer, cc *controllableConn) { |
| 327 | cc.breakWith(io.EOF) |
| 328 | }) |
| 329 | }) |
| 330 | } |
| 331 | |
| 332 | type controllableConn struct { |
| 333 | net.Conn |
nothing calls this directly
no test coverage detected