Procházet zdrojové kódy

chore: Improve dashboard test reliability in publish workflow (#4122)

Michael Bromley před 14 hodinami
rodič
revize
143edae21a

+ 25 - 6
.github/workflows/publish_and_install.yml

@@ -86,6 +86,18 @@ jobs:
                   cd $HOME/install/test-app
                   npm run dev &
                   node $GITHUB_WORKSPACE/.github/workflows/scripts/smoke-tests
+            - name: Kill dev server after smoke tests
+              shell: bash
+              run: |
+                  # Kill everything on port 3000 so dashboard tests can start fresh
+                  # (npm run dev spawns child processes that aren't killed by killing the parent)
+                  if [[ "$RUNNER_OS" == "Windows" ]]; then
+                      # Windows: use netstat to find PID and taskkill
+                      netstat -ano | grep ':3000' | grep 'LISTENING' | awk '{print $5}' | head -1 | xargs -r taskkill //F //PID 2>/dev/null || true
+                  else
+                      # Linux/macOS: use lsof
+                      lsof -ti:3000 | xargs kill 2>/dev/null || true
+                  fi
             - name: Copy files (Windows)
               if: runner.os == 'Windows'
               shell: pwsh
@@ -120,13 +132,20 @@ jobs:
                 # start the dev server in the background
                 npm run dev &
                 DEV_PID=$!
-                # Wait a moment for it to start
-                sleep 5
-                # Start the dashboard in the background
-                npx vite --port 5173 &
+                # Wait for the dev server to be available (use /health endpoint, not root)
+                wait-on http://localhost:3000/health --timeout 60000
+                # Start the dashboard with --strictPort to fail fast if port is in use
+                npx vite --port 5173 --strictPort &
                 DASHBOARD_PID=$!
-                # Wait a moment for it to start
-                sleep 5
+                # Give Vite a moment to start or fail
+                sleep 3
+                # Check if Vite process is still running (it will exit immediately if port is in use)
+                if ! kill -0 $DASHBOARD_PID 2>/dev/null; then
+                    echo "Vite failed to start - port 5173 may be in use"
+                    exit 1
+                fi
+                # Wait for the dashboard to be available
+                wait-on http://localhost:5173 --timeout 120000
                 # Run the dashboard tests
                 node $GITHUB_WORKSPACE/.github/workflows/scripts/dashboard-tests.js
                 # Clean up dashboard process

+ 2 - 28
.github/workflows/scripts/dashboard-tests.js

@@ -184,37 +184,11 @@ async function runDashboardTests() {
     }
 }
 
-// Wait for the dashboard to be available
-async function awaitDashboardStartup() {
-    console.log('Checking for availability of Dashboard...');
-    let attempts = 0;
-    const maxAttempts = 30;
-
-    while (attempts < maxAttempts) {
-        try {
-            const response = await fetch('http://localhost:5173');
-            if (response.ok) {
-                console.log('Dashboard is running!');
-                return;
-            }
-        } catch (e) {
-            // Ignore errors and continue polling
-        }
-
-        attempts++;
-        if (attempts < maxAttempts) {
-            console.log('Dashboard not yet available, waiting 2s...');
-            await new Promise(resolve => setTimeout(resolve, 2000));
-        }
-    }
-
-    throw new Error('Unable to establish connection to Dashboard server!');
-}
-
 // Main execution
 async function main() {
     try {
-        await awaitDashboardStartup();
+        // Note: The workflow uses wait-on to ensure the dashboard is available
+        // before running this script, so we can proceed directly to tests
         await runDashboardTests();
         process.exit(0);
     } catch (error) {