| 55 | } |
| 56 | |
| 57 | func (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 | |
| 89 | func (s *ServerTestSuite) TestShutdown() { |
| 90 | _, cancel := context.WithCancel(context.Background()) |