Stateless tests: fix hanging tests 02473_multistep_prewhere* 00411_long_accurate_number_comparison*

This commit is contained in:
Nikita Fomichev 2024-08-02 16:05:39 +02:00
parent 9c7464e065
commit 2c9cef38e5
4 changed files with 26 additions and 18 deletions

View File

@ -2,23 +2,16 @@
import os, itertools, urllib.request, urllib.parse, urllib.error, urllib.request, urllib.error, urllib.parse, sys
CURDIR = os.path.dirname(os.path.realpath(__file__))
sys.path.insert(0, os.path.join(CURDIR, "helpers"))
def get_ch_answer(query):
return (
urllib.request.urlopen(
os.environ.get(
"CLICKHOUSE_URL",
"http://localhost:" + os.environ.get("CLICKHOUSE_PORT_HTTP", "8123"),
),
data=query.encode(),
)
.read()
.decode()
)
from pure_http_client import ClickHouseClient
client = ClickHouseClient()
def check_answers(query, answer):
ch_answer = get_ch_answer(query)
ch_answer = client.query(query)
if ch_answer.strip() != answer.strip():
print("FAIL on query:", query)
print("Expected answer:", answer)

View File

@ -6,7 +6,7 @@ import sys
CURDIR = os.path.dirname(os.path.realpath(__file__))
sys.path.insert(0, os.path.join(CURDIR, "helpers"))
from pure_http_client import ClickHouseClient
from pure_http_client import ClickHouseClient, requests_session_with_retries
class Tester:
@ -195,7 +195,7 @@ def main():
default_index_granularity = 10
total_rows = 7 * default_index_granularity
step = default_index_granularity
session = requests.Session()
session = requests_session_with_retries()
for index_granularity in [
default_index_granularity - 1,
default_index_granularity,

View File

@ -6,7 +6,7 @@ import sys
CURDIR = os.path.dirname(os.path.realpath(__file__))
sys.path.insert(0, os.path.join(CURDIR, "helpers"))
from pure_http_client import ClickHouseClient
from pure_http_client import ClickHouseClient, requests_session_with_retries
class Tester:
@ -161,7 +161,7 @@ def main():
default_index_granularity = 10
total_rows = 8 * default_index_granularity
step = default_index_granularity
session = requests.Session()
session = requests_session_with_retries()
for index_granularity in [default_index_granularity - 1, default_index_granularity]:
tester = Tester(session, url, index_granularity, total_rows)
# Test combinations of ranges of columns c and d

View File

@ -1,7 +1,8 @@
import os
import io
import sys
import requests
from requests.adapters import HTTPAdapter
from requests.packages.urllib3.util.retry import Retry
import time
import pandas as pd
@ -77,3 +78,17 @@ class ClickHouseClient:
return result
else:
raise ValueError(r.text)
def requests_session_with_retries(retries=3, timeout=180):
session = requests.Session()
retry = Retry(
total=retries,
read=retries,
connect=retries,
)
adapter = HTTPAdapter(max_retries=retry)
session.mount("http://", adapter)
session.mount("https://", adapter)
session.timeout = timeout
return session