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.
This commit is contained in:
Owais Lone
2021-10-12 20:49:13 +05:30
committed by GitHub
parent cc2e7d276b
commit b41a91713e
3 changed files with 20 additions and 13 deletions

View File

@ -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

View File

@ -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()

View File

@ -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