Skip to content

test(mqtt): fix env var race in topic_writer_tests - #299

Merged
lxsaah merged 1 commit into
mainfrom
fix/mqtt-topic-env-race
Oct 6, 2026
Merged

lxsaah merged 1 commit into
mainfrom
fix/mqtt-topic-env-race

Conversation

@lxsaah

@lxsaah lxsaah commented Oct 6, 2026

Copy link
Copy Markdown
Contributor

Description

Fixes the intermittent test_topic_resolver_from_env failure that broke the Comprehensive Development Check job in CI run #828 on main:

panicked at aimdb-mqtt-connector/tests/topic_writer_tests.rs:212:5
  left: None
 right: Some("env/dynamic/topic")

Root cause: test_topic_resolver_with_connector_registration also set and removed TEST_MQTT_TOPIC, but never read it. Its resolver reads TEST_COMMAND_TOPIC. Cargo runs tests in parallel, so its remove_var could land between the other test's set_var and var calls.

Fix: remove the unused set_var/remove_var so TEST_MQTT_TOPIC is only used by one test. The other env-mutating tests (TEST_INBOUND_TOPIC, KNX KNX_SWITCH_GROUP/KNX_SWITCH_INPUT) each use their own variable, so they don't have this problem.

Related Issue

Checklist

  • My code follows the project's coding standards (cargo fmt --check clean).
  • All existing tests in the affected file passed: cargo test -p aimdb-mqtt-connector --features "std,tokio-rustls" --test topic_writer_tests (17/17, run 5×). Full make check not run locally.
  • I have added tests to cover my changes. (Not applicable: test-only fix.)
  • I have updated the documentation accordingly. (Not applicable.)

🤖 Generated with Claude Code

https://claude.ai/code/session_01BcQmgAzd8UMfUWiAFN4swa


Generated by Claude Code

test_topic_resolver_with_connector_registration set and removed
TEST_MQTT_TOPIC without ever reading it (its resolver reads
TEST_COMMAND_TOPIC). Running in parallel with
test_topic_resolver_from_env, the remove_var could land between that
test's set_var and var calls, making it read None. This failed CI
run #828 on main.

Drop the unused set_var/remove_var so the variable has a single owner.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01BcQmgAzd8UMfUWiAFN4swa
@lxsaah
lxsaah merged commit ec0d671 into main Oct 6, 2026
7 checks passed
@lxsaah
lxsaah deleted the fix/mqtt-topic-env-race branch October 6, 2026 20:17
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.

2 participants