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:
2026-03-06 15:03:21 -05:00
parent ec4b598728
commit 4ea4393344
2 changed files with 10 additions and 46 deletions
+3 -20
View File
@@ -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