Skip to content

Commit eb3f7c3

Browse files
committed
system_tests: fix test race condition
1 parent 241f75f commit eb3f7c3

File tree

1 file changed

+18
-14
lines changed

1 file changed

+18
-14
lines changed

src/system_tests/camera_settings.cpp

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -247,15 +247,19 @@ TEST(SystemTest, CameraSettingsAsync)
247247

248248
ASSERT_EQ(camera.camera_list().cameras.size(), 1);
249249

250-
bool found_wb_temp = false;
251-
camera.subscribe_current_settings([&](const Camera::CurrentSettingsUpdate& update) {
252-
for (auto& setting : update.current_settings) {
253-
// std::cout << "setting: " << setting << "\n";
254-
if (setting.setting_id == "WB_TEMP") {
255-
found_wb_temp = true;
250+
std::promise<void> prom_found_wb_temp;
251+
auto fut_found_wb_temp = prom_found_wb_temp.get_future();
252+
253+
Camera::CurrentSettingsHandle handle_settings =
254+
camera.subscribe_current_settings([&](const Camera::CurrentSettingsUpdate& update) {
255+
for (auto& setting : update.current_settings) {
256+
// std::cout << "setting: " << setting << "\n";
257+
if (setting.setting_id == "WB_TEMP") {
258+
camera.unsubscribe_current_settings(handle_settings);
259+
prom_found_wb_temp.set_value();
260+
}
256261
}
257-
}
258-
});
262+
});
259263

260264
// Set white balance mode to manual, so we have the WB_TEMP param available.
261265
Camera::Setting setting{};
@@ -265,15 +269,16 @@ TEST(SystemTest, CameraSettingsAsync)
265269
camera.set_setting(camera.camera_list().cameras[0].component_id, setting),
266270
Camera::Result::Success);
267271

268-
std::this_thread::sleep_for(std::chrono::milliseconds(500));
269-
EXPECT_TRUE(found_wb_temp);
272+
EXPECT_EQ(fut_found_wb_temp.wait_for(std::chrono::seconds(1)), std::future_status::ready);
270273

271-
bool found_exp_absolute = false;
274+
std::promise<void> prom_found_exp_absolute;
275+
auto fut_found_exp_absolute = prom_found_exp_absolute.get_future();
272276
camera.subscribe_possible_setting_options(
273277
[&](const Camera::PossibleSettingOptionsUpdate& update) {
274278
for (auto& setting_options : update.setting_options) {
279+
// std::cout << "setting options: " << setting_options.setting_id << "\n";
275280
if (setting_options.setting_id == "EXP_ABSOLUTE") {
276-
found_exp_absolute = true;
281+
prom_found_exp_absolute.set_value();
277282
}
278283
}
279284
});
@@ -285,6 +290,5 @@ TEST(SystemTest, CameraSettingsAsync)
285290
camera.set_setting(camera.camera_list().cameras[0].component_id, setting),
286291
Camera::Result::Success);
287292

288-
std::this_thread::sleep_for(std::chrono::milliseconds(500));
289-
EXPECT_TRUE(found_exp_absolute);
293+
EXPECT_EQ(fut_found_exp_absolute.wait_for(std::chrono::seconds(1)), std::future_status::ready);
290294
}

0 commit comments

Comments
 (0)