Skip to content

Commit

Permalink
[ci] Add simple Playwright parallel tests connect to autoscaling Grid…
Browse files Browse the repository at this point in the history
… in K8s (#2409)

Signed-off-by: Viet Nguyen Duc <nguyenducviet4496@gmail.com>
  • Loading branch information
VietND96 authored Sep 24, 2024
1 parent dedd69b commit e61f20c
Show file tree
Hide file tree
Showing 11 changed files with 205 additions and 30 deletions.
45 changes: 35 additions & 10 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,25 @@ version: 2.1
workflows:
build-and-test-multi-arch:
jobs:
- kubernetes-test:
name: "K8s test - Playwright Connect Autoscaling Grid"
platforms: linux/arm64
machine-type: ubuntu2204arm64large
k8s-version: 'v1.25.16'
test-strategy: playwright_connect_grid
cluster: 'minikube'
helm-version: 'v3.10.3'
docker-version: '24.0.9'
test-upgrade: true
- kubernetes-test:
name: "K8s test - Autoscaling disabled"
platforms: linux/arm64
machine-type: ubuntu2204arm64large
k8s-version: 'v1.26.15'
test-strategy: disabled
cluster: 'minikube'
helm-version: 'v3.10.3'
helm-version: 'v3.11.3'
docker-version: '24.0.9'
test-upgrade: true
- kubernetes-test:
name: "K8s test - Autoscaling Jobs"
Expand All @@ -19,43 +30,48 @@ workflows:
k8s-version: 'v1.27.16'
test-strategy: job
cluster: 'minikube'
helm-version: 'v3.11.3'
helm-version: 'v3.12.3'
docker-version: '24.0.9'
test-upgrade: true
- kubernetes-test:
name: "K8s test - Autoscaling Deployments"
platforms: linux/arm64
machine-type: ubuntu2204arm64large
k8s-version: 'v1.28.13'
k8s-version: 'v1.28.14'
test-strategy: deployment
cluster: 'minikube'
helm-version: 'v3.12.3'
helm-version: 'v3.13.3'
docker-version: '24.0.9'
test-upgrade: true
- kubernetes-test:
name: "K8s test - Autoscaling Jobs - HTTPS"
platforms: linux/arm64
machine-type: ubuntu2204arm64large
k8s-version: 'v1.29.8'
k8s-version: 'v1.29.9'
test-strategy: job_https
cluster: 'minikube'
helm-version: 'v3.13.3'
helm-version: 'v3.14.3'
docker-version: '25.0.5'
test-upgrade: true
- kubernetes-test:
name: "K8s test - Autoscaling Jobs - Ingress hostname"
platforms: linux/arm64
machine-type: ubuntu2204arm64large
k8s-version: 'v1.30.4'
k8s-version: 'v1.30.5'
test-strategy: job_hostname
cluster: 'minikube'
helm-version: 'v3.14.4'
helm-version: 'v3.15.4'
docker-version: '26.1.4'
test-upgrade: true
- kubernetes-test:
name: "K8s test - Autoscaling Deployments - HTTPS"
platforms: linux/arm64
machine-type: ubuntu2204arm64large
k8s-version: 'v1.31.0'
k8s-version: 'v1.31.1'
test-strategy: deployment_https
cluster: 'minikube'
helm-version: 'v3.15.4'
helm-version: 'v3.16.1'
docker-version: '27.2.0'
test-upgrade: true
- docker-test:
name: "Docker test - Use random user (true)"
Expand Down Expand Up @@ -206,6 +222,8 @@ jobs:
type: string
helm-version:
type: string
docker-version:
type: string
test-upgrade:
type: boolean
executor: << parameters.machine-type >>
Expand All @@ -217,6 +235,7 @@ jobs:
CLUSTER: << parameters.cluster >>
KUBERNETES_VERSION: << parameters.k8s-version >>
HELM_VERSION: << parameters.helm-version >>
DOCKER_VERSION: << parameters.docker-version >>
TEST_UPGRADE_CHART: << parameters.test-upgrade >>
steps:
- run:
Expand Down Expand Up @@ -266,14 +285,20 @@ jobs:
name: "Test Selenium Grid on Kubernetes"
no_output_timeout: 30m
command: |
if [ "${TEST_STRATEGY}" == "playwright_connect_grid" ]; then
PLATFORMS=${PLATFORMS} NAME=${IMAGE_REGISTRY} VERSION=${BRANCH} BUILD_DATE=${BUILD_DATE} TEST_UPGRADE_CHART=false make chart_test_autoscaling_${TEST_STRATEGY} && make test_video_integrity
exit $?
fi
N=3
while [ $N -gt 0 ]; do
output=$(eval "PLATFORMS=${PLATFORMS} NAME=${IMAGE_REGISTRY} VERSION=${BRANCH} BUILD_DATE=${BUILD_DATE} TEST_UPGRADE_CHART=false make chart_test_autoscaling_${TEST_STRATEGY} && make test_video_integrity")
status=$?
if [ $status -eq 0 ]; then
echo "${output}"
echo "Tests passed"
exit 0
else
echo "${output}"
echo "Tests failed. Retrying..."
N=$((N-1))
sleep 10
Expand Down
26 changes: 16 additions & 10 deletions .github/workflows/helm-chart-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,40 +34,46 @@ jobs:
fail-fast: false
matrix:
include:
- k8s-version: 'v1.25.16'
test-strategy: playwright_connect_grid
cluster: 'minikube'
helm-version: 'v3.10.3'
docker-version: '24.0.9'
test-upgrade: true
- k8s-version: 'v1.26.15'
test-strategy: disabled
cluster: 'minikube'
helm-version: 'v3.10.3'
helm-version: 'v3.11.3'
docker-version: '24.0.9'
test-upgrade: true
- k8s-version: 'v1.27.16'
test-strategy: job
cluster: 'minikube'
helm-version: 'v3.11.3'
helm-version: 'v3.12.3'
docker-version: '24.0.9'
test-upgrade: true
- k8s-version: 'v1.28.13'
- k8s-version: 'v1.28.14'
test-strategy: deployment
cluster: 'minikube'
helm-version: 'v3.12.3'
helm-version: 'v3.13.3'
docker-version: '24.0.9'
test-upgrade: true
- k8s-version: 'v1.29.8'
- k8s-version: 'v1.29.9'
test-strategy: job_https
cluster: 'minikube'
helm-version: 'v3.13.3'
helm-version: 'v3.14.3'
docker-version: '25.0.5'
test-upgrade: true
- k8s-version: 'v1.30.4'
- k8s-version: 'v1.30.5'
test-strategy: job_hostname
cluster: 'minikube'
helm-version: 'v3.14.4'
helm-version: 'v3.15.4'
docker-version: '26.1.4'
test-upgrade: true
- k8s-version: 'v1.31.0'
- k8s-version: 'v1.31.1'
test-strategy: deployment_https
cluster: 'minikube'
helm-version: 'v3.15.4'
helm-version: 'v3.16.1'
docker-version: '27.2.0'
test-upgrade: true
env:
Expand Down
2 changes: 2 additions & 0 deletions .keda/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ If you are deploying KEDA core using their official Helm [chart](https://github.
If you are deployment Selenium Grid chart with `autoscaling.enabled` is `true` (implies installing KEDA sub-chart), KEDA images registry and tag already set in the `values.yaml`. Refer to list [configuration](../charts/selenium-grid/CONFIGURATION.md).

If you want to disable default patched KEDA image tags in Selenium Grid chart, you can set via Helm CLI `--set keda.image=null` or the same in values file.

# Pull requests under testing

Here is list of pull requests that are under testing and will be merged to the upstream KEDA repository.
Expand Down
10 changes: 5 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -948,12 +948,12 @@ chart_test_autoscaling_job:
TEMPLATE_OUTPUT_FILENAME="k8s_fullDistributed_secureIngress_externalCerts_ingressHostName_ingressTLSInline_autoScaling_scaledJob_existingKEDA_prefixSelenium_nodeChromium_enableTracing.yaml" \
./tests/charts/make/chart_test.sh JobAutoscaling

chart_test_language_bindings:
PLATFORMS=$(PLATFORMS) \
SELENIUM_GRID_HOST=$$(hostname -i) \
SELENIUM_GRID_AUTOSCALING_MIN_REPLICA=1 \
chart_test_autoscaling_playwright_connect_grid:
PLATFORMS=$(PLATFORMS) CHART_ENABLE_TRACING=true CHART_ENABLE_BASIC_AUTH=true MATRIX_TESTS=CDPTests \
SECURE_INGRESS_ONLY_DEFAULT=true SECURE_USE_EXTERNAL_CERT=true SELENIUM_GRID_PROTOCOL=https SELENIUM_GRID_HOST=$$(hostname -i) SELENIUM_GRID_PORT=443 \
VERSION=$(TAG_VERSION) VIDEO_TAG=$(FFMPEG_TAG_VERSION)-$(BUILD_DATE) KEDA_BASED_NAME=$(KEDA_BASED_NAME) KEDA_BASED_TAG=$(KEDA_BASED_TAG) NAMESPACE=$(NAMESPACE) BINDING_VERSION=$(BINDING_VERSION) \
./tests/charts/make/chart_test.sh DeploymentAutoscaling
TEMPLATE_OUTPUT_FILENAME="k8s_playwright_connect_grid_basicAuth_secureIngress_ingressPublicIP_autoScaling.yaml" \
./tests/charts/make/chart_test.sh JobAutoscaling

chart_test_delete:
helm del test -n selenium || true
Expand Down
8 changes: 8 additions & 0 deletions tests/CDPTests/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
node_modules/
/test-results/
/playwright-report/
/playwright/.cache/
.idea/
.vscode/
jsonReports/
package-lock.json
28 changes: 28 additions & 0 deletions tests/CDPTests/bootstrap.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#!/usr/bin/env bash

cd tests/CDPTests || true

npm install
npx playwright install --force chromium

BROWSER=${1:-"chrome"}

SELENIUM_REMOTE_URL="${SELENIUM_GRID_PROTOCOL}://${SELENIUM_GRID_HOST}:${SELENIUM_GRID_PORT}"
echo "SELENIUM_REMOTE_URL=${SELENIUM_REMOTE_URL}" > .env

if [ -n ${SELENIUM_GRID_USERNAME} ] && [ -n ${SELENIUM_GRID_PASSWORD} ]; then
BASIC_AUTH="$(echo -n "${SELENIUM_GRID_USERNAME}:${SELENIUM_GRID_PASSWORD}" | base64)"
echo "SELENIUM_REMOTE_HEADERS={\"Authorization\": \"Basic ${BASIC_AUTH}\"}" >> .env
fi

echo "SELENIUM_REMOTE_CAPABILITIES={\"browserName\": \"${BROWSER}\"}" >> .env
echo "NODE_EXTRA_CA_CERTS=${CHART_CERT_PATH}" >> .env

cat .env

until [ "$(curl --noproxy "*" -sk -H "Authorization: Basic ${BASIC_AUTH}" -o /dev/null -w "%{http_code}" "${SELENIUM_REMOTE_URL}/status")" = "200" ]; do
echo "Waiting for Grid to be ready..."
sleep 1
done

npx playwright test
21 changes: 21 additions & 0 deletions tests/CDPTests/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"name": "CDPTests",
"version": "1.47.2",
"main": "index.js",
"scripts": {},
"keywords": [],
"author": "",
"license": "ISC",
"devDependencies": {
"@playwright/test": "^1.47.2"
},
"directories": {
"test": "tests"
},
"dependencies": {
"dotenv": "^16.3.1",
"express": "^4.18.2",
"playwright-core": "^1.47.2"
},
"description": ""
}
22 changes: 22 additions & 0 deletions tests/CDPTests/playwright.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import type {PlaywrightTestConfig} from '@playwright/test';
import * as dotenv from 'dotenv';

dotenv.config();

const config: PlaywrightTestConfig = {
timeout: 1500000,
testMatch: ["tests/*.ts"],
use: {
headless: false,
screenshot: "on",
video: "on"
},
reporter: [["dot"], ["json", {
outputFile: "jsonReports/jsonReport.json"
}], ["html", {
open: "never"
}]],
workers: 5
};

export default config;
50 changes: 50 additions & 0 deletions tests/CDPTests/tests/Tests.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
const {test, expect} = require('@playwright/test');
const path = require('path');

function sleep(ms: number) {
return new Promise(resolve => setTimeout(resolve, ms));
}

test.describe.parallel('Parallel tests connect to autoscaling Grid', () => {
test('test_title', async ({page}) => {
await page.goto('https://the-internet.herokuapp.com');
await expect(page).toHaveTitle('The Internet');
await sleep(2);
});

test('test_with_frames', async ({page}) => {
await page.goto('http://the-internet.herokuapp.com/nested_frames');
const frame = page.frameLocator('frame[name="frame-top"]').frameLocator('frame[name="frame-middle"]');
await expect(frame.locator('#content')).toHaveText('MIDDLE');
await sleep(2);
});

test('test_select_from_a_dropdown', async ({page}) => {
await page.goto('http://the-internet.herokuapp.com/dropdown');
const dropdown = await page.locator('#dropdown');
await dropdown.selectOption({label: 'Option 1'});
const selectedOption = await dropdown.inputValue();
expect(selectedOption).toBe('1');
await sleep(2);
});

test('test_visit_basic_auth_secured_page', async ({page}) => {
await page.goto('http://admin:admin@the-internet.herokuapp.com/basic_auth');
const pageMessage = await page.locator('.example p').textContent();
expect(pageMessage.trim()).toBe('Congratulations! You must have the proper credentials.');
await sleep(2);
});

test('test_download_file', async ({page}) => {
await page.goto('https://the-internet.herokuapp.com/download');
const fileLink = page.locator('a', {hasText: 'some-file.txt'});
await fileLink.scrollIntoViewIfNeeded();
const [download] = await Promise.all([
page.waitForEvent('download'),
fileLink.click()
]);
const fileName = download.suggestedFilename();
expect(fileName).toBe('some-file.txt');
await sleep(2);
});
});
14 changes: 12 additions & 2 deletions tests/charts/make/chart_setup_env.sh
Original file line number Diff line number Diff line change
Expand Up @@ -161,8 +161,9 @@ rm -rf ct.tar.gz
ct version
echo "==============================="
echo "Installing helm-docs for AMD64 / ARM64"
go install github.com/norwoodj/helm-docs/cmd/helm-docs@latest
$HOME/go/bin/helm-docs -h
mkdir -p $HOME/go/bin
GOBIN=$HOME/go/bin go install github.com/norwoodj/helm-docs/cmd/helm-docs@latest
$HOME/go/bin/helm-docs -h || true
echo "==============================="
echo "Installing envsubst for AMD64 / ARM64"
ENVSUBST_VERSION="v1.4.2"
Expand All @@ -172,3 +173,12 @@ chmod +x envsubst
sudo mv envsubst /usr/local/bin
sudo ln -sf /usr/local/bin/envsubst /usr/bin/envsubst
echo "==============================="
echo "Installing Node for AMD64 / ARM64"
curl -o- https://raw.github.com/nvm-sh/nvm/v0.40.0/install.sh | bash
export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"
[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion"
source $HOME/.bashrc
nvm install --lts
node --version
npm --version
9 changes: 6 additions & 3 deletions tests/charts/make/chart_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -354,9 +354,7 @@ elif [ "${TEST_EXISTING_KEDA}" != "true" ]; then
"
else
HELM_COMMAND_SET_IMAGES="${HELM_COMMAND_SET_IMAGES} \
--set keda.image.keda.registry=null --set keda.image.keda.repository=null --set keda.image.keda.tag=null \
--set keda.image.metricsApiServer.registry=null --set keda.image.metricsApiServer.repository=null --set keda.image.metricsApiServer.tag=null \
--set keda.image.webhooks.registry=null --set keda.image.webhooks.repository=null --set keda.image.webhooks.tag=null \
--set keda.image=null \
"
fi
fi
Expand Down Expand Up @@ -411,6 +409,11 @@ if [ "${MATRIX_BROWSER}" = "NoAutoscaling" ]; then
else
./tests/bootstrap.sh NodeChromium
fi
elif [ "${MATRIX_TESTS}" = "CDPTests" ]; then
./tests/CDPTests/bootstrap.sh "chrome"
if [ "${TEST_PLATFORMS}" = "linux/amd64" ]; then
./tests/CDPTests/bootstrap.sh "MicrosoftEdge"
fi
else
./tests/bootstrap.sh ${MATRIX_BROWSER}
fi
Expand Down

0 comments on commit e61f20c

Please sign in to comment.