Improve resource cleanup on connection close (and make server API a unique pointer) (#9799)

* Improve resource cleanup on connection close

* Copilot had some good feedback. Let's just make the api a unique pointer

* Update src/mesh/api/ServerAPI.cpp

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>

* Copilot stupidly suggesting we call protected methods

* Gotta do it in the superclasses as well

* Fix moar

* Refactor MQTT unit test to ensure proper subscription handling and clear side effects

---------

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
This commit is contained in:
Ben Meadors
2026-03-03 13:37:15 -06:00
committed by GitHub
co-authored by Copilot
parent eb2f3cef89
commit 3601eabbf8
8 changed files with 34 additions and 19 deletions
+9 -4
View File
@@ -291,11 +291,16 @@ class MQTTUnitTest : public MQTT
if (!moduleConfig.mqtt.enabled || moduleConfig.mqtt.proxy_to_client_enabled || *moduleConfig.mqtt.root) {
loopUntil([] { return true; }); // Loop once
return;
} else {
// Wait for MQTT to subscribe to all topics.
TEST_ASSERT_TRUE(loopUntil(
[] { return pubsub->subscriptions_.count("msh/2/e/test/+") && pubsub->subscriptions_.count("msh/2/e/PKI/+"); }));
}
// Wait for MQTT to subscribe to all topics.
TEST_ASSERT_TRUE(loopUntil(
[] { return pubsub->subscriptions_.count("msh/2/e/test/+") && pubsub->subscriptions_.count("msh/2/e/PKI/+"); }));
// Clear any side effects from startup (e.g. map report triggered by runOnce)
mockMeshService->messages_.clear();
mockMeshService->notifications_.clear();
mockRouter->packets_.clear();
mockRoutingModule->ackNacks_.clear();
}
PubSubClient &getPubSub() { return pubSub; }
};