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

Method TestStartServerWithInvalidBind

server/server_test.go:57–87  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

55}
56
57func (s *ServerTestSuite) TestStartServerWithInvalidBind() {
58 ctx, cancel := context.WithCancel(s.T().Context())
59
60 // Track if cancel was called using atomic
61 var cancelCalled atomic.Bool
62 cancelWrapper := func() {
63 cancel()
64 cancelCalled.Store(true)
65 }
66
67 s.config().Bind = "-1.-1.-1.-1" // Invalid address
68
69 srv, err := server.Start(cancelWrapper, s.router())
70
71 s.Require().Error(err)
72 s.Nil(srv)
73 s.Contains(err.Error(), "can't start server")
74
75 // Check if cancel was called using Eventually
76 s.Require().Eventually(cancelCalled.Load, 100*time.Millisecond, 10*time.Millisecond)
77
78 // Also verify the context was cancelled
79 s.Require().Eventually(func() bool {
80 select {
81 case <-ctx.Done():
82 return true
83 default:
84 return false
85 }
86 }, 100*time.Millisecond, 10*time.Millisecond)
87}
88
89func (s *ServerTestSuite) TestShutdown() {
90 _, cancel := context.WithCancel(context.Background())

Callers

nothing calls this directly

Calls 3

StartFunction · 0.92
TMethod · 0.80
ErrorMethod · 0.65

Tested by

no test coverage detected