Files
Alexey MilovidovandClaude Opus 4.8 295ced78d1 Enable more Ruff checks (F401/F403/F405/F541/F841) and clean up tests
Follow-up to #105171, which added `ruff` with a deliberately narrow,
bug-class-only rule set and left the unused-name and star-import rules
off pending a dedicated cleanup pass. This enables that second batch in
`pyproject.toml` and fixes every violation across the tree (the bulk in
integration tests):

- `F401` unused-import and `F841` unused-variable: removed, preserving
  any side-effecting right-hand side (e.g. `result = node.query(...)`
  becomes `node.query(...)`). Two `try: import ...` feature probes are
  kept with `# noqa: F401`.
- `F541` f-string-missing-placeholders: dropped the redundant `f` prefix.
- `F403`/`F405` star imports: every `from module import *` is expanded
  into explicit imports of the names actually used, taken from each
  name's real origin, so stdlib/third-party names import from their real
  source rather than through a test "convenience bundle". The now-empty
  `tests/integration/helpers/kafka/common_direct.py` bundle is removed and
  its three remaining consumers import `_VarintBytes`/`KafkaAdminClient`
  directly.

Eliminating the star imports surfaced a real bug the wildcard had masked
from `F821`: `generate_presets.py` in `test_prometheus_protocols` called
an undefined `execute_instant_query_with_http_api`; fixed to the existing
`execute_query_via_http_api`.

No `black`/`isort` reformatting was applied (neither is enforced in the
style check), so the diff is limited to the lint fixes themselves.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
2026-06-18 23:22:25 +00:00

110 lines
3.1 KiB
Python

#!/usr/bin/env python3
import pytest
from multiprocessing.dummy import Pool
import helpers.keeper_utils as keeper_utils
from helpers.cluster import ClickHouseCluster
cluster = ClickHouseCluster(__file__)
node1 = cluster.add_instance(
"node1",
main_configs=["configs/enable_keeper1.xml"],
stay_alive=True,
)
node2 = cluster.add_instance(
"node2",
main_configs=["configs/enable_keeper2.xml"],
stay_alive=True,
)
@pytest.fixture(scope="module")
def started_cluster():
try:
cluster.start()
yield cluster
finally:
cluster.shutdown(ignore_fatal=True)
def wait_nodes():
keeper_utils.wait_nodes(cluster, [node1, node2])
def get_fake_zk(nodename, timeout=30.0):
return keeper_utils.get_fake_zk(cluster, nodename, timeout=timeout)
def start_clickhouse(node):
node.start_clickhouse()
def setup_nodes():
node1.stop_clickhouse()
node2.stop_clickhouse()
p = Pool(2)
waiters = []
for node in [node1, node2]:
node.exec_in_container(["rm", "-rf", "/var/lib/clickhouse/coordination/log"])
node.exec_in_container(
["rm", "-rf", "/var/lib/clickhouse/coordination/snapshots"]
)
waiters.append(p.apply_async(start_clickhouse, (node,)))
for waiter in waiters:
waiter.wait()
wait_nodes()
def test_keeper_invalid_digest(started_cluster):
if (
node1.is_built_with_thread_sanitizer()
or node1.is_built_with_address_sanitizer()
or node1.is_built_with_memory_sanitizer()
):
pytest.skip("doesn't fit in timeouts for stacktrace generation")
try:
# Wait for the cluster to be ready
setup_nodes()
# Enable the failpoint on node1 to set invalid digest
node1.query("SYSTEM ENABLE FAILPOINT keeper_leader_sets_invalid_digest")
# Create a zookeeper connection to node1
node1_zk = get_fake_zk("node1")
# Perform an operation that will trigger the failpoint
# The second node should detect the invalid digest and abort
node1_zk.create_async("/test_invalid_digest", b"testdata")
node2.wait_for_log_line("Digest for nodes is not matching after preprocessing request of type 'Create' at log index")
node2.stop_clickhouse(kill=True)
def get_last_committed_log_idx():
return int(
next(
filter(
lambda line: line.startswith("last_committed_log_idx"),
keeper_utils.send_4lw_cmd(cluster, node1, "lgif").split("\n"),
)
).split("\t")[1]
)
last_committed_log_idx = get_last_committed_log_idx()
node2.start_clickhouse(expected_to_fail=True)
node2.wait_for_log_line("Digest for nodes is not matching after preprocessing request of type 'Create' at log index")
assert get_last_committed_log_idx() == last_committed_log_idx
finally:
# Clean up connections
try:
if "node1_zk" in locals():
node1_zk.stop()
node1_zk.close()
except:
pass