Skip to content

Commit e5851b7

Browse files
committed
Wait until all users are created
Increase timeout time for individual tests. Do tests with Github runner + azure instance
1 parent 368a8d6 commit e5851b7

File tree

3 files changed

+58
-11
lines changed

3 files changed

+58
-11
lines changed

.github/workflows/test_cloud.yml

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@ name: "test_cloud"
33

44
on: # yamllint disable-line rule:truthy
55
pull_request:
6-
branches:
7-
- '*_cloud'
6+
branches: main
87
workflow_dispatch:
98
schedule:
109
- cron: '0 2 * * *' # Nightly run at 2:00 AM UTC
@@ -13,32 +12,33 @@ jobs:
1312
cloud_smt_tests:
1413
name: ClickHouse Cloud SharedMergeTree Tests
1514
runs-on: ubuntu-latest
15+
timeout-minutes: 90
1616

1717
env:
1818
PYTHONPATH: dbt
19-
DBT_CH_TEST_HOST: ${{ secrets.INTEGRATIONS_TEAM_TESTS_CLOUD_HOST_SMT }}
20-
DBT_CH_TEST_PASSWORD: ${{ secrets.INTEGRATIONS_TEAM_TESTS_CLOUD_PASSWORD_SMT }}
19+
DBT_CH_TEST_HOST: ${{ secrets.DBT_TESTS_CLOUD_HOST_SMT }}
20+
DBT_CH_TEST_PASSWORD: ${{ secrets.DBT_TESTS_CLOUD_PASSWORD_SMT }}
2121
DBT_CH_TEST_CLUSTER_MODE: true
2222
DBT_CH_TEST_CLOUD: true
2323

2424
steps:
2525
- name: Checkout
2626
uses: actions/checkout@v3
2727

28-
- name: Setup Python 3.11
28+
- name: Setup Python 3.12
2929
uses: actions/setup-python@v4
3030
with:
31-
python-version: '3.11'
31+
python-version: '3.12'
3232

3333
- name: Install requirements
3434
run: pip3 install . -r dev_requirements.txt
3535

3636
- name: Run HTTP tests
3737
env:
3838
DBT_CH_TEST_PORT: 8443
39-
run: pytest tests
39+
run: pytest tests --timeout=240
4040

4141
- name: Run Native tests
4242
env:
4343
DBT_CH_TEST_PORT: 9440
44-
run: pytest tests
44+
run: pytest tests --timeout=240

tests/integration/adapter/materialized_view/test_materialized_view.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
import pytest
99
from dbt.adapters.clickhouse.query import quote_identifier
10+
from dbt.tests.fixtures.project import TestProjInfo
1011
from dbt.tests.util import check_relation_types, run_dbt
1112

1213
PEOPLE_SEED_CSV = """
@@ -193,14 +194,14 @@ def test_disabled_catchup(self, project):
193194
"""
194195

195196

196-
def query_table_type(project, schema, table):
197+
def query_table_type(project: TestProjInfo, schema: str, table: str) -> str:
197198
table_type = project.run_sql(
198199
f"""
199200
select engine from system.tables where database = '{schema}' and name = '{table}'
200201
""",
201202
fetch="all",
202203
)
203-
return table_type[0][0] if len(table_type) > 0 else None
204+
return table_type[0][0] if len(table_type) > 0 else ''
204205

205206

206207
class TestUpdateMV:
@@ -300,7 +301,7 @@ def test_mv_is_dropped_on_full_refresh(self, project):
300301
# Step 4: Assert that target table is now a view and internal MV no longer exists
301302
assert query_table_type(project, schema_unquoted, 'hackers_mv') == "View"
302303
# Verify that the internal materialized view (_mv) no longer exists
303-
assert query_table_type(project, schema_unquoted, 'hackers_mv_mv') is None
304+
assert not query_table_type(project, schema_unquoted, 'hackers_mv_mv')
304305

305306
def test_view_full_refresh_does_not_affect_existing_mv_with_mv_suffix(self, project):
306307
"""

tests/integration/conftest.py

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import logging
12
import os
23
import random
34
import sys
@@ -196,3 +197,48 @@ def wait_until_responsive(check, timeout, pause, clock=timeit.default_timer):
196197
return
197198
now = clock()
198199
raise Exception("Timeout reached while waiting on service!")
200+
201+
202+
def wait_for_users_in_cluster(client, cluster_name, users, timeout=30.0, pause=1.0):
203+
start_time = timeit.default_timer()
204+
205+
result = client.query(f"""
206+
SELECT count() as replica_count
207+
FROM system.clusters
208+
WHERE cluster = '{cluster_name}'
209+
""")
210+
replica_count = result.result_rows[0][0] if result.result_rows else 0
211+
212+
logging.debug(f"Found {replica_count} replicas in cluster '{cluster_name}'\n")
213+
214+
# Check if all users exist in all replicas
215+
while (timeit.default_timer() - start_time) < timeout:
216+
all_users_ready = True
217+
218+
user_list = ", ".join([f"'{user}'" for user in users])
219+
220+
user_check_query = f"""
221+
SELECT name, count() as user_count
222+
FROM clusterAllReplicas('{cluster_name}', system.users)
223+
WHERE name IN ({user_list})
224+
group by name
225+
"""
226+
result = client.query(user_check_query)
227+
for row in result.result_rows:
228+
user_name, user_count = row
229+
if user_count < replica_count:
230+
logging.info(
231+
f"User '{user_name}' found in {user_count}/{replica_count} replicas. Waiting...\n"
232+
)
233+
all_users_ready = False
234+
break
235+
236+
if all_users_ready:
237+
logging.info(f"All {len(users)} users are created in all {replica_count} replicas\n")
238+
return True
239+
240+
time.sleep(pause)
241+
242+
raise Exception(
243+
f"Timeout reached: Not all users were created in all replicas within {timeout} seconds"
244+
)

0 commit comments

Comments
 (0)