From da211909e91b3bdcef096626ddcec39267efc43b Mon Sep 17 00:00:00 2001 From: Azat Khuzhin Date: Sat, 25 Dec 2021 11:52:39 +0300 Subject: [PATCH 1/2] tests/integration: refactor test_async_drain_connection --- .../test_async_drain_connection/test.py | 33 +++++++++---------- 1 file changed, 15 insertions(+), 18 deletions(-) diff --git a/tests/integration/test_async_drain_connection/test.py b/tests/integration/test_async_drain_connection/test.py index 21f9b142e7a..5eaac2b28b7 100644 --- a/tests/integration/test_async_drain_connection/test.py +++ b/tests/integration/test_async_drain_connection/test.py @@ -1,21 +1,21 @@ -import os -import sys -import time -from multiprocessing.dummy import Pool +# pylint: disable=redefined-outer-name +# pylint: disable=unused-argument + import pytest from helpers.cluster import ClickHouseCluster cluster = ClickHouseCluster(__file__) -node = cluster.add_instance("node", main_configs=["configs/config.xml"]) +node = cluster.add_instance('node', main_configs=['configs/config.xml']) -@pytest.fixture(scope="module") +@pytest.fixture(scope='module') def started_cluster(): try: cluster.start() - node.query( - 'create table t (number UInt64) engine = Distributed(test_cluster_two_shards, system, numbers);' - ) + node.query(""" + create table t (number UInt64) + engine = Distributed(test_cluster_two_shards, system, numbers) + """) yield cluster finally: @@ -23,14 +23,11 @@ def started_cluster(): def test_filled_async_drain_connection_pool(started_cluster): - busy_pool = Pool(10) - - def execute_query(i): + def execute_queries(_): for _ in range(100): - node.query('select * from t where number = 0 limit 2;', - settings={ - "sleep_in_receive_cancel_ms": 10000000, - "max_execution_time": 5 - }) + node.query('select * from t where number = 0 limit 2', settings={ + 'sleep_in_receive_cancel_ms': int(10e6), + 'max_execution_time': 5, + }) - p = busy_pool.map(execute_query, range(10)) + any(map(execute_queries, range(10))) From 42ab02a81034d7c88a9a4426b470d7422857d4c5 Mon Sep 17 00:00:00 2001 From: Azat Khuzhin Date: Sat, 25 Dec 2021 11:52:57 +0300 Subject: [PATCH 2/2] Fix test_async_drain_connection flakiness Sometimes [1] 5 seconds is not enough, since drain_timeout is 3 seconds, and 2 seconds sometimes is not enough to do other things, especially under sanitizers: E Code: 159. DB::Exception: Received from 172.16.1.2:9000. DB::Exception: Timeout exceeded: elapsed 5.019254094 seconds, maximum: 5. Stack trace: [1]: https://s3.amazonaws.com/clickhouse-test-reports/0/826f7cb0f53e20e67ef52800cb735bb88a6de658/integration_tests__thread__actions__[4/4].html --- tests/integration/test_async_drain_connection/test.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/tests/integration/test_async_drain_connection/test.py b/tests/integration/test_async_drain_connection/test.py index 5eaac2b28b7..40d78ebbe7c 100644 --- a/tests/integration/test_async_drain_connection/test.py +++ b/tests/integration/test_async_drain_connection/test.py @@ -28,6 +28,9 @@ def test_filled_async_drain_connection_pool(started_cluster): node.query('select * from t where number = 0 limit 2', settings={ 'sleep_in_receive_cancel_ms': int(10e6), 'max_execution_time': 5, + # decrease drain_timeout to make test more stable + # (another way is to increase max_execution_time, but this will make test slower) + 'drain_timeout': 1, }) any(map(execute_queries, range(10)))