test(mqtt): extract + test remaining inline MQTT decision points (Phase 6)
Close the host-testable gaps named in Phase 6 of STABILITY_TESTABILITY_HANDOFF.md
by moving the last inline decision logic into the pure, host-tested policy seams:
- WiFi STA reconnect backoff: extract the inline ladder + wrap-safe timing from
handleWiFiConnection() into MQTTConnectionPolicy::{wifiReconnectBackoffMs,
wifiReconnectDue,nextWifiBackoffAttempt}. Behavior-preserving (elapsedMs is the
wrap-safe form of the old ULONG_MAX branch); ladder/clamp/attempt-cap unchanged.
- Publication outcome pairing: name the (packet, raw) -> delivered contract as
MQTTPacketQueuePolicy::queuedPacketPublished() and wire both queue-drain sites;
partial success = completed, not retried.
- Freeze MQTTPublicationType enum values in a test (the bridge-side MQTTMessageType
alignment is already enforced by a compile-time static_assert).
Adds host tests for all three (exact boundaries + millis() rollover). Native suite
green (13 dirs); non-PSRAM observer firmware smoke build compiles.
WebConfig batch/reboot/stop state-machine extraction and queue-orchestration
coverage remain open (tracked in the Phase 6 status).
This commit is contained in:
1 parent
2e1a1410ce
commit
b0cf29fb33
7 files changed
+151
-15
No files matched your search
@@ -151,6 +151,29 @@ TEST(MQTTPacketQueuePolicy, RetrySchedulingDeadlineMayWrapToZero) {
|
||||
decision.retry_attempts));
|
||||
}
|
||||
|
||||
TEST(MQTTPacketQueuePolicy, PartialPublishCountsAsDeliveredEitherWay) {
|
||||
EXPECT_TRUE(QueuePolicy::queuedPacketPublished(true, true));
|
||||
EXPECT_TRUE(QueuePolicy::queuedPacketPublished(true, false)); // packet ok, raw failed
|
||||
EXPECT_TRUE(QueuePolicy::queuedPacketPublished(false, true)); // raw ok, packet failed
|
||||
EXPECT_FALSE(QueuePolicy::queuedPacketPublished(false, false)); // neither reached a slot
|
||||
}
|
||||
|
||||
TEST(MQTTPacketQueuePolicy, PublishOutcomePairingDrivesRetryDecision) {
|
||||
// packet succeeds / raw fails -> completed, no retry.
|
||||
QueuePolicy::RetryDecision d =
|
||||
QueuePolicy::retryDecision(QueuePolicy::queuedPacketPublished(true, false), 0, 1234U);
|
||||
EXPECT_EQ(QueuePolicy::RetryAction::Complete, d.action);
|
||||
|
||||
// raw succeeds / packet fails -> also completed.
|
||||
d = QueuePolicy::retryDecision(QueuePolicy::queuedPacketPublished(false, true), 0, 1234U);
|
||||
EXPECT_EQ(QueuePolicy::RetryAction::Complete, d.action);
|
||||
|
||||
// both fail on a fresh packet -> scheduled for a bounded retry.
|
||||
d = QueuePolicy::retryDecision(QueuePolicy::queuedPacketPublished(false, false), 0, 1234U);
|
||||
EXPECT_EQ(QueuePolicy::RetryAction::Schedule, d.action);
|
||||
EXPECT_EQ(1U, d.retry_attempts);
|
||||
}
|
||||
|
||||
int main(int argc, char** argv) {
|
||||
::testing::InitGoogleTest(&argc, argv);
|
||||
return RUN_ALL_TESTS();
|
||||
|
||||
Reference in new issue
Block a user