Repository navigation
Bring back the NATS integration tests - #112464
Conversation
`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]>
|
Workflow [PR], commit [499e3a1] Summary: ✅ AI ReviewSummaryThis 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
Final Verdict |
| start = time.time() | ||
| while time.time() - start < timeout: | ||
| try: | ||
| asyncio.run(check_nats_is_available(cluster)) |
There was a problem hiding this comment.
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.
Related: #100913
Bring back
tests/integration/test_storage_nats/test_nats_core.pyandtest_nats_jet_stream.py(33 tests each), together withcommon.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
SELECTonly 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_selectpublished 50 messages at15:30:52.179while the consumer subscribed at15:30:52.215, and then asserted on an empty view.wait_for_mv_attached_to_tablenow also waits for a freshStarted streaming to N attached viewsline, which the background task logs right after the consumer has subscribed. This is the same barriertest_system_stop.pyalready uses.configs/nats.xmlandnats_certs.shreappeared inmasterwith Add unified SYSTEM STOP/PAUSE/CANCEL/REFRESH for streaming engines and materialized views #107476, which addedtest_system_stop.pyto the same directory. Those versions are kept, and the<nats>credentials that the restored tests rely on are re-added tonats.xml.check_nats_is_availableno longer hangs on an unusable broker.nats.connectreports 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 "Removetest_storage_nats""" #100913 hit:ssl.create_default_contextenablesVERIFY_X509_STRICTsince Python 3.13 (the test images switched in d308407, after the tests were removed), and the certificate of the time was rejected withCA cert does not include key usage extension. The certificate is already fixed inmaster; the connect attempt is now bounded as well, and what the client saw is logged.The
ruffrules F401 (unused import) and F541 (f-string without placeholders) were enabled after the tests were removed, so the unused imports and the extraneousfprefixes are dropped. One expected error message lost its trailing period in the meantime, so that assertion is adjusted.Verified locally against a
masterrelease binary (26.8.1.332): both modules pass in full, 33 tests each. One caveat:test_nats_restore_failed_connection_without_losses_on_writeis 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):