test/watchdog: Fix multi-object acquisition
The tests were mistakenly trying to acquire the same DBus path for
watchdog objects while older versions of the objects were still alive.
This fixes the issue by purging the old objects before creating new
ones.
Change-Id: I65bef2f0edab7057c05af9ecd31e554da6565184
Signed-off-by: William A. Kennington III <wak@google.com>
diff --git a/test/watchdog.cpp b/test/watchdog.cpp
index ffcf70f..4f444ed 100644
--- a/test/watchdog.cpp
+++ b/test/watchdog.cpp
@@ -221,6 +221,7 @@
fallback.action = Watchdog::Action::PowerOff;
fallback.interval = static_cast<uint64_t>(fallbackIntervalMs);
fallback.always = false;
+ wdog.reset();
wdog = std::make_unique<Watchdog>(bus, TEST_PATH, event,
Watchdog::ActionTargetMap(),
std::move(fallback));
@@ -303,6 +304,7 @@
fallback.action = Watchdog::Action::PowerOff;
fallback.interval = static_cast<uint64_t>(fallbackIntervalMs);
fallback.always = false;
+ wdog.reset();
wdog = std::make_unique<Watchdog>(bus, TEST_PATH, event,
Watchdog::ActionTargetMap(),
std::move(fallback));
@@ -356,6 +358,7 @@
fallback.action = Watchdog::Action::PowerOff;
fallback.interval = static_cast<uint64_t>(fallbackIntervalMs);
fallback.always = false;
+ wdog.reset();
wdog = std::make_unique<Watchdog>(bus, TEST_PATH, event,
Watchdog::ActionTargetMap(),
std::move(fallback));
@@ -413,6 +416,7 @@
fallback.action = Watchdog::Action::PowerOff;
fallback.interval = static_cast<uint64_t>(fallbackIntervalMs);
fallback.always = true;
+ wdog.reset();
wdog = std::make_unique<Watchdog>(bus, TEST_PATH, event,
Watchdog::ActionTargetMap(), fallback,
milliseconds(TEST_MIN_INTERVAL).count());
@@ -484,6 +488,7 @@
TEST_F(WdogTest, verifyConstructorMinIntervalSetting)
{
// Initiate default Watchdog and get the default interval value.
+ wdog.reset();
wdog = std::make_unique<Watchdog>(bus, TEST_PATH, event);
auto defaultIntervalMs = wdog->interval();
auto defaultInterval = milliseconds(defaultIntervalMs);
@@ -492,6 +497,7 @@
// We initiate a new Watchdog with min interval greater than the default
// intrval
+ wdog.reset();
wdog = std::make_unique<Watchdog>(bus, TEST_PATH, event,
Watchdog::ActionTargetMap(), std::nullopt,
minIntervalMs);