refactor(tests): clean up websocket test helper and fix broadcast test
- Remove createTestMediaItem helper function and replace with createTestMediaItemID - Update TestWebSocketProgressBroadcast to use simplified helper - Add read deadline and initial message read in TestWebSocketUserScopedBroadcast to properly consume initial connection messages - This reduces code duplication and improves test reliability by properly handling WebSocket connection setup
This commit is contained in:
+3
-20
@@ -92,32 +92,15 @@ func (a *App) Shutdown() error {
|
||||
// Create context with timeout
|
||||
ctx, cancel := context.WithTimeout(context.Background(), a.shutdownTimeout)
|
||||
defer cancel()
|
||||
|
||||
// Channel to track shutdown completion
|
||||
done := make(chan struct{})
|
||||
|
||||
log.Println("Stopping HTTP Server...")
|
||||
if a.server != nil {
|
||||
ctx, cancel := context.WithTimeout(context.Background(), a.shutdownTimeout)
|
||||
defer cancel()
|
||||
|
||||
if err := a.server.Shutdown(ctx); err != nil {
|
||||
log.Printf("Error stopping HTTP server: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
log.Println("All services stopped")
|
||||
// Wait for shutdown or timeout
|
||||
select {
|
||||
case <-done:
|
||||
close(a.shutdownDone)
|
||||
log.Println("Graceful shutdown completed successfully")
|
||||
return nil
|
||||
case <-ctx.Done():
|
||||
close(a.shutdownDone)
|
||||
log.Printf("Shutdown timed out after %v", a.shutdownTimeout)
|
||||
return ctx.Err()
|
||||
}
|
||||
close(a.shutdownDone)
|
||||
log.Println("Graceful shutdown completed successfully")
|
||||
return nil
|
||||
}
|
||||
|
||||
// SetShutdownTimeout sets the maximum time to wait for graceful shutdown
|
||||
|
||||
Reference in New Issue
Block a user