From fca40e4d5b2c872a573bbe0edc2894d1fc3d809b Mon Sep 17 00:00:00 2001 From: dgtlmoon Date: Wed, 31 Jan 2024 15:10:44 +0100 Subject: [PATCH] Testing - General test workflow improvements (#2144) --- .github/workflows/pypi-release.yml | 6 +++--- .github/workflows/test-only.yml | 28 ++++++++++++++++++++-------- changedetectionio/tests/test_api.py | 1 + 3 files changed, 24 insertions(+), 11 deletions(-) diff --git a/.github/workflows/pypi-release.yml b/.github/workflows/pypi-release.yml index 0f38941f..1b2ffb76 100644 --- a/.github/workflows/pypi-release.yml +++ b/.github/workflows/pypi-release.yml @@ -40,12 +40,12 @@ jobs: path: dist/ - name: Test that the basic pip built package runs without error run: | - set -e + set -ex pip3 install dist/changedetection.io*.whl changedetection.io -d /tmp -p 10000 & sleep 3 - curl http://127.0.0.1:10000/static/styles/pure-min.css >/dev/null - curl http://127.0.0.1:10000/ >/dev/null + curl --retry-connrefused --retry 6 http://127.0.0.1:10000/static/styles/pure-min.css >/dev/null + curl --retry-connrefused --retry 6 http://127.0.0.1:10000/ >/dev/null killall changedetection.io diff --git a/.github/workflows/test-only.yml b/.github/workflows/test-only.yml index 6f762437..f3fde056 100644 --- a/.github/workflows/test-only.yml +++ b/.github/workflows/test-only.yml @@ -27,7 +27,7 @@ jobs: run: | docker network create changedet-network - + # Selenium+browserless docker run --network changedet-network -d --hostname selenium -p 4444:4444 --rm --shm-size="2g" selenium/standalone-chrome:4 docker run --network changedet-network -d --name browserless --hostname browserless -e "FUNCTION_BUILT_INS=[\"fs\",\"crypto\"]" -e "DEFAULT_LAUNCH_ARGS=[\"--window-size=1920,1080\"]" --rm -p 3000:3000 --shm-size="2g" browserless/chrome:1.60-chrome-stable @@ -47,7 +47,7 @@ jobs: # Debug SMTP server/echo message back server docker run --network changedet-network -d -p 11025:11025 -p 11080:11080 --hostname mailserver test-changedetectionio bash -c 'python changedetectionio/tests/smtp/smtp-test-server.py' - - name: Test built container with pytest + - name: Test built container with Pytest (generally as requests/plaintext fetching) run: | # Unit tests echo "run test with unittest" @@ -61,20 +61,32 @@ jobs: # append the docker option. e.g. '-e LOGGER_LEVEL=DEBUG' docker run --network changedet-network test-changedetectionio bash -c 'cd changedetectionio && ./run_basic_tests.sh' - - name: Test built container selenium+browserless/playwright + - name: Specific tests in built container for Selenium run: | # Selenium fetch docker run --rm -e "WEBDRIVER_URL=http://selenium:4444/wd/hub" --network changedet-network test-changedetectionio bash -c 'cd changedetectionio;pytest tests/fetchers/test_content.py && pytest tests/test_errorhandling.py' - + + - name: Specific tests in built container for Playwright + run: | # Playwright/Browserless fetch docker run --rm -e "PLAYWRIGHT_DRIVER_URL=ws://browserless:3000" --network changedet-network test-changedetectionio bash -c 'cd changedetectionio;pytest tests/fetchers/test_content.py && pytest tests/test_errorhandling.py && pytest tests/visualselector/test_fetch_data.py' - + + - name: Specific tests in built container for headers and requests checks with Playwright + run: | # Settings headers playwright tests - Call back in from Browserless, check headers docker run --name "changedet" --hostname changedet --rm -e "FLASK_SERVER_NAME=changedet" -e "PLAYWRIGHT_DRIVER_URL=ws://browserless:3000?dumpio=true" --network changedet-network test-changedetectionio bash -c 'cd changedetectionio; pytest --live-server-host=0.0.0.0 --live-server-port=5004 tests/test_request.py' + + - name: Specific tests in built container for headers and requests checks with Selenium + run: | docker run --name "changedet" --hostname changedet --rm -e "FLASK_SERVER_NAME=changedet" -e "WEBDRIVER_URL=http://selenium:4444/wd/hub" --network changedet-network test-changedetectionio bash -c 'cd changedetectionio; pytest --live-server-host=0.0.0.0 --live-server-port=5004 tests/test_request.py' + + - name: Specific tests in built container with Playwright as Puppeteer experimental fetcher + run: | docker run --name "changedet" --hostname changedet --rm -e "FLASK_SERVER_NAME=changedet" -e "USE_EXPERIMENTAL_PUPPETEER_FETCH=yes" -e "PLAYWRIGHT_DRIVER_URL=ws://browserless:3000?dumpio=true" --network changedet-network test-changedetectionio bash -c 'cd changedetectionio; pytest --live-server-host=0.0.0.0 --live-server-port=5004 tests/test_request.py' - + + - name: Test built container restock detection via Playwright + run: | # restock detection via playwright - added name=changedet here so that playwright/browserless can connect to it docker run --rm --name "changedet" -e "FLASK_SERVER_NAME=changedet" -e "PLAYWRIGHT_DRIVER_URL=ws://browserless:3000" --network changedet-network test-changedetectionio bash -c 'cd changedetectionio;pytest --live-server-port=5004 --live-server-host=0.0.0.0 tests/restock/test_restock.py' @@ -106,10 +118,10 @@ jobs: docker run --name test-changedetectionio -p 5556:5000 -d test-changedetectionio sleep 3 # Should return 0 (no error) when grep finds it - curl -s http://localhost:5556 |grep -q checkbox-uuid + curl --retry-connrefused --retry 6 -s http://localhost:5556 |grep -q checkbox-uuid # and IPv6 - curl -s -g -6 "http://[::1]:5556"|grep -q checkbox-uuid + curl --retry-connrefused --retry 6 -s -g -6 "http://[::1]:5556"|grep -q checkbox-uuid # Check whether TRACE log is enabled. # Also, check whether TRACE is came from STDERR diff --git a/changedetectionio/tests/test_api.py b/changedetectionio/tests/test_api.py index d83ababa..5be55ec2 100644 --- a/changedetectionio/tests/test_api.py +++ b/changedetectionio/tests/test_api.py @@ -163,6 +163,7 @@ def test_api_simple(client, live_server): # Loading the most recent snapshot should force viewed to become true client.get(url_for("diff_history_page", uuid="first"), follow_redirects=True) + time.sleep(3) # Fetch the whole watch again, viewed should be true res = client.get( url_for("watch", uuid=watch_uuid),