From 5c4509f9ea77aa0fa2d6da5ad403de2544681904 Mon Sep 17 00:00:00 2001 From: Thomas Ubensee <34603111+tomuben@users.noreply.github.com> Date: Thu, 17 Oct 2024 14:06:37 -0300 Subject: [PATCH] Test for DNS resolution --- .github/workflows/ci.yml | 45 ++++++++++++------ .../test_itde_manager_in_docker_container.py | 46 +++++++++++++++++++ 2 files changed, 76 insertions(+), 15 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 86f27c8..0dfaf78 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -1,22 +1,37 @@ -name: CI +name: Checks on: + pull_request: push: - branches-ignore: - - "github-pages/*" - - "gh-pages/*" - - "main" - - "master" - schedule: - # “At 00:00 on every 7th day-of-month from 1 through 31.” (https://crontab.guru) - - cron: "0 0 1/7 * *" jobs: + tests-job: + name: Tests + runs-on: ubuntu-latest + strategy: + fail-fast: false - ci-job: - name: Checks - uses: ./.github/workflows/checks.yml + steps: + - name: SCM Checkout + uses: actions/checkout@v4 + - name: Free disk space + uses: jlumbroso/free-disk-space@main + with: + tool-cache: true + large-packages: false - metrics: - needs: [ ci-job ] - uses: ./.github/workflows/report.yml + - name: Free disk space by removing large directories + run: | + sudo rm -rf /usr/local/graalvm/ + sudo rm -rf /usr/local/.ghcup/ + sudo rm -rf /usr/local/share/powershell + sudo rm -rf /usr/local/share/chromium + sudo rm -rf /usr/local/lib/node_modules + sudo rm -rf /opt/ghc + - name: Setup Python & Poetry Environment + uses: exasol/python-toolbox/.github/actions/python-environment@0.14.0 + with: + python-version: '3.10' + + - name: Calculate Test Coverage + run: poetry run pytest test/test_itde_manager_in_docker_container.py diff --git a/test/integration/test_itde_manager_in_docker_container.py b/test/integration/test_itde_manager_in_docker_container.py index 76003c5..7a6a094 100644 --- a/test/integration/test_itde_manager_in_docker_container.py +++ b/test/integration/test_itde_manager_in_docker_container.py @@ -127,6 +127,52 @@ def run_test(): return source_code +@pytest.fixture +def itde_connect_test_impl_dns(): + """ + This fixture returns the test source code for starting up ITDE,connecting to it and let the DB execute a UDF which requires proper internet access. + The source code needs to appended to the wheel file inside the Docker container called TEST_CONTAINER. + """ + + def run_test(): + from pathlib import Path + + from exasol.nb_connector.ai_lab_config import AILabConfig + from exasol.nb_connector.connections import open_pyexasol_connection + from exasol.nb_connector.itde_manager import bring_itde_up + from exasol.nb_connector.itde_manager import take_itde_down + from exasol.nb_connector.secret_store import Secrets + import requests + + requests.get("https://example.com/") + secrets = Secrets(db_file=Path("secrets.sqlcipher"), master_password="test") + secrets.save(AILabConfig.mem_size.value, "2") + secrets.save(AILabConfig.disk_size.value, "4") + + bring_itde_up(secrets) + try: + con = open_pyexasol_connection(secrets) + try: + udf = textwrap.dedent(''' + CREATE OR REPLACE PYTHON SCALAR SCRIPT test_dns(dummy INTEGER) + RETURNS INTEGER AS + def run(ctx): + import requests + requests.get("https://example.com/") + return 1 + ''') + result = con.execute(udf).fetchmany() + assert result[0][0] == 1 + finally: + con.close() + finally: + take_itde_down(secrets) + + function_source_code = textwrap.dedent(dill.source.getsource(run_test)) + source_code = f"{function_source_code}\nrun_test()" + return source_code + + @pytest.fixture def itde_recreation_after_take_down(): """