Skip to content

Commit

Permalink
chore: stabilize MySQL tests by aligning isolation levels (#28028)
Browse files Browse the repository at this point in the history
  • Loading branch information
mistercrunch authored Apr 15, 2024
1 parent c225e17 commit de9daf7
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/bashlib.sh
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,8 @@ EOF
setup-mysql() {
say "::group::Initialize database"
mysql -h 127.0.0.1 -P 13306 -u root --password=root <<-EOF
SET GLOBAL transaction_isolation='READ-COMMITTED';
SET GLOBAL TRANSACTION ISOLATION LEVEL READ COMMITTED;
DROP DATABASE IF EXISTS superset;
CREATE DATABASE superset DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci;
DROP DATABASE IF EXISTS sqllab_test_db;
Expand Down
5 changes: 5 additions & 0 deletions .github/workflows/superset-python-integrationtest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@ jobs:
MYSQL_ROOT_PASSWORD: root
ports:
- 13306:3306
options: >-
--health-cmd="mysqladmin ping --silent"
--health-interval=10s
--health-timeout=5s
--health-retries=5
redis:
image: redis:7-alpine
options: --entrypoint redis-server
Expand Down
5 changes: 5 additions & 0 deletions tests/integration_tests/charts/data/api_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import copy
from datetime import datetime
from io import BytesIO
import time
from typing import Any, Optional
from unittest import mock
from zipfile import ZipFile
Expand Down Expand Up @@ -723,8 +724,12 @@ def test_chart_data_async(self):
app._got_first_request = False
async_query_manager_factory.init_app(app)
self.login(ADMIN_USERNAME)
# Introducing time.sleep to make test less flaky with MySQL
time.sleep(1)
rv = self.post_assert_metric(CHART_DATA_URI, self.query_context_payload, "data")
time.sleep(1)
self.assertEqual(rv.status_code, 202)
time.sleep(1)
data = json.loads(rv.data.decode("utf-8"))
keys = list(data.keys())
self.assertCountEqual(
Expand Down
4 changes: 4 additions & 0 deletions tests/integration_tests/query_context_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,8 +151,12 @@ def test_query_cache_key_changes_when_datasource_is_updated(self):
description_original = datasource.description
datasource.description = "temporary description"
db.session.commit()
# wait a second since mysql records timestamps in second granularity
time.sleep(1)
datasource.description = description_original
db.session.commit()
# wait another second because why not
time.sleep(1)

# create new QueryContext with unchanged attributes, extract new query_cache_key
query_context = ChartDataQueryContextSchema().load(payload)
Expand Down

0 comments on commit de9daf7

Please sign in to comment.