MCPcopy
hub / github.com/grpc/grpc-go / TestMaxConnectionAge

Method TestMaxConnectionAge

internal/transport/keepalive_test.go:132–171  ·  view source on GitHub ↗

TestMaxConnectionAge tests that a server will send GoAway after a duration of MaxConnectionAge.

(t *testing.T)

Source from the content-addressed store, hash-verified

130// TestMaxConnectionAge tests that a server will send GoAway after a duration
131// of MaxConnectionAge.
132func (s) TestMaxConnectionAge(t *testing.T) {
133 maxConnAge := 100 * time.Millisecond
134 serverConfig := &ServerConfig{
135 BufferPool: mem.DefaultBufferPool(),
136 KeepaliveParams: keepalive.ServerParameters{
137 MaxConnectionAge: maxConnAge,
138 MaxConnectionAgeGrace: 10 * time.Millisecond,
139 },
140 }
141 copts := ConnectOptions{
142 BufferPool: mem.DefaultBufferPool(),
143 }
144 server, client, cancel := setUpWithOptions(t, 0, serverConfig, suspended, copts)
145 defer func() {
146 client.Close(fmt.Errorf("closed manually by test"))
147 server.stop()
148 cancel()
149 }()
150
151 ctx, cancel := context.WithTimeout(context.Background(), defaultTestTimeout)
152 defer cancel()
153 if _, err := client.NewStream(ctx, &CallHdr{}, nil); err != nil {
154 t.Fatalf("client.NewStream() failed: %v", err)
155 }
156
157 // Verify the server sends a GoAway to client even after client remains idle
158 // for more than MaxConnectionIdle time.
159 select {
160 case <-client.GoAway():
161 reason, debugMsg := client.GetGoAwayReason()
162 if reason != GoAwayNoReason {
163 t.Fatalf("GoAwayReason is %v, want %v", reason, GoAwayNoReason)
164 }
165 if !strings.Contains(debugMsg, "max_age") {
166 t.Fatalf("GoAwayDebugMessage is %v, want %v", debugMsg, "max_age")
167 }
168 case <-ctx.Done():
169 t.Fatalf("timed out before getting a GoAway from the server.")
170 }
171}
172
173const (
174 defaultWriteBufSize = 32 * 1024

Callers

nothing calls this directly

Calls 10

DefaultBufferPoolFunction · 0.92
setUpWithOptionsFunction · 0.85
CloseMethod · 0.65
ErrorfMethod · 0.65
stopMethod · 0.65
NewStreamMethod · 0.65
FatalfMethod · 0.65
GoAwayMethod · 0.65
GetGoAwayReasonMethod · 0.65
DoneMethod · 0.45

Tested by

no test coverage detected