Skip to content

Bring back the NATS integration tests - #112464

Merged
alexey-milovidov merged 1 commit into
masterfrom
restore-nats-integration-tests
Jul 30, 2026
Merged

alexey-milovidov merged 1 commit into
masterfrom
restore-nats-integration-tests

Conversation

@alexey-milovidov

Copy link
Copy Markdown
Member

Related: #100913

Bring back tests/integration/test_storage_nats/test_nats_core.py and test_nats_jet_stream.py (33 tests each), together with common.py, the test configs, the Protobuf schema and the JSON reference. They were removed in #93616 - a re-removal of #92140 after #92155 had restored them.

Restoring them as they were is not enough, four things have drifted since:

  • Waiting for the consumer, not just for the view. Refusing a direct SELECT only proves that a materialized view is attached; the background streaming task subscribes to the subjects a moment later. Core NATS has no backlog, so messages published in that window are dropped and never reach the view - test_nats_select published 50 messages at 15:30:52.179 while the consumer subscribed at 15:30:52.215, and then asserted on an empty view. wait_for_mv_attached_to_table now also waits for a fresh Started streaming to N attached views line, which the background task logs right after the consumer has subscribed. This is the same barrier test_system_stop.py already uses.

  • configs/nats.xml and nats_certs.sh reappeared in master with Add unified SYSTEM STOP/PAUSE/CANCEL/REFRESH for streaming engines and materialized views #107476, which added test_system_stop.py to the same directory. Those versions are kept, and the <nats> credentials that the restored tests rely on are re-added to nats.xml.

  • check_nats_is_available no longer hangs on an unusable broker. nats.connect reports a TLS or an authentication failure through its error callback and then keeps retrying, so every NATS test ran into the 900 s pytest timeout with no indication of the cause. That is what all seven integration jobs of Revert "Revert "Revert "Remove test_storage_nats""" #100913 hit: ssl.create_default_context enables VERIFY_X509_STRICT since Python 3.13 (the test images switched in d308407, after the tests were removed), and the certificate of the time was rejected with CA cert does not include key usage extension. The certificate is already fixed in master; the connect attempt is now bounded as well, and what the client saw is logged.

  • The ruff rules F401 (unused import) and F541 (f-string without placeholders) were enabled after the tests were removed, so the unused imports and the extraneous f prefixes are dropped. One expected error message lost its trailing period in the meantime, so that assertion is adjusted.

Verified locally against a master release binary (26.8.1.332): both modules pass in full, 33 tests each. One caveat: test_nats_restore_failed_connection_without_losses_on_write is sensitive to host load - it allows 300 s to consume 100000 messages, and it failed once (84033 of 100000 keys) while both modules were running concurrently on an already saturated host, then passed 3/3 in isolation and in the clean full-file runs.

Changelog category (leave one):

  • CI Fix or Improvement (changelog entry is not required)

`tests/integration/test_storage_nats/test_nats_core.py` and
`test_nats_jet_stream.py`, together with `common.py`, the test configs, the
Protobuf schema and the JSON reference, were removed in
#93616 - a re-removal of
#92140 after
#92155 had restored them. Restore
them and fix what has drifted since, so that they pass instead of timing out.

Four things had to be reconciled with the current `master`:

- Waiting for the consumer, not just for the view. Refusing a direct `SELECT`
  only proves that a materialized view is attached; the background streaming
  task subscribes to the subjects a moment later. Core NATS has no backlog, so
  messages published in that window are dropped and never reach the view - for
  example `test_nats_select` published 50 messages at `15:30:52.179` while the
  consumer subscribed at `15:30:52.215`, and then asserted on an empty view.
  `wait_for_mv_attached_to_table` now also waits for a fresh
  `Started streaming to N attached views` line, which the background task logs
  right after the consumer has subscribed. This is the same barrier
  `test_system_stop.py` already uses.

- `configs/nats.xml` and `nats_certs.sh` reappeared in `master` with
  #107476, which added
  `test_system_stop.py` to the same directory. Keep those versions and re-add
  the `<nats>` credentials that the restored tests rely on to `nats.xml`.

- `check_nats_is_available` no longer hangs on an unusable broker.
  `nats.connect` reports a TLS or an authentication failure through its error
  callback and then keeps retrying, so every NATS test ran into the 900 s pytest
  timeout with no indication of the cause - this is what all seven integration
  jobs of #100913 hit, because
  `ssl.create_default_context` enables `VERIFY_X509_STRICT` since Python 3.13
  (the test images switched in d308407, after the tests were removed) and
  the certificate of the time was rejected with `CA cert does not include key
  usage extension`. The certificate is already fixed in `master`; bound the
  connect attempt as well and log what the client saw.

- The `ruff` rules F401 (unused import) and F541 (`f`-string without
  placeholders) were enabled after the tests were removed, so drop the unused
  imports and the extraneous `f` prefixes. One expected error message lost its
  trailing period in the meantime, adjust the assertion accordingly.

Verified locally against a `master` release binary: both modules pass in full,
33 tests each.

Related: #100913

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
@clickhouse-gh

clickhouse-gh Bot commented Jul 29, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [499e3a1]

Summary: ✅


AI Review

Summary

This PR restores the NATS integration suites and adds the missing synchronization around materialized-view startup plus a bounded NATS availability probe. The overall direction looks right, but one helper still assumes that "broker unavailable" only arrives as an exception, which leaves the paused-broker coverage vulnerable to timing out on the new timeout-based failure mode.

Findings

⚠️ Majors

  • [tests/integration/test_storage_nats/common.py:32] wait_nats_paused ignores the new False return from check_nats_is_available. After this patch, a timed-out connect attempt is represented as False instead of NoServersError; in that case the loop sleeps until its 180-second deadline even though NATS is already unreachable, so test_nats_no_connection_at_startup_2 in both the core and JetStream suites can still fail spuriously on loaded shards. Treat a falsy result as the paused condition, or re-raise a dedicated unavailable exception from check_nats_is_available.
Final Verdict

⚠️ Needs changes before merge.

@clickhouse-gh clickhouse-gh Bot added the pr-ci label Jul 29, 2026
start = time.time()
while time.time() - start < timeout:
try:
asyncio.run(check_nats_is_available(cluster))

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

check_nats_is_available now reports one class of broker unavailability by returning False on timeout, but wait_nats_paused still treats only NoServersError as "paused". If pause_container("nats1") manifests as a timed-out connect instead of an immediate exception, this loop keeps sleeping until its 180-second timeout and both test_nats_no_connection_at_startup_2 variants fail even though NATS is already unreachable. Please treat a falsy return as the paused condition here, or make check_nats_is_available raise a dedicated unavailable exception so the helper does not depend on one specific failure mode.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pr-ci pr-synced-to-cloud The PR is synced to the cloud repo

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants