fix(mqtt): restore PSRAM buffers after restart
This commit is contained in:
1 parent
7b60ee704c
commit
b5deaf93fc
5 files changed
+154
-15
No files matched your search
@@ -30,6 +30,7 @@ does not reflect the GoogleTest count — run the built binary directly
|
||||
| `test_mqtt_topic_router` | `src/helpers/MQTTTopicRouter.h` | complete preset/custom topic-routing contract; MeshRank packets-only behavior; required identifiers; invalid inputs/slots; exact buffer boundaries |
|
||||
| `test_mqtt_connection_policy` | `src/helpers/MQTTConnectionPolicy.h` | reconnect guard/backoff/stagger and breaker transitions; stable reset; JWT lifetime/renewal policy; exact timing boundaries and 32-bit `millis()` rollover |
|
||||
| `test_mqtt_packet_queue_policy` | `src/helpers/MQTTPacketQueuePolicy.h` | queue-full eviction; stale-disconnect flush; adaptive drain limits; bounded QoS0 retries; exact timing boundaries and 32-bit `millis()` rollover |
|
||||
| `test_mqtt_runtime_buffer_lifecycle` | `src/helpers/MQTTRuntimeBufferLifecycle.h` | idempotent allocation/release; partial-allocation degradation; retry of only missing buffers |
|
||||
| `test_mqtt_payload_builder` | `src/helpers/MQTTPayloadBuilder.cpp` | status/packet/raw JSON contracts; optional fields; escaping; RX metrics and path; score handling; exact buffer bounds; maximum representative payloads |
|
||||
| `test_utils` | `src/Utils.cpp` | `Utils::toHex` (upstream) |
|
||||
|
||||
|
||||
@@ -0,0 +1,70 @@
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
#include <cstdlib>
|
||||
#include <vector>
|
||||
|
||||
#include "helpers/MQTTRuntimeBufferLifecycle.h"
|
||||
|
||||
namespace RuntimeBuffers = MQTTRuntimeBufferLifecycle;
|
||||
|
||||
TEST(MQTTRuntimeBufferLifecycle, PartialAllocationKeepsOtherBuffersAndRetriesOnlyMissing) {
|
||||
std::vector<size_t> allocation_sizes;
|
||||
int allocation_attempt = 0;
|
||||
const auto allocate = [&allocation_sizes, &allocation_attempt](size_t size) -> void* {
|
||||
allocation_sizes.push_back(size);
|
||||
allocation_attempt++;
|
||||
if (allocation_attempt == 2) {
|
||||
return nullptr;
|
||||
}
|
||||
return std::malloc(size);
|
||||
};
|
||||
|
||||
void* raw = nullptr;
|
||||
void* publish = nullptr;
|
||||
void* status = nullptr;
|
||||
|
||||
raw = RuntimeBuffers::allocateIfMissing(raw, 256, allocate);
|
||||
publish = RuntimeBuffers::allocateIfMissing(publish, 2048, allocate);
|
||||
status = RuntimeBuffers::allocateIfMissing(status, 768, allocate);
|
||||
|
||||
ASSERT_NE(nullptr, raw);
|
||||
EXPECT_EQ(nullptr, publish);
|
||||
ASSERT_NE(nullptr, status);
|
||||
ASSERT_EQ(3U, allocation_sizes.size());
|
||||
void* const initial_raw = raw;
|
||||
void* const initial_status = status;
|
||||
|
||||
raw = RuntimeBuffers::allocateIfMissing(raw, 256, allocate);
|
||||
publish = RuntimeBuffers::allocateIfMissing(publish, 2048, allocate);
|
||||
status = RuntimeBuffers::allocateIfMissing(status, 768, allocate);
|
||||
|
||||
EXPECT_EQ(4U, allocation_sizes.size());
|
||||
EXPECT_EQ(2048U, allocation_sizes.back());
|
||||
EXPECT_EQ(initial_raw, raw);
|
||||
EXPECT_EQ(initial_status, status);
|
||||
EXPECT_NE(nullptr, publish);
|
||||
|
||||
int releases = 0;
|
||||
const auto release = [&releases](void* allocation) {
|
||||
releases++;
|
||||
std::free(allocation);
|
||||
};
|
||||
raw = RuntimeBuffers::release(raw, release);
|
||||
publish = RuntimeBuffers::release(publish, release);
|
||||
status = RuntimeBuffers::release(status, release);
|
||||
|
||||
EXPECT_EQ(nullptr, raw);
|
||||
EXPECT_EQ(nullptr, publish);
|
||||
EXPECT_EQ(nullptr, status);
|
||||
EXPECT_EQ(3, releases);
|
||||
|
||||
raw = RuntimeBuffers::release(raw, release);
|
||||
publish = RuntimeBuffers::release(publish, release);
|
||||
status = RuntimeBuffers::release(status, release);
|
||||
EXPECT_EQ(3, releases);
|
||||
}
|
||||
|
||||
int main(int argc, char** argv) {
|
||||
::testing::InitGoogleTest(&argc, argv);
|
||||
return RUN_ALL_TESTS();
|
||||
}
|
||||
Reference in new issue
Block a user