@@ -40,14 +40,25 @@ UNIT_TEST(ThreadPoolDelayed_SimpleSync)
40
40
bool done = false ;
41
41
42
42
ThreadPool thread;
43
- TEST_NOT_EQUAL (thread.Push ([&value]() { ++value; }), ThreadPool::kIncorrectId , ());
44
- TEST_NOT_EQUAL (thread.Push ([&value]() { value *= 2 ; }), ThreadPool::kIncorrectId , ());
45
- TEST_NOT_EQUAL (thread.Push ([&value]() { value = value * value * value; }), ThreadPool::kIncorrectId , ());
46
- TEST_NOT_EQUAL (thread.Push ([&]() {
43
+ auto pushResult = thread.Push ([&value]() { ++value; });
44
+ TEST (pushResult.m_isSuccess , ());
45
+ TEST_NOT_EQUAL (pushResult.m_id , ThreadPool::kIncorrectId , ());
46
+
47
+ pushResult = thread.Push ([&value]() { value *= 2 ; });
48
+ TEST (pushResult.m_isSuccess , ());
49
+ TEST_NOT_EQUAL (pushResult.m_id , ThreadPool::kIncorrectId , ());
50
+
51
+ pushResult = thread.Push ([&value]() { value = value * value * value; });
52
+ TEST (pushResult.m_isSuccess , ());
53
+ TEST_NOT_EQUAL (pushResult.m_id , ThreadPool::kIncorrectId , ());
54
+
55
+ pushResult = thread.Push ([&]() {
47
56
lock_guard<mutex> lk (mu);
48
57
done = true ;
49
58
cv.notify_one ();
50
- }), ThreadPool::kIncorrectId , ());
59
+ });
60
+ TEST (pushResult.m_isSuccess , ());
61
+ TEST_NOT_EQUAL (pushResult.m_id , ThreadPool::kIncorrectId , ());
51
62
52
63
{
53
64
unique_lock<mutex> lk (mu);
@@ -62,11 +73,17 @@ UNIT_TEST(ThreadPoolDelayed_SimpleFlush)
62
73
int value = 0 ;
63
74
{
64
75
ThreadPool thread;
65
- TEST_NOT_EQUAL (thread.Push ([&value]() { ++value; }), ThreadPool::kIncorrectId , ());
66
- TEST_NOT_EQUAL (thread.Push ([&value]() {
76
+ auto pushResult = thread.Push ([&value]() { ++value; });
77
+ TEST (pushResult.m_isSuccess , ());
78
+ TEST_NOT_EQUAL (pushResult.m_id , ThreadPool::kIncorrectId , ());
79
+
80
+ pushResult = thread.Push ([&value]() {
67
81
for (int i = 0 ; i < 10 ; ++i)
68
82
value *= 2 ;
69
- }), ThreadPool::kIncorrectId , ());
83
+ });
84
+ TEST (pushResult.m_isSuccess , ());
85
+ TEST_NOT_EQUAL (pushResult.m_id , ThreadPool::kIncorrectId , ());
86
+
70
87
TEST (thread.Shutdown (ThreadPool::Exit::ExecPending), ());
71
88
}
72
89
TEST_EQUAL (value, 1024 , ());
@@ -80,12 +97,15 @@ UNIT_TEST(ThreadPoolDelayed_PushFromPendingTask)
80
97
auto f = p.get_future ();
81
98
82
99
ThreadPool thread;
83
- auto const id = thread.Push ([&f, &thread]() {
100
+ auto const pushResult = thread.Push ([&f, &thread]() {
84
101
f.get ();
85
- auto const id = thread.Push ([]() { TEST (false , (" This task should not be executed" )); });
86
- TEST_EQUAL (id, ThreadPool::kIncorrectId , ());
102
+ auto const pushResult = thread.Push ([]() { TEST (false , (" This task should not be executed" )); });
103
+ TEST (!pushResult.m_isSuccess , ());
104
+ TEST_EQUAL (pushResult.m_id , ThreadPool::kIncorrectId , ());
87
105
});
88
- TEST_NOT_EQUAL (id, ThreadPool::kIncorrectId , ());
106
+ TEST (pushResult.m_isSuccess , ());
107
+ TEST_NOT_EQUAL (pushResult.m_id , ThreadPool::kIncorrectId , ());
108
+
89
109
thread.Shutdown (ThreadPool::Exit::ExecPending);
90
110
p.set_value ();
91
111
}
@@ -112,15 +132,19 @@ UNIT_TEST(ThreadPoolDelayed_DelayedAndImmediateTasks)
112
132
auto & entry = delayedEntries[i];
113
133
entry.m_start = thread.Now ();
114
134
entry.m_delay = milliseconds (i + 1 );
115
- auto const id = thread.PushDelayed (entry.m_delay , [&]() { entry.m_end = thread.Now (); });
116
- TEST_NOT_EQUAL (id, ThreadPool::kIncorrectId , ());
135
+
136
+ auto const pushResult = thread.PushDelayed (entry.m_delay , [&]() { entry.m_end = thread.Now (); });
137
+ TEST (pushResult.m_isSuccess , ());
138
+ TEST_NOT_EQUAL (pushResult.m_id , ThreadPool::kIncorrectId , ());
117
139
}
118
140
119
141
for (int i = 0 ; i < kNumTasks ; ++i)
120
142
{
121
143
auto & entry = immediateEntries[i];
122
- auto const id = thread.Push ([&]() { entry = thread.Now (); });
123
- TEST_NOT_EQUAL (id, ThreadPool::kIncorrectId , ());
144
+ auto const pushResult = thread.Push ([&]() { entry = thread.Now (); });
145
+
146
+ TEST (pushResult.m_isSuccess , ());
147
+ TEST_NOT_EQUAL (pushResult.m_id , ThreadPool::kIncorrectId , ());
124
148
}
125
149
126
150
thread.Shutdown (ThreadPool::Exit::ExecPending);
@@ -147,23 +171,26 @@ UNIT_TEST(ThreadPoolDelayed_CancelImmediate)
147
171
TaskLoop::TaskId cancelTaskId;
148
172
ThreadPool thread;
149
173
{
150
- auto const id = thread.Push ([&value]() {
174
+ auto const pushResult = thread.Push ([&value]() {
151
175
++value;
152
176
testing::Wait ();
153
177
});
154
- TEST_EQUAL (id, ThreadPool::kImmediateMinId , ());
178
+ TEST (pushResult.m_isSuccess , ());
179
+ TEST_EQUAL (pushResult.m_id , ThreadPool::kImmediateMinId , ());
155
180
}
156
181
157
182
{
158
- cancelTaskId = thread.Push ([&]() { value += 1023 ; });
183
+ auto const pushResult = thread.Push ([&]() { value += 1023 ; });
184
+ TEST (pushResult.m_isSuccess , ());
185
+ TEST_EQUAL (pushResult.m_id , ThreadPool::kImmediateMinId + 1 , ());
159
186
160
- TEST_EQUAL ( cancelTaskId, ThreadPool:: kImmediateMinId + 1 , ()) ;
187
+ cancelTaskId = pushResult. m_id ;
161
188
}
162
189
163
190
{
164
- auto const id = thread.Push ([&]() { ++value; });
165
-
166
- TEST_EQUAL (id , ThreadPool::kImmediateMinId + 2 , ());
191
+ auto const pushResult = thread.Push ([&]() { ++value; });
192
+ TEST (pushResult. m_isSuccess , ());
193
+ TEST_EQUAL (pushResult. m_id , ThreadPool::kImmediateMinId + 2 , ());
167
194
}
168
195
169
196
TEST (thread.Cancel (cancelTaskId), ());
@@ -184,23 +211,29 @@ UNIT_TEST(ThreadPoolDelayed_CancelDelayed)
184
211
TaskLoop::TaskId cancelTaskId;
185
212
ThreadPool thread;
186
213
{
187
- auto const id = thread.Push ([]() { testing::Wait (); });
188
- TEST_EQUAL (id, ThreadPool::kImmediateMinId , ());
214
+ auto const pushResult = thread.Push ([]() { testing::Wait (); });
215
+ TEST (pushResult.m_isSuccess , ());
216
+ TEST_EQUAL (pushResult.m_id , ThreadPool::kImmediateMinId , ());
189
217
}
190
218
191
219
{
192
- auto const delayedId = thread.PushDelayed (milliseconds (1 ), [&value]() { ++value; });
193
- TEST_EQUAL (delayedId, ThreadPool::kDelayedMinId , ());
220
+ auto const pushResult = thread.PushDelayed (milliseconds (1 ), [&value]() { ++value; });
221
+ TEST (pushResult.m_isSuccess , ());
222
+ TEST_EQUAL (pushResult.m_id , ThreadPool::kDelayedMinId , ());
194
223
}
195
224
196
225
{
197
- cancelTaskId = thread.PushDelayed (milliseconds (2 ), [&]() { value += 1023 ; });
198
- TEST_EQUAL (cancelTaskId, ThreadPool::kDelayedMinId + 1 , ());
226
+ auto const pushResult = thread.PushDelayed (milliseconds (2 ), [&]() { value += 1023 ; });
227
+ TEST (pushResult.m_isSuccess , ());
228
+ TEST_EQUAL (pushResult.m_id , ThreadPool::kDelayedMinId + 1 , ());
229
+
230
+ cancelTaskId = pushResult.m_id ;
199
231
}
200
232
201
233
{
202
- auto const delayedId = thread.PushDelayed (milliseconds (3 ), [&value]() { ++value; });
203
- TEST_EQUAL (delayedId, ThreadPool::kDelayedMinId + 2 , ());
234
+ auto const pushResult = thread.PushDelayed (milliseconds (3 ), [&value]() { ++value; });
235
+ TEST (pushResult.m_isSuccess , ());
236
+ TEST_EQUAL (pushResult.m_id , ThreadPool::kDelayedMinId + 2 , ());
204
237
}
205
238
206
239
TEST (thread.Cancel (cancelTaskId), ());
0 commit comments