You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@superset.apache.org by ma...@apache.org on 2024/04/15 22:49:15 UTC

(superset) branch master updated: chore: stabilize MySQL tests by aligning isolation levels (#28028)

This is an automated email from the ASF dual-hosted git repository.

maximebeauchemin pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/superset.git


The following commit(s) were added to refs/heads/master by this push:
     new de9daf7ad9 chore: stabilize MySQL tests by aligning isolation levels (#28028)
de9daf7ad9 is described below

commit de9daf7ad9b41e84ca7fc0d18dca5d2ba1ef5553
Author: Maxime Beauchemin <ma...@gmail.com>
AuthorDate: Mon Apr 15 15:49:09 2024 -0700

    chore: stabilize MySQL tests by aligning isolation levels (#28028)
---
 .github/workflows/bashlib.sh                          | 2 ++
 .github/workflows/superset-python-integrationtest.yml | 5 +++++
 tests/integration_tests/charts/data/api_tests.py      | 5 +++++
 tests/integration_tests/query_context_tests.py        | 4 ++++
 4 files changed, 16 insertions(+)

diff --git a/.github/workflows/bashlib.sh b/.github/workflows/bashlib.sh
index e34101ad78..3e407eb91d 100644
--- a/.github/workflows/bashlib.sh
+++ b/.github/workflows/bashlib.sh
@@ -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;
diff --git a/.github/workflows/superset-python-integrationtest.yml b/.github/workflows/superset-python-integrationtest.yml
index 2c1e721df4..8005e05595 100644
--- a/.github/workflows/superset-python-integrationtest.yml
+++ b/.github/workflows/superset-python-integrationtest.yml
@@ -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
diff --git a/tests/integration_tests/charts/data/api_tests.py b/tests/integration_tests/charts/data/api_tests.py
index 4eabd16eaa..061cdece50 100644
--- a/tests/integration_tests/charts/data/api_tests.py
+++ b/tests/integration_tests/charts/data/api_tests.py
@@ -21,6 +21,7 @@ import unittest
 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
@@ -723,8 +724,12 @@ class TestPostChartDataApi(BaseTestChartDataApi):
         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(
diff --git a/tests/integration_tests/query_context_tests.py b/tests/integration_tests/query_context_tests.py
index d36b6c85c1..6ad3c30cd0 100644
--- a/tests/integration_tests/query_context_tests.py
+++ b/tests/integration_tests/query_context_tests.py
@@ -151,8 +151,12 @@ class TestQueryContext(SupersetTestCase):
         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)