@@ -159,13 +159,13 @@ func TestGracefulShutdown_SuccessWithDBFail(t *testing.T) {
159159 return expectedErr
160160 }
161161
162- // channel to signal shutdown completion
162+ // channel to signal shutdown completion and to receive shutdown error
163163 done := make (chan struct {})
164- var shutdownErr error
164+ errCh := make ( chan error , 1 )
165165
166- // run GracefulShutdown with the failing closeDB function
166+ // run GracefulShutdown with the failing closeDB function and send error on channel
167167 go func () {
168- shutdownErr = server .GracefulShutdown (srv , 5 * time .Second , done , closeDB )
168+ errCh <- server .GracefulShutdown (srv , 5 * time .Second , done , closeDB )
169169 }()
170170
171171 // send SIGINT after 1 second
@@ -179,7 +179,8 @@ func TestGracefulShutdown_SuccessWithDBFail(t *testing.T) {
179179 t .Fatal ("shutdown did not complete within 10 seconds" )
180180 }
181181
182- // verify that the closeDB error is returned
182+ // receive and verify that the closeDB error is returned
183+ shutdownErr := <- errCh
183184 if shutdownErr == nil {
184185 t .Error ("expected an error, got nil" )
185186 } else if ! errors .Is (shutdownErr , expectedErr ) {
@@ -225,13 +226,13 @@ func TestGracefulShutdown_TimeoutForceCloseSuccess(t *testing.T) {
225226 // wait briefly to ensure the request starts
226227 time .Sleep (500 * time .Millisecond )
227228
228- // channel to signal shutdown completion
229+ // channel to signal shutdown completion and to receive shutdown error
229230 done := make (chan struct {})
230- var shutdownErr error
231+ errCh := make ( chan error , 1 )
231232
232- // run GracefulShutdown with a 2-second timeout
233+ // run GracefulShutdown with a 2-second timeout and send error on channel
233234 go func () {
234- shutdownErr = server .GracefulShutdown (srv , 2 * time .Second , done )
235+ errCh <- server .GracefulShutdown (srv , 2 * time .Second , done )
235236 }()
236237
237238 // send SIGINT after 1 second, while the handler is still sleeping
@@ -245,7 +246,8 @@ func TestGracefulShutdown_TimeoutForceCloseSuccess(t *testing.T) {
245246 t .Fatal ("shutdown did not complete within 10 seconds" )
246247 }
247248
248- // verify that the error is context.DeadlineExceeded
249+ // receive and verify that the error is context.DeadlineExceeded
250+ shutdownErr := <- errCh
249251 if ! errors .Is (shutdownErr , context .DeadlineExceeded ) {
250252 t .Errorf ("expected context.DeadlineExceeded, got %v" , shutdownErr )
251253 }
0 commit comments