mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-26 01:22:04 +00:00
Merge pull request #52184 from azat/tests/randomize-timezone
Randomize timezone in tests across non-deterministic around 1970 and default
This commit is contained in:
commit
34ff0e0ea9
@ -4,6 +4,9 @@
|
||||
set -e -x -a
|
||||
|
||||
# Choose random timezone for this test run.
|
||||
#
|
||||
# NOTE: that clickhouse-test will randomize session_timezone by itself as well
|
||||
# (it will choose between default server timezone and something specific).
|
||||
TZ="$(rg -v '#' /usr/share/zoneinfo/zone.tab | awk '{print $3}' | shuf | head -n1)"
|
||||
echo "Choosen random timezone $TZ"
|
||||
ln -snf "/usr/share/zoneinfo/$TZ" /etc/localtime && echo "$TZ" > /etc/timezone
|
||||
|
@ -529,6 +529,12 @@ def threshold_generator(always_on_prob, always_off_prob, min_val, max_val):
|
||||
return gen
|
||||
|
||||
|
||||
# To keep dependency list as short as possible, tzdata is not used here (to
|
||||
# avoid try/except block for import)
|
||||
def get_localzone():
|
||||
return os.getenv("TZ", "/".join(os.readlink("/etc/localtime").split("/")[-2:]))
|
||||
|
||||
|
||||
class SettingsRandomizer:
|
||||
settings = {
|
||||
"max_insert_threads": lambda: 0
|
||||
@ -602,20 +608,33 @@ class SettingsRandomizer:
|
||||
"enable_memory_bound_merging_of_aggregation_results": lambda: random.randint(
|
||||
0, 1
|
||||
),
|
||||
"session_timezone": lambda: random.choice(
|
||||
[
|
||||
# special non-deterministic around 1970 timezone, see [1].
|
||||
#
|
||||
# [1]: https://github.com/ClickHouse/ClickHouse/issues/42653
|
||||
"America/Mazatlan",
|
||||
"America/Hermosillo",
|
||||
"Mexico/BajaSur",
|
||||
# server default that is randomized across all timezones
|
||||
# NOTE: due to lots of trickery we cannot use empty timezone here, but this should be the same.
|
||||
get_localzone(),
|
||||
]
|
||||
),
|
||||
}
|
||||
|
||||
@staticmethod
|
||||
def get_random_settings(args):
|
||||
random_settings = []
|
||||
random_settings = {}
|
||||
is_debug = BuildFlags.DEBUG in args.build_flags
|
||||
for setting, generator in SettingsRandomizer.settings.items():
|
||||
if (
|
||||
is_debug
|
||||
and setting == "allow_prefetched_read_pool_for_remote_filesystem"
|
||||
):
|
||||
random_settings.append(f"{setting}=0")
|
||||
random_settings[setting] = 0
|
||||
else:
|
||||
random_settings.append(f"{setting}={generator()}")
|
||||
random_settings[setting] = generator()
|
||||
return random_settings
|
||||
|
||||
|
||||
@ -651,10 +670,10 @@ class MergeTreeSettingsRandomizer:
|
||||
|
||||
@staticmethod
|
||||
def get_random_settings(args):
|
||||
random_settings = []
|
||||
random_settings = {}
|
||||
for setting, generator in MergeTreeSettingsRandomizer.settings.items():
|
||||
if setting not in args.changed_merge_tree_settings:
|
||||
random_settings.append(f"{setting}={generator()}")
|
||||
random_settings[setting] = generator()
|
||||
return random_settings
|
||||
|
||||
|
||||
@ -766,7 +785,14 @@ class TestCase:
|
||||
|
||||
@staticmethod
|
||||
def cli_format_settings(settings_list) -> str:
|
||||
return " ".join([f"--{setting}" for setting in settings_list])
|
||||
out = []
|
||||
for k, v in settings_list.items():
|
||||
out.extend([f"--{k}", str(v)])
|
||||
return " ".join(out)
|
||||
|
||||
@staticmethod
|
||||
def http_format_settings(settings_list) -> str:
|
||||
return urllib.parse.urlencode(settings_list)
|
||||
|
||||
def has_show_create_table_in_test(self):
|
||||
return not subprocess.call(["grep", "-iq", "show create", self.case_file])
|
||||
@ -774,11 +800,12 @@ class TestCase:
|
||||
def add_random_settings(self, client_options):
|
||||
new_options = ""
|
||||
if self.randomize_settings:
|
||||
http_params = self.http_format_settings(self.random_settings)
|
||||
if len(self.base_url_params) == 0:
|
||||
os.environ["CLICKHOUSE_URL_PARAMS"] = "&".join(self.random_settings)
|
||||
os.environ["CLICKHOUSE_URL_PARAMS"] = http_params
|
||||
else:
|
||||
os.environ["CLICKHOUSE_URL_PARAMS"] = (
|
||||
self.base_url_params + "&" + "&".join(self.random_settings)
|
||||
self.base_url_params + "&" + http_params
|
||||
)
|
||||
|
||||
new_options += f" {self.cli_format_settings(self.random_settings)}"
|
||||
|
@ -5,4 +5,5 @@ CURDIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)
|
||||
# shellcheck source=../shell_config.sh
|
||||
. "$CURDIR"/../shell_config.sh
|
||||
|
||||
env TZ=UTC ${CLICKHOUSE_CLIENT} --use_client_time_zone=1 --query="SELECT toDateTime(1000000000)"
|
||||
# NOTE: session_timezone overrides use_client_time_zone, disable it randomization
|
||||
env TZ=UTC ${CLICKHOUSE_CLIENT} --session_timezone '' --use_client_time_zone=1 --query="SELECT toDateTime(1000000000)"
|
||||
|
@ -7,11 +7,12 @@ CURDIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)
|
||||
function perform()
|
||||
{
|
||||
local query=$1
|
||||
TZ=UTC $CLICKHOUSE_CLIENT \
|
||||
--allow_deprecated_syntax_for_merge_tree=1 \
|
||||
--use_client_time_zone=1 \
|
||||
--input_format_values_interpret_expressions=0 \
|
||||
--query "$query" 2>/dev/null
|
||||
local settings=(
|
||||
--allow_deprecated_syntax_for_merge_tree 1
|
||||
--session_timezone UTC
|
||||
--input_format_values_interpret_expressions 0
|
||||
)
|
||||
TZ=UTC $CLICKHOUSE_CLIENT "${settings[@]}" --query "$query" 2>/dev/null
|
||||
if [ "$?" -ne 0 ]; then
|
||||
echo "query failed"
|
||||
fi
|
||||
|
@ -1,3 +1,15 @@
|
||||
-- disable timezone randomization since otherwise TTL may fail at particular datetime, i.e.:
|
||||
--
|
||||
-- SELECT
|
||||
-- now(),
|
||||
-- toDate(toTimeZone(now(), 'America/Mazatlan')),
|
||||
-- today()
|
||||
--
|
||||
-- ┌───────────────now()─┬─toDate(toTimeZone(now(), 'America/Mazatlan'))─┬────today()─┐
|
||||
-- │ 2023-07-24 06:24:06 │ 2023-07-23 │ 2023-07-24 │
|
||||
-- └─────────────────────┴───────────────────────────────────────────────┴────────────┘
|
||||
set session_timezone = '';
|
||||
|
||||
drop table if exists ttl_00933_1;
|
||||
|
||||
-- Column TTL works only with wide parts, because it's very expensive to apply it for compact parts
|
||||
|
@ -7,8 +7,8 @@ CURDIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)
|
||||
|
||||
set -e -o pipefail
|
||||
|
||||
# Run the client.
|
||||
$CLICKHOUSE_CLIENT --multiquery <<'EOF'
|
||||
# NOTE: dictionaries TTLs works with server timezone, so session_timeout cannot be used
|
||||
$CLICKHOUSE_CLIENT --session_timezone '' --multiquery <<'EOF'
|
||||
DROP DATABASE IF EXISTS dictdb_01042;
|
||||
CREATE DATABASE dictdb_01042;
|
||||
CREATE TABLE dictdb_01042.table(x Int64, y Int64, insert_time DateTime) ENGINE = MergeTree ORDER BY tuple();
|
||||
|
@ -2,6 +2,9 @@
|
||||
|
||||
set mutations_sync = 2;
|
||||
|
||||
-- system.parts has server default, timezone cannot be randomized
|
||||
set session_timezone = '';
|
||||
|
||||
drop table if exists ttl;
|
||||
|
||||
create table ttl (d Date, a Int) engine = MergeTree order by a partition by toDayOfMonth(d)
|
||||
|
@ -5,7 +5,8 @@ CUR_DIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)
|
||||
# shellcheck source=../shell_config.sh
|
||||
. "$CUR_DIR"/../shell_config.sh
|
||||
|
||||
$CLICKHOUSE_CLIENT -q "
|
||||
# NOTE: dictionaries will be updated according to server TZ, not session, so prohibit it's randomization
|
||||
$CLICKHOUSE_CLIENT --session_timezone '' -q "
|
||||
CREATE TABLE table_for_update_field_dictionary
|
||||
(
|
||||
key UInt64,
|
||||
|
Loading…
Reference in New Issue
Block a user