diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index fb434133..dfb88ef5 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -266,6 +266,54 @@ jobs: max_attempts: 3 retry_wait_seconds: 30 command: rad deploy ${{ matrix.path }} ${{ matrix.deployArgs }} + - name: Wait for all pods to be ready + if: steps.gen-id.outputs.RUN_TEST == 'true' + id: wait-for-pods + run: | + namespace="${{ matrix.env }}-${{ matrix.app }}" + label="radapp.io/application=${{ matrix.app }}" + kubectl rollout status deployment -l $label -n $namespace --timeout=90s + # Verify endpoint reachability + - name: Verify endpoint reachability + if: steps.gen-id.outputs.RUN_TEST == 'true' && matrix.container == '' + run: | + # Extract the endpoint using rad app status + endpoint=$(rad app status -a ${{ matrix.app }} | sed 's/ /\n/g' | grep http) + if [ -z "$endpoint" ]; then + echo "Error: Could not extract endpoint from rad app status" + exit 1 + fi + echo "Extracted endpoint: $endpoint" + # Extract hostname and port from the endpoint + hostname=$(echo $endpoint | awk -F[/:] '{print $4}') + port=$(echo $endpoint | awk -F[/:] '{print $5}') + port=${port:-80} # Default to 80 if port is not specified + + namespace="${{ matrix.env }}-${{ matrix.app }}" + if [ "$hostname" == "localhost" ]; then + hostname="${{ matrix.app }}.$namespace.svc.cluster.local" + echo "New hostname: $hostname" + fi + + echo "Verifying endpoint reachability: $hostname:$port" + + # Get the name of an existing pod and use Python for endpoint check + pod_name=$(kubectl get pods -n $namespace -l radapp.io/application=${{ matrix.app }} -o jsonpath='{.items[0].metadata.name}') + if [ -z "$pod_name" ]; then + echo "Error: No pods found for the application" + exit 1 + fi + echo "Using pod: $pod_name" + kubectl exec $pod_name -n $namespace -- python3 - <<-EOT + import socket, sys + hostname, port = '$hostname', $port + try: + with socket.create_connection((hostname, port), timeout=10): + print('Endpoint is reachable') + except Exception as e: + print(f'Error: Endpoint is not reachable. {e}') + sys.exit(1) + EOT - name: Run Playwright Test if: steps.gen-id.outputs.RUN_TEST == 'true' && matrix.uiTestFile != '' id: run-playwright-test diff --git a/playwright/playwright.config.ts b/playwright/playwright.config.ts index a44ba2e0..5c4cfc24 100644 --- a/playwright/playwright.config.ts +++ b/playwright/playwright.config.ts @@ -47,8 +47,8 @@ export default defineConfig({ use: { ...devices["Desktop Safari"] }, }, ], - timeout: 1 * 60 * 1000, + timeout: 2 * 60 * 1000, expect: { - timeout: 30 * 1000, + timeout: 60 * 1000, }, }); diff --git a/playwright/tests/eshop/eshop.app.spec.ts b/playwright/tests/eshop/eshop.app.spec.ts index 4340cc88..38bb61d3 100644 --- a/playwright/tests/eshop/eshop.app.spec.ts +++ b/playwright/tests/eshop/eshop.app.spec.ts @@ -1,4 +1,4 @@ -import { test, expect } from "@playwright/test"; +import { expect, test } from "@playwright/test"; test("eShop on Containers App Basic UI and Functionality Checks", async ({ page, @@ -17,17 +17,34 @@ test("eShop on Containers App Basic UI and Functionality Checks", async ({ let endpoint = process.env.ENDPOINT; expect(endpoint).toBeDefined(); - // Remove quotes from the endpoint if they exist - try { - endpoint = (endpoint as string).replace(/['"]+/g, ""); - log(`Navigating to the endpoint: ${endpoint}`); - await page.goto(endpoint); - } catch (error) { - console.error( - `Attempt ${testInfo.retry}: Failed to navigate to the endpoint:`, - error - ); - } +// Remove quotes from the endpoint if they exist +try { + endpoint = (endpoint as string).replace(/['"]+/g, ""); + log(`Endpoint after removing quotes: ${endpoint}`); +} catch (error) { + console.error(`Error processing the endpoint:`, error); +} + +// Check if the endpoint is reachable +try { + const response = await fetch(endpoint); + if (!response.ok) throw new Error(`HTTP error! Status: ${response.status}`); + log(`Endpoint is reachable: ${endpoint}`); +} catch (error) { + console.error(`Failed to reach the endpoint:`, error); + return; +} + +// Navigate to the endpoint +try { + log(`Navigating to the endpoint: ${endpoint}`); + await page.goto(endpoint); +} catch (error) { + console.error( + `Attempt ${testInfo.retry}: Failed to navigate to the endpoint:`, + error + ); +} // Expect page to have proper URL log(`Checking the URL: ${endpoint}/catalog`); diff --git a/playwright/tests/util/helper.ts b/playwright/tests/util/helper.ts index 45a5b500..e8a3eeec 100644 --- a/playwright/tests/util/helper.ts +++ b/playwright/tests/util/helper.ts @@ -1,6 +1,6 @@ import axios from "axios"; -export async function waitForWebApp(url: string | undefined, timeout = 30000) { +export async function waitForWebApp(url: string | undefined, timeout = 60000) { if (!url) { throw new Error("URL is not defined"); }