@@ -56,6 +56,9 @@ TEST(AlarmTest, Create) {
56
56
// Leave plenty of time for all the alarms to fire.
57
57
std::this_thread::sleep_for (TEST_TIMEOUT);
58
58
59
+ // Acquire the lock to check the callbacks.
60
+ std::lock_guard<std::mutex> guard (m);
61
+
59
62
// Make sure all the alarms fired around the expected time.
60
63
for (size_t i = 0 ; i < 5 ; ++i)
61
64
EXPECT_GE (callbacks_actual[i], callbacks_expected[i]);
@@ -83,6 +86,9 @@ TEST(AlarmTest, Exit) {
83
86
// Let the alarm go out of scope before any alarm had a chance to fire.
84
87
}
85
88
89
+ // Acquire the lock to check the callbacks.
90
+ std::lock_guard<std::mutex> guard (m);
91
+
86
92
// Make sure none of the alarms fired.
87
93
for (bool callback : callbacks)
88
94
EXPECT_TRUE (callback);
@@ -113,6 +119,9 @@ TEST(AlarmTest, Cancel) {
113
119
// Leave plenty of time for all the alarms to fire.
114
120
std::this_thread::sleep_for (TEST_TIMEOUT);
115
121
122
+ // Acquire the lock to check the callbacks.
123
+ std::lock_guard<std::mutex> guard (m);
124
+
116
125
// Make sure none of the first 4 alarms fired.
117
126
for (size_t i = 0 ; i < 4 ; ++i)
118
127
EXPECT_FALSE (callbacks[i]);
@@ -146,13 +155,17 @@ TEST(AlarmTest, Restart) {
146
155
147
156
// Update the last 2 alarms.
148
157
for (size_t i = 3 ; i < 5 ; ++i) {
158
+ std::lock_guard<std::mutex> guard (m);
149
159
callbacks_expected[i] = std::chrono::system_clock::now () + ALARM_TIMEOUT;
150
160
EXPECT_TRUE (alarm .Restart (handles[i]));
151
161
}
152
162
153
163
// Leave plenty of time for all the alarms to fire.
154
164
std::this_thread::sleep_for (TEST_TIMEOUT);
155
165
166
+ // Acquire the lock to check the callbacks.
167
+ std::lock_guard<std::mutex> guard (m);
168
+
156
169
// Make sure all the alarms around the expected time.
157
170
for (size_t i = 0 ; i < 5 ; ++i)
158
171
EXPECT_GE (callbacks_actual[i], callbacks_expected[i]);
0 commit comments