Skip to content

Commit

Permalink
bug(SeleniumHQ#1824): Container ENV SE_NODE_SESSION_TIMEOUT not take …
Browse files Browse the repository at this point in the history
…effect

Signed-off-by: Viet Nguyen Duc <nguyenducviet4496@gmail.com>
  • Loading branch information
VietND96 committed Dec 2, 2023
1 parent c2a5b66 commit e55fffc
Show file tree
Hide file tree
Showing 10 changed files with 101 additions and 31 deletions.
13 changes: 11 additions & 2 deletions .github/workflows/helm-chart-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ jobs:
run: |
echo "BUILD_DATE=$(date '+%Y%m%d')" >> $GITHUB_ENV
echo "IMAGE_REGISTRY=artifactory/selenium" >> $GITHUB_ENV
- name: Build and lint charts
run: |
VERSION=${BRANCH} BUILD_DATE=${BUILD_DATE} make chart_build
echo "CHART_PACKAGE_PATH=$(cat /tmp/selenium_chart_version)" >> $GITHUB_ENV
- name: Build Docker images
run: NAME=${IMAGE_REGISTRY} VERSION=${BRANCH} BUILD_DATE=${BUILD_DATE} make build
- name: Setup Kubernetes environment
Expand All @@ -46,10 +50,15 @@ jobs:
- name: Test Selenium Grid on Kubernetes
uses: nick-invision/retry@v2.9.0
with:
timeout_minutes: 20
max_attempts: 3
timeout_minutes: 30
max_attempts: 2
command: |
NAME=${IMAGE_REGISTRY} VERSION=${BRANCH} BUILD_DATE=${BUILD_DATE} make chart_test
- name: Cleanup Kubernetes cluster
if: always()
run: make chart_cluster_cleanup
- name: Upload Helm chart package
uses: actions/upload-artifact@v3
with:
name: selenium_grid_chart_package
path: ${{ env.CHART_PACKAGE_PATH }}
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -149,3 +149,4 @@ ENV/
.DS_Store
/charts/*/charts
/charts/*/**.lock
/charts/*.tgz
41 changes: 22 additions & 19 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -366,32 +366,35 @@ test_video: video hub chrome firefox edge
chart_setup_env:
./tests/charts/make/chart_setup_env.sh

chart_test: chart_lint \
chart_test_template \
chart_install_chrome \
chart_install_firefox \
chart_install_edge

chart_test_template:
./tests/charts/bootstrap.sh

chart_cluster_setup:
VERSION=$(TAG_VERSION) NAMESPACE=$(NAMESPACE) ./tests/charts/make/chart_cluster_setup.sh

chart_lint:
./tests/charts/make/chart_lint.sh
chart_cluster_cleanup:
./tests/charts/make/chart_cluster_cleanup.sh

chart_install_chrome:
VERSION=$(TAG_VERSION) NAMESPACE=$(NAMESPACE) ./tests/charts/make/chart_install.sh NodeChrome
chart_build:
VERSION=$(TAG_VERSION) ./tests/charts/make/chart_build.sh

chart_install_firefox:
VERSION=$(TAG_VERSION) NAMESPACE=$(NAMESPACE) ./tests/charts/make/chart_install.sh NodeFirefox
chart_test: chart_test_template \
chart_test_node_session_timeout \
chart_test_chrome \
chart_test_firefox \
chart_test_edge

chart_install_edge:
VERSION=$(TAG_VERSION) NAMESPACE=$(NAMESPACE) ./tests/charts/make/chart_install.sh NodeEdge
chart_test_template:
./tests/charts/bootstrap.sh

chart_cluster_cleanup:
./tests/charts/make/chart_cluster_cleanup.sh
chart_test_chrome:
VERSION=$(TAG_VERSION) NAMESPACE=$(NAMESPACE) ./tests/charts/make/chart_test.sh NodeChrome

chart_test_firefox:
VERSION=$(TAG_VERSION) NAMESPACE=$(NAMESPACE) ./tests/charts/make/chart_test.sh NodeFirefox

chart_test_edge:
VERSION=$(TAG_VERSION) NAMESPACE=$(NAMESPACE) ./tests/charts/make/chart_test.sh NodeEdge

chart_test_node_session_timeout:
VERSION=$(TAG_VERSION) NAMESPACE=$(NAMESPACE) ./tests/charts/make/chart_test.sh NodeSessionTimeout

.PHONY: \
all \
Expand Down
6 changes: 6 additions & 0 deletions NodeBase/start-selenium-node.sh
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,12 @@ if [ ! -z "$SE_OPTS" ]; then
echo "Appending Selenium options: ${SE_OPTS}"
fi

# Workaround for issue #1824
if [ ! -z "$SE_NODE_SESSION_TIMEOUT" ]; then
SE_OPTS="$SE_OPTS --session-timeout $SE_NODE_SESSION_TIMEOUT"
echo "Appending Selenium node session timeout via SE_OPTS: ${SE_OPTS}"
fi

if [ "$GENERATE_CONFIG" = true ]; then
echo "Generating Selenium Config"
/opt/bin/generate_config
Expand Down
10 changes: 7 additions & 3 deletions charts/selenium-grid/TESTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ All related testing to this helm chart will be documented in this file.
| | Components are able to set `.affinity` | &check; | Template |
| Tracing | Enable tracing via `SE_ENABLE_TRACING` | &check; | Cluster |
| | Disable tracing via `SE_ENABLE_TRACING` | &cross; | |
| Container ENV vars | `SE_NODE_SESSION_TIMEOUT` pass value to opts `--session-timeout` | &check; | Cluster |

## Test Chart Template
- By using `helm template` command, the chart template is tested without installing it to Kubernetes cluster.
Expand All @@ -36,7 +37,7 @@ All related testing to this helm chart will be documented in this file.
cd ../..

# Build chart dependencies and lint
make chart_lint
make chart_build

# Test chart template
make chart_test_template
Expand All @@ -51,11 +52,14 @@ Run entire commands to build and test Docker images with Helm charts in local en
# Back to root directory
cd ../..

# Setup Kubernetes environment
make chart_setup_env

# Build Docker images
make build

# Setup Kubernetes environment
make chart_setup_env
# Build and lint charts
make chart_build

# Setup Kubernetes cluster
make chart_cluster_setup
Expand Down
20 changes: 20 additions & 0 deletions tests/SeleniumTests/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import unittest
import os
import time
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
Expand All @@ -11,6 +12,7 @@
SELENIUM_GRID_HOST = os.environ.get('SELENIUM_GRID_HOST', 'localhost')
SELENIUM_GRID_PORT = os.environ.get('SELENIUM_GRID_PORT', '4444')
WEB_DRIVER_WAIT_TIMEOUT = int(os.environ.get('WEB_DRIVER_WAIT_TIMEOUT', 60))
SE_NODE_SESSION_TIMEOUT = int(os.environ.get('SE_NODE_SESSION_TIMEOUT', 10))

class SeleniumGenericTests(unittest.TestCase):

Expand Down Expand Up @@ -113,3 +115,21 @@ def test_title_and_maximize_window(self):
self.driver.get('https://the-internet.herokuapp.com')
self.driver.maximize_window()
self.assertTrue(self.driver.title == 'The Internet')

class NodeSessionTimeoutTests(unittest.TestCase):
def setUp(self):
self.driver = webdriver.Remote(
options = ChromeOptions(),
command_executor="http://%s:%s" % (SELENIUM_GRID_HOST,SELENIUM_GRID_PORT)
)

def test_node_session_timeout(self):
self.driver.get('https://the-internet.herokuapp.com')
self.assertTrue(self.driver.title == 'The Internet')
time.sleep(SE_NODE_SESSION_TIMEOUT + 5)
is_timed_out = False
try:
self.driver.quit()
except:
is_timed_out = True
self.assertTrue(is_timed_out, "Node session should be timed out after %s seconds" % SE_NODE_SESSION_TIMEOUT)
11 changes: 11 additions & 0 deletions tests/charts/ci/NodeSessionTimeout-values.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
chromeNode:
nameOverride: my-chrome-name
extraEnvironmentVariables:
- name: SE_OPTS
value: "--enable-managed-downloads true"
- name: SE_NODE_SESSION_TIMEOUT
value: "10"
edgeNode:
enabled: false
firefoxNode:
enabled: false
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
#!/bin/bash

CHART_PATH=${CHART_PATH:-"charts/selenium-grid"}
# Function to be executed on command failure
on_failure() {
local exit_status=$?
Expand All @@ -22,8 +24,14 @@ python -m pip install yamale==4.0.4 \
| grep -v 'Requirement already satisfied'

cd ..
rm -rf ./charts/**/Chart.lock
rm -rf ${CHART_PATH}/Chart.lock
ct lint --all --config tests/charts/config/ct.yaml
# Helm dependencies build and lint is done by `ct lint` command
rm -rf ${CHART_PATH}/../*.tgz
helm package ${CHART_PATH} --version ${VERSION} --destination ${CHART_PATH}/..

readlink -f ${CHART_PATH}/../*.tgz > /tmp/selenium_chart_version
cat /tmp/selenium_chart_version

if [ "${CI:-false}" = "false" ]; then
deactivate
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,19 @@ on_failure() {
# Trap ERR signal and call on_failure function
trap 'on_failure' ERR

HELM_COMMAND_SET_AUTOSCALING=""
if [ "${SELENIUM_GRID_AUTOSCALING}" = "true" ]; then
HELM_COMMAND_SET_AUTOSCALING="--values ${TEST_VALUES_PATH}/autoscaling-values.yaml \
--set autoscaling.enableWithExistingKEDA=${SELENIUM_GRID_AUTOSCALING} \
--set autoscaling.scaledOptions.minReplicaCount=${SELENIUM_GRID_AUTOSCALING_MIN_REPLICA}"
fi

echo "Deploy Selenium Grid Chart"
helm upgrade --install ${RELEASE_NAME} \
-f ${TEST_VALUES_PATH}/auth-ingress-values.yaml \
-f ${TEST_VALUES_PATH}/tracing-values.yaml \
-f ${TEST_VALUES_PATH}/${MATRIX_BROWSER}-values.yaml \
-f ${TEST_VALUES_PATH}/autoscaling-values.yaml \
--set autoscaling.enableWithExistingKEDA=${SELENIUM_GRID_AUTOSCALING} \
--set autoscaling.scaledOptions.minReplicaCount=${SELENIUM_GRID_AUTOSCALING_MIN_REPLICA} \
--values ${TEST_VALUES_PATH}/auth-ingress-values.yaml \
--values ${TEST_VALUES_PATH}/tracing-values.yaml \
--values ${TEST_VALUES_PATH}/${MATRIX_BROWSER}-values.yaml \
${HELM_COMMAND_SET_AUTOSCALING} \
--set global.seleniumGrid.imageTag=${VERSION} --set global.seleniumGrid.imageRegistry=${NAMESPACE} \
--set global.seleniumGrid.nodesImageTag=${VERSION} \
${CHART_PATH} --namespace ${SELENIUM_NAMESPACE} --create-namespace
Expand Down
3 changes: 3 additions & 0 deletions tests/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@
# Firefox Images
'NodeFirefox': 'FirefoxTests',
'StandaloneFirefox': 'FirefoxTests',

# Container Env Vars
'NodeSessionTimeout': 'NodeSessionTimeoutTests'
}

FROM_IMAGE_ARGS = {
Expand Down

0 comments on commit e55fffc

Please sign in to comment.