MCPcopy
hub / github.com/valyala/fasthttp / TestServerReduceMemoryUsageReadTimeoutOnFirstByte

Function TestServerReduceMemoryUsageReadTimeoutOnFirstByte

server_test.go:1253–1298  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

1251}
1252
1253func TestServerReduceMemoryUsageReadTimeoutOnFirstByte(t *testing.T) {
1254 t.Parallel()
1255
1256 s := &Server{
1257 Handler: func(ctx *RequestCtx) {
1258 t.Error("shouldn't reach handler")
1259 },
1260 ReduceMemoryUsage: true,
1261 ReadTimeout: 100 * time.Millisecond,
1262 Logger: &testLogger{},
1263 }
1264
1265 pipe := fasthttputil.NewPipeConns()
1266 cc, sc := pipe.Conn1(), pipe.Conn2()
1267 defer cc.Close()
1268
1269 serveErrCh := make(chan error, 1)
1270 go func() {
1271 serveErrCh <- s.ServeConn(sc)
1272 }()
1273
1274 readErrCh := make(chan error, 1)
1275 go func() {
1276 var b [1]byte
1277 _, err := cc.Read(b[:])
1278 readErrCh <- err
1279 }()
1280
1281 select {
1282 case err := <-readErrCh:
1283 if err == nil {
1284 t.Fatal("server didn't close connection after first-byte timeout")
1285 }
1286 case <-time.After(time.Second):
1287 t.Fatal("server didn't close connection after first-byte timeout")
1288 }
1289
1290 select {
1291 case err := <-serveErrCh:
1292 if err != nil {
1293 t.Fatalf("unexpected error from ServeConn: %v", err)
1294 }
1295 case <-time.After(time.Second):
1296 t.Fatal("timeout waiting for ServeConn")
1297 }
1298}
1299
1300func TestServerServeTLSEmbed(t *testing.T) {
1301 t.Parallel()

Callers

nothing calls this directly

Calls 7

Conn1Method · 0.95
Conn2Method · 0.95
ServeConnMethod · 0.95
NewPipeConnsFunction · 0.92
CloseMethod · 0.65
ErrorMethod · 0.45
ReadMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…