MCPcopy Create free account
hub / github.com/brimdata/super / TestRequestContextClosure

Function TestRequestContextClosure

pkg/httpd/server_test.go:15–38  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

13)
14
15func TestRequestContextClosure(t *testing.T) {
16 errCh := make(chan error)
17 h := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
18 w.WriteHeader(http.StatusOK)
19 w.(http.Flusher).Flush()
20 ctx := r.Context()
21 <-ctx.Done()
22 errCh <- ctx.Err()
23 })
24 srv := httpd.New("127.0.0.1:", h)
25 ctx, cancel := context.WithCancel(t.Context())
26 require.NoError(t, srv.Start(ctx))
27 res, err := http.Get(fmt.Sprintf("http://%s/", srv.Addr()))
28 require.NoError(t, err)
29 require.Equal(t, http.StatusOK, res.StatusCode)
30 cancel()
31 select {
32 case err = <-errCh:
33 case <-time.After(time.Second):
34 t.Fatalf("context did not cancel after one second")
35 }
36 assert.Equal(t, context.Canceled, err)
37 assert.NoError(t, srv.Wait())
38}
39
40func TestDeadlineExceeded(t *testing.T) {
41 old := httpd.ShutdownTimeout

Callers

nothing calls this directly

Calls 12

NewFunction · 0.92
WriteHeaderMethod · 0.80
ContextMethod · 0.80
ErrMethod · 0.80
AddrMethod · 0.80
GetMethod · 0.65
AfterMethod · 0.65
FlushMethod · 0.45
DoneMethod · 0.45
StartMethod · 0.45
EqualMethod · 0.45
WaitMethod · 0.45

Tested by

no test coverage detected