From b41a91713efa584582b4a55676255cbac7f660e0 Mon Sep 17 00:00:00 2001 From: Owais Lone Date: Tue, 12 Oct 2021 20:49:13 +0530 Subject: [PATCH] Fix mssql docker tests v4 (#727) * Remove unneded CI steps These were not really needed and got in by mistake. * Fix broken mssql integration tests We were giving mssql server 10 seconds to start before creating the test database. It now takes Github CI more than 10 seconds to start the mssql server. Instead of increasing the leeway with guesses, this commit moves the creation of test database from docker compose to the python test suite. This allows the docker image to come up first and then create the DB inside the test suite with proper retry mechanism that is already in place. --- .github/workflows/test.yml | 7 ------ .../tests/check_availability.py | 24 +++++++++++++++---- .../tests/docker-compose.yml | 2 +- 3 files changed, 20 insertions(+), 13 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 13f9d4d76..066f95ea2 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -84,13 +84,6 @@ jobs: python-version: 3.9 - name: Install tox run: pip install -U tox - - name: Prep mssql driver - if: ${{ matrix.tox-environment == 'docker-tests' }} - run: | - curl https://packages.microsoft.com/keys/microsoft.asc | sudo apt-key add - - sudo sh -c "echo 'deb [arch=amd64,armhf,arm64] https://packages.microsoft.com/ubuntu/20.04/prod focal main' > /etc/apt/sources.list.d/mssql-release.list" - sudo apt-get update - sudo ACCEPT_EULA=Y apt-get install -y msodbcsql17 - name: Install libsnappy-dev if: ${{ matrix.tox-environment == 'lint' }} run: sudo apt-get install -y libsnappy-dev diff --git a/tests/opentelemetry-docker-tests/tests/check_availability.py b/tests/opentelemetry-docker-tests/tests/check_availability.py index 28cd47ab7..2ec8e4337 100644 --- a/tests/opentelemetry-docker-tests/tests/check_availability.py +++ b/tests/opentelemetry-docker-tests/tests/check_availability.py @@ -110,14 +110,27 @@ def check_redis_connection(): connection.hgetall("*") -@retryable -def check_mssql_connection(): +def new_mssql_connection() -> pyodbc.Connection: connection = pyodbc.connect( f"DRIVER={{ODBC Driver 17 for SQL Server}};SERVER={MSSQL_HOST}," - f"{MSSQL_PORT};DATABASE={MSSQL_DB_NAME};UID={MSSQL_USER};" - f"PWD={MSSQL_PASSWORD}" + f"{MSSQL_PORT};DATABASE=master;UID={MSSQL_USER};" + f"PWD={MSSQL_PASSWORD}", + autocommit=True, ) - connection.close() + return connection + + +@retryable +def check_mssql_connection(): + conn = new_mssql_connection() + conn.close() + + +def setup_mssql_db(): + conn = new_mssql_connection() + cur = conn.cursor() + cur.execute(f"CREATE DATABASE [{MSSQL_DB_NAME}]") + conn.close() def check_docker_services_availability(): @@ -127,6 +140,7 @@ def check_docker_services_availability(): check_postgres_connection() check_redis_connection() check_mssql_connection() + setup_mssql_db() check_docker_services_availability() diff --git a/tests/opentelemetry-docker-tests/tests/docker-compose.yml b/tests/opentelemetry-docker-tests/tests/docker-compose.yml index 047a27177..8a33adb79 100644 --- a/tests/opentelemetry-docker-tests/tests/docker-compose.yml +++ b/tests/opentelemetry-docker-tests/tests/docker-compose.yml @@ -46,4 +46,4 @@ services: environment: ACCEPT_EULA: "Y" SA_PASSWORD: "yourStrong(!)Password" - command: /bin/sh -c "sleep 10s && /opt/mssql-tools/bin/sqlcmd -S localhost -U sa -P yourStrong\(!\)Password -d master -Q 'CREATE DATABASE [opentelemetry-tests]' & /opt/mssql/bin/sqlservr" + command: /opt/mssql/bin/sqlservr