TestMaxConnectionAge tests that a server will send GoAway after a duration of MaxConnectionAge.
(t *testing.T)
| 130 | // TestMaxConnectionAge tests that a server will send GoAway after a duration |
| 131 | // of MaxConnectionAge. |
| 132 | func (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 | |
| 173 | const ( |
| 174 | defaultWriteBufSize = 32 * 1024 |
nothing calls this directly
no test coverage detected