From c1c278ab9d0742c2488db8e8a9ccbacfc4e0f663 Mon Sep 17 00:00:00 2001 From: Alexander Tokmakov Date: Wed, 8 Feb 2023 20:10:33 +0100 Subject: [PATCH 1/2] make a bug in HTTP interface less annoying --- tests/clickhouse-test | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/tests/clickhouse-test b/tests/clickhouse-test index a65662440f6..913f5430009 100755 --- a/tests/clickhouse-test +++ b/tests/clickhouse-test @@ -91,7 +91,7 @@ class HTTPError(Exception): # Helpers to execute queries via HTTP interface. def clickhouse_execute_http( - base_args, query, timeout=30, settings=None, default_format=None + base_args, query, timeout=30, settings=None, default_format=None, max_http_retries=5 ): if args.secure: client = http.client.HTTPSConnection( @@ -120,7 +120,7 @@ def clickhouse_execute_http( if default_format is not None: params["default_format"] = default_format - for i in range(MAX_RETRIES): + for i in range(max_http_retries): try: client.request( "POST", @@ -130,7 +130,7 @@ def clickhouse_execute_http( data = res.read() break except Exception as ex: - if i == MAX_RETRIES - 1: + if i == max_http_retries - 1: raise ex sleep(i + 1) @@ -140,13 +140,12 @@ def clickhouse_execute_http( return data - -def clickhouse_execute(base_args, query, timeout=30, settings=None): - return clickhouse_execute_http(base_args, query, timeout, settings).strip() +def clickhouse_execute(base_args, query, timeout=30, settings=None, max_http_retries=5): + return clickhouse_execute_http(base_args, query, timeout, settings, max_http_retries=max_http_retries).strip() def clickhouse_execute_json(base_args, query, timeout=60, settings=None): - data = clickhouse_execute_http(base_args, query, timeout, settings, "JSONEachRow") + data = clickhouse_execute_http(base_args, query, timeout, settings, "JSONEachRow", max_http_retries=max_http_retries) if not data: return None rows = [] @@ -641,7 +640,7 @@ class TestCase: clickhouse_execute( args, - "CREATE DATABASE " + database + get_db_engine(testcase_args, database), + "CREATE DATABASE IF NOT EXISTS " + database + get_db_engine(testcase_args, database), settings=get_create_database_settings(args, testcase_args), ) @@ -1139,7 +1138,7 @@ class TestCase: seconds_left = max( args.timeout - (datetime.now() - start_time).total_seconds(), 20 ) - drop_database_query = "DROP DATABASE " + database + drop_database_query = "DROP DATABASE IF EXISTS " + database if args.replicated_database: drop_database_query += " ON CLUSTER test_cluster_database_replicated" @@ -1670,7 +1669,7 @@ def check_server_started(args): retry_count = args.server_check_retries while retry_count > 0: try: - clickhouse_execute(args, "SELECT 1") + clickhouse_execute(args, "SELECT 1", max_http_retries=1) print(" OK") sys.stdout.flush() return True From 16f35b6a6cfca149d219bb8c14ecf4f70b161a97 Mon Sep 17 00:00:00 2001 From: Alexander Tokmakov Date: Thu, 9 Feb 2023 00:42:08 +0300 Subject: [PATCH 2/2] Update clickhouse-test --- tests/clickhouse-test | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/clickhouse-test b/tests/clickhouse-test index 913f5430009..2215982affe 100755 --- a/tests/clickhouse-test +++ b/tests/clickhouse-test @@ -144,7 +144,7 @@ def clickhouse_execute(base_args, query, timeout=30, settings=None, max_http_ret return clickhouse_execute_http(base_args, query, timeout, settings, max_http_retries=max_http_retries).strip() -def clickhouse_execute_json(base_args, query, timeout=60, settings=None): +def clickhouse_execute_json(base_args, query, timeout=60, settings=None, max_http_retries=5): data = clickhouse_execute_http(base_args, query, timeout, settings, "JSONEachRow", max_http_retries=max_http_retries) if not data: return None