Skip to content

Commit 0802da0

Browse files
committed
[test_daemon] use mpt::Signal instead of raw condition variable
Signed-off-by: Mustafa Kemal Gilor <[email protected]>
1 parent 3a31985 commit 0802da0

File tree

1 file changed

+5
-11
lines changed

1 file changed

+5
-11
lines changed

tests/test_daemon.cpp

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
#include "mock_vm_blueprint_provider.h"
3838
#include "mock_vm_image_vault.h"
3939
#include "path.h"
40+
#include "signal.h"
4041
#include "stub_virtual_machine.h"
4142
#include "stub_vm_image_vault.h"
4243
#include "tracking_url_downloader.h"
@@ -386,15 +387,12 @@ TEST_F(Daemon, ensure_that_on_restart_future_completes)
386387
.WillOnce(Return(mp::VirtualMachine::State::stopped));
387388
EXPECT_CALL(*mock_vm, start).Times(1);
388389

389-
std::mutex mtx;
390-
std::condition_variable cv;
391-
bool ready = false;
390+
mpt::Signal signal;
392391
// update_state is called by the finished() handler of the future. If it's called, then
393392
// everything's ok.
394-
EXPECT_CALL(*mock_vm, update_state).WillOnce([&cv, &mtx, &ready] {
393+
EXPECT_CALL(*mock_vm, update_state).WillOnce([&signal] {
395394
// Ensure that update_state is delayed until daemon's destructor call.
396-
std::unique_lock lock(mtx);
397-
cv.wait(lock, [&] { return ready; });
395+
signal.wait();
398396
// Wait a bit to ensure that daemon's destructor has been run
399397
std::this_thread::sleep_for(std::chrono::milliseconds{50});
400398
});
@@ -403,11 +401,7 @@ TEST_F(Daemon, ensure_that_on_restart_future_completes)
403401

404402
{
405403
mp::Daemon daemon{config_builder.build()};
406-
{
407-
std::lock_guard lock(mtx);
408-
ready = true;
409-
}
410-
cv.notify_one();
404+
signal.signal();
411405
}
412406
}
413407

0 commit comments

Comments
 (0)