MCPcopy Create free account
hub / github.com/imgproxy/imgproxy / TestCheckTimeout

Function TestCheckTimeout

server/timer_test.go:14–68  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

12)
13
14func TestCheckTimeout(t *testing.T) {
15 tests := []struct {
16 name string
17 setup func() context.Context
18 fail bool
19 }{
20 {
21 name: "WithoutTimeout",
22 setup: context.Background,
23 fail: false,
24 },
25 {
26 name: "ActiveTimerContext",
27 setup: func() context.Context {
28 req := httptest.NewRequest(http.MethodGet, "/test", nil)
29 newReq, _ := server.StartRequestTimer(req, 10*time.Second)
30 return newReq.Context()
31 },
32 fail: false,
33 },
34 {
35 name: "CancelledContext",
36 setup: func() context.Context {
37 req := httptest.NewRequest(http.MethodGet, "/test", nil)
38 newReq, cancel := server.StartRequestTimer(req, 10*time.Second)
39 cancel() // Cancel immediately
40 return newReq.Context()
41 },
42 fail: true,
43 },
44 {
45 name: "DeadlineExceeded",
46 setup: func() context.Context {
47 ctx, cancel := context.WithTimeout(context.Background(), time.Nanosecond)
48 defer cancel()
49 time.Sleep(time.Millisecond * 10) // Ensure timeout
50 return ctx
51 },
52 fail: true,
53 },
54 }
55
56 for _, tt := range tests {
57 t.Run(tt.name, func(t *testing.T) {
58 ctx := tt.setup()
59 err := server.CheckTimeout(ctx)
60
61 if tt.fail {
62 require.Error(t, err)
63 } else {
64 require.NoError(t, err)
65 }
66 })
67 }
68}

Callers

nothing calls this directly

Calls 6

StartRequestTimerFunction · 0.92
CheckTimeoutFunction · 0.92
NewRequestMethod · 0.80
BackgroundMethod · 0.80
RunMethod · 0.80
ErrorMethod · 0.65

Tested by

no test coverage detected