Skip to content

tests: drop unnecessary time.sleep#774

Merged
dkropachev merged 5 commits into
masterfrom
cherry-pick-time-sleep-optimizations
Mar 30, 2026
Merged

tests: drop unnecessary time.sleep#774
dkropachev merged 5 commits into
masterfrom
cherry-pick-time-sleep-optimizations

Conversation

@dkropachev

@dkropachev dkropachev commented Mar 30, 2026

Copy link
Copy Markdown
Collaborator

Point of this PR

  • Land only the time.sleep() removal/optimization work from improve/integration-test-performance-pr without bringing in unrelated integration-test refactors.
  • Improve integration-test stability and runtime by replacing fixed sleeps with polling/event-based waits, including tablet invalidation waiting improvements.

From / To

  • Extracted from source branch: improve/integration-test-performance-pr
  • Proposed into base branch: master
  • PR branch: cherry-pick-time-sleep-optimizations

Extracted commits

  • 70cc3ffd3 - tests: remove redundant 10s sleep from setup_keyspace()
  • 0ebdd8dbe - tests: replace high-priority time.sleep() calls with polling
  • 8ff92d5b9 - tests: replace medium-priority time.sleep() calls with polling
  • ea8ecf800 - tests: fix flaky tablet tests by increasing trace timeout and polling for invalidation
  • e8b729f3e - tests: replace fixed time.sleep() calls with polling (~17s saving)

@dkropachev dkropachev self-assigned this Mar 30, 2026
@dkropachev dkropachev changed the title tests: cherry-pick time.sleep optimizations from improve/integration-test-performance-pr tests: remove unnecessary time.sleep from tests Mar 30, 2026
@dkropachev dkropachev changed the title tests: remove unnecessary time.sleep from tests tests: drop unnecessary time.sleep Mar 30, 2026
@dkropachev

Copy link
Copy Markdown
Collaborator Author

CI speed measurement for this change set (focused on Integration tests):

  • Scope: compared the PR integration workflow run to recent successful master integration workflow runs.
  • Why this workflow: this PR only changes integration tests (time.sleep() removal/replacement with polling).

Compared runs

Results

  • PR run total: 22m23s
  • Baseline average: 27m21s
  • Baseline median: 27m20s
  • Improvement vs baseline avg: 4m58s faster (~18.16%)
  • Improvement vs baseline median: 4m56s faster (~18.08%)

Head-to-head against the most recent baseline run (26m55s):

  • 4m32s faster (~16.84%)

Additional signal from matrix jobs:

  • Across common jobs, Test with pytest step improved by ~4m55s mean (~295s) per job.

So this PR appears to reduce integration CI time by roughly 17–18% while keeping checks green.

Comment on lines 217 to 220
)
time.sleep(5)
time.sleep(2) # allow iptables rule to take effect
try:
self.query_data(self.session, verify_in_tracing=False)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Commit: "tests: replace medium-priority time.sleep() calls with polling"

This doesn't introduce polling, just decreases sleep. Why? Are you sure it won't become flaky?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

2 seconds is more than enough for driver to drop all the connections.
But you have a good point, could have poolling here, let me add.

mykaul added 5 commits March 30, 2026 15:22
The time.sleep(10) in setup_keyspace() is redundant because callers
already ensure the cluster is fully ready before calling it:
- use_cluster() calls start_cluster_wait_for_up() which uses
  wait_for_binary_proto=True + wait_other_notice=True, then
  wait_for_node_socket() per node
- External cluster path (wait=False) had no sleep anyway

Remove the wait parameter entirely and its associated sleep, saving 10s
per cluster startup.
Replace fixed sleeps with condition-based polling to speed up tests:

- simulacron/utils.py: replace 5s sleep with HTTP endpoint polling
  (max 15s timeout, typically <1s)
- test_authentication.py: replace 10s sleep with auth readiness poll
  that tries connecting with default credentials
- upgrade/__init__.py: replace 10s auth sleep with same polling pattern
- upgrade/test_upgrade.py: replace 3x 20s sleeps (60s total) with
  control connection readiness polling

Total potential saving: ~95s of unconditional waiting per test run.
Replace fixed sleeps with condition-based polling in four test files:

- test_shard_aware.py: replace 25s of sleeps (5+10+5+5) with
  wait_until_not_raised polling for reconnection after shard connection
  close and iptables blocking
- test_metrics.py: replace 15s of sleeps (5+5+5) with polling for
  cluster recovery and node-down detection
- test_tablets.py: replace 13s of sleeps (3+10) with polling for
  metadata refresh and decommission completion
- simulacron/test_connection.py: replace 20s of sleeps (10+10) with
  polling for quiescent pool state

Total potential saving: ~73s of unconditional waiting.
… for invalidation

The tablet tests were intermittently failing because:
1. get_query_trace() used the default 2s max_wait, which is too short
   under resource pressure (--smp 2). Increased to 10s.
2. test_tablets_invalidation_decommission_non_cc_node used a fixed
   time.sleep(2) hoping tablet metadata invalidation would complete.
   Replaced with wait_until polling for the tablet record to be purged
   (0.5s delay, 20 attempts = 10s budget).
- test_cluster.py: replace sleep(1) x10 iterations with
  connect(wait_for_all_pools=True) for deterministic pool readiness
- test_query.py: replace sleep(5) with wait_until polling for
  'Preparing all known prepared statements' log message
- test_connection.py: replace sleep(2) with wait_until polling for
  host_down listener notification
@dkropachev dkropachev force-pushed the cherry-pick-time-sleep-optimizations branch from 9e56125 to 4b73e63 Compare March 30, 2026 19:23
@dkropachev

dkropachev commented Mar 30, 2026

Copy link
Copy Markdown
Collaborator Author

Updated per request: I squashed the new test_shard_aware iptables polling change into the existing commit that originally replaced time.sleep(2) in this area (tests/integration/standard/test_shard_aware.py) and force-pushed the branch history.

New commit sequence on this PR branch:

  • b577d6306 tests: remove redundant 10s sleep from setup_keyspace()
  • 3a703cbdd tests: replace high-priority time.sleep() calls with polling
  • 1098a6ea5 tests: replace medium-priority time.sleep() calls with polling
  • 8550056fb tests: fix flaky tablet tests by increasing trace timeout and polling for invalidation
  • 4b73e635d tests: replace fixed time.sleep() calls with polling (~17s saving)

@dkropachev dkropachev merged commit d31ea37 into master Mar 30, 2026
17 checks passed
@dkropachev dkropachev deleted the cherry-pick-time-sleep-optimizations branch March 30, 2026 20:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants