@@ -56,6 +56,9 @@ TEST(AlarmTest, Create) {
5656 // Leave plenty of time for all the alarms to fire.
5757 std::this_thread::sleep_for (TEST_TIMEOUT);
5858
59+ // Acquire the lock to check the callbacks.
60+ std::lock_guard<std::mutex> guard (m);
61+
5962 // Make sure all the alarms fired around the expected time.
6063 for (size_t i = 0 ; i < 5 ; ++i)
6164 EXPECT_GE (callbacks_actual[i], callbacks_expected[i]);
@@ -83,6 +86,9 @@ TEST(AlarmTest, Exit) {
8386 // Let the alarm go out of scope before any alarm had a chance to fire.
8487 }
8588
89+ // Acquire the lock to check the callbacks.
90+ std::lock_guard<std::mutex> guard (m);
91+
8692 // Make sure none of the alarms fired.
8793 for (bool callback : callbacks)
8894 EXPECT_TRUE (callback);
@@ -113,6 +119,9 @@ TEST(AlarmTest, Cancel) {
113119 // Leave plenty of time for all the alarms to fire.
114120 std::this_thread::sleep_for (TEST_TIMEOUT);
115121
122+ // Acquire the lock to check the callbacks.
123+ std::lock_guard<std::mutex> guard (m);
124+
116125 // Make sure none of the first 4 alarms fired.
117126 for (size_t i = 0 ; i < 4 ; ++i)
118127 EXPECT_FALSE (callbacks[i]);
@@ -146,13 +155,17 @@ TEST(AlarmTest, Restart) {
146155
147156 // Update the last 2 alarms.
148157 for (size_t i = 3 ; i < 5 ; ++i) {
158+ std::lock_guard<std::mutex> guard (m);
149159 callbacks_expected[i] = std::chrono::system_clock::now () + ALARM_TIMEOUT;
150160 EXPECT_TRUE (alarm.Restart (handles[i]));
151161 }
152162
153163 // Leave plenty of time for all the alarms to fire.
154164 std::this_thread::sleep_for (TEST_TIMEOUT);
155165
166+ // Acquire the lock to check the callbacks.
167+ std::lock_guard<std::mutex> guard (m);
168+
156169 // Make sure all the alarms around the expected time.
157170 for (size_t i = 0 ; i < 5 ; ++i)
158171 EXPECT_GE (callbacks_actual[i], callbacks_expected[i]);
0 commit comments