Skip to content

Commit b41a917

Browse files
authored
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.
1 parent cc2e7d2 commit b41a917

File tree

3 files changed

+20
-13
lines changed

3 files changed

+20
-13
lines changed

.github/workflows/test.yml

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -84,13 +84,6 @@ jobs:
8484
python-version: 3.9
8585
- name: Install tox
8686
run: pip install -U tox
87-
- name: Prep mssql driver
88-
if: ${{ matrix.tox-environment == 'docker-tests' }}
89-
run: |
90-
curl https://packages.microsoft.com/keys/microsoft.asc | sudo apt-key add -
91-
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"
92-
sudo apt-get update
93-
sudo ACCEPT_EULA=Y apt-get install -y msodbcsql17
9487
- name: Install libsnappy-dev
9588
if: ${{ matrix.tox-environment == 'lint' }}
9689
run: sudo apt-get install -y libsnappy-dev

tests/opentelemetry-docker-tests/tests/check_availability.py

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -110,14 +110,27 @@ def check_redis_connection():
110110
connection.hgetall("*")
111111

112112

113-
@retryable
114-
def check_mssql_connection():
113+
def new_mssql_connection() -> pyodbc.Connection:
115114
connection = pyodbc.connect(
116115
f"DRIVER={{ODBC Driver 17 for SQL Server}};SERVER={MSSQL_HOST},"
117-
f"{MSSQL_PORT};DATABASE={MSSQL_DB_NAME};UID={MSSQL_USER};"
118-
f"PWD={MSSQL_PASSWORD}"
116+
f"{MSSQL_PORT};DATABASE=master;UID={MSSQL_USER};"
117+
f"PWD={MSSQL_PASSWORD}",
118+
autocommit=True,
119119
)
120-
connection.close()
120+
return connection
121+
122+
123+
@retryable
124+
def check_mssql_connection():
125+
conn = new_mssql_connection()
126+
conn.close()
127+
128+
129+
def setup_mssql_db():
130+
conn = new_mssql_connection()
131+
cur = conn.cursor()
132+
cur.execute(f"CREATE DATABASE [{MSSQL_DB_NAME}]")
133+
conn.close()
121134

122135

123136
def check_docker_services_availability():
@@ -127,6 +140,7 @@ def check_docker_services_availability():
127140
check_postgres_connection()
128141
check_redis_connection()
129142
check_mssql_connection()
143+
setup_mssql_db()
130144

131145

132146
check_docker_services_availability()

tests/opentelemetry-docker-tests/tests/docker-compose.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,4 +46,4 @@ services:
4646
environment:
4747
ACCEPT_EULA: "Y"
4848
SA_PASSWORD: "yourStrong(!)Password"
49-
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"
49+
command: /opt/mssql/bin/sqlservr

0 commit comments

Comments
 (0)