9
9
10
10
#include < thread>
11
11
#include < future>
12
+ #include < vector>
12
13
13
14
#include < mqtt/broker/broker.hpp>
14
15
@@ -36,6 +37,7 @@ template <typename ClientCreator, typename Test>
36
37
inline void do_test (
37
38
ClientCreator const & cc,
38
39
Test const & test,
40
+ std::size_t clients,
39
41
MQTT_NS::optional<MQTT_NS::protocol_version> v = MQTT_NS::nullopt) {
40
42
boost::asio::io_context iocb;
41
43
MQTT_NS::broker::broker_t b (iocb);
@@ -51,18 +53,26 @@ inline void do_test(
51
53
);
52
54
f.wait ();
53
55
boost::asio::io_context ioc;
54
- auto c =
56
+ auto cs =
55
57
[&] {
58
+ BOOST_ASSERT (clients > 0 );
59
+ std::vector<decltype (cc (ioc, broker_url, broker_notls_port))> cs;
60
+ cs.reserve (clients);
56
61
if (v) {
57
- return cc (ioc, broker_url, broker_notls_port, v.value ());
62
+ for (std::size_t i = 0 ; i != clients; ++i) {
63
+ cs.push_back (cc (ioc, broker_url, broker_notls_port, v.value ()));
64
+ }
58
65
}
59
66
else {
60
- return cc (ioc, broker_url, broker_notls_port);
67
+ for (std::size_t i = 0 ; i != clients; ++i) {
68
+ cs.push_back (cc (ioc, broker_url, broker_notls_port));
69
+ }
61
70
}
71
+ return cs;
62
72
} ();
63
73
test (
64
74
ioc,
65
- c ,
75
+ cs ,
66
76
[&] {
67
77
as::post (
68
78
iocb,
@@ -90,6 +100,7 @@ template <typename ClientCreator, typename Test>
90
100
inline void do_tls_test (
91
101
ClientCreator const & cc,
92
102
Test const & test,
103
+ std::size_t clients,
93
104
MQTT_NS::optional<MQTT_NS::protocol_version> v = MQTT_NS::nullopt) {
94
105
boost::asio::io_context iocb;
95
106
MQTT_NS::broker::broker_t b (iocb);
@@ -105,22 +116,32 @@ inline void do_tls_test(
105
116
);
106
117
f.wait ();
107
118
boost::asio::io_context ioc;
108
- auto c =
119
+ auto cs =
109
120
[&] {
121
+ BOOST_ASSERT (clients > 0 );
122
+ std::vector<decltype (cc (ioc, broker_url, broker_tls_port))> cs;
123
+ cs.reserve (clients);
110
124
if (v) {
111
- return cc (ioc, broker_url, broker_tls_port, v.value ());
125
+ for (std::size_t i = 0 ; i != clients; ++i) {
126
+ cs.push_back (cc (ioc, broker_url, broker_tls_port, v.value ()));
127
+ }
112
128
}
113
129
else {
114
- return cc (ioc, broker_url, broker_tls_port);
130
+ for (std::size_t i = 0 ; i != clients; ++i) {
131
+ cs.push_back (cc (ioc, broker_url, broker_tls_port));
132
+ }
115
133
}
134
+ return cs;
116
135
} ();
117
136
std::string path = boost::unit_test::framework::master_test_suite ().argv [0 ];
118
137
std::size_t pos = path.find_last_of (" /\\ " );
119
138
std::string base = (pos == std::string::npos) ? " " : path.substr (0 , pos + 1 );
120
- c->get_ssl_context ().load_verify_file (base + " cacert.pem" );
139
+ for (auto & c : cs) {
140
+ c->get_ssl_context ().load_verify_file (base + " cacert.pem" );
141
+ }
121
142
test (
122
143
ioc,
123
- c ,
144
+ cs ,
124
145
[&] {
125
146
as::post (
126
147
iocb,
@@ -144,6 +165,7 @@ template <typename ClientCreator, typename Test>
144
165
inline void do_ws_test (
145
166
ClientCreator const & cc,
146
167
Test const & test,
168
+ std::size_t clients,
147
169
MQTT_NS::optional<MQTT_NS::protocol_version> v = MQTT_NS::nullopt) {
148
170
boost::asio::io_context iocb;
149
171
MQTT_NS::broker::broker_t b (iocb);
@@ -159,18 +181,26 @@ inline void do_ws_test(
159
181
);
160
182
f.wait ();
161
183
boost::asio::io_context ioc;
162
- auto c =
184
+ auto cs =
163
185
[&] {
186
+ BOOST_ASSERT (clients > 0 );
187
+ std::vector<decltype (cc (ioc, broker_url, broker_notls_ws_port))> cs;
188
+ cs.reserve (clients);
164
189
if (v) {
165
- return cc (ioc, broker_url, broker_notls_ws_port, " /" , v.value ());
190
+ for (std::size_t i = 0 ; i != clients; ++i) {
191
+ cs.push_back (cc (ioc, broker_url, broker_notls_ws_port, " /" , v.value ()));
192
+ }
166
193
}
167
194
else {
168
- return cc (ioc, broker_url, broker_notls_ws_port);
195
+ for (std::size_t i = 0 ; i != clients; ++i) {
196
+ cs.push_back (cc (ioc, broker_url, broker_notls_ws_port));
197
+ }
169
198
}
199
+ return cs;
170
200
} ();
171
201
test (
172
202
ioc,
173
- c ,
203
+ cs ,
174
204
[&] {
175
205
as::post (
176
206
iocb,
@@ -192,6 +222,7 @@ template <typename ClientCreator, typename Test>
192
222
inline void do_tls_ws_test (
193
223
ClientCreator const & cc,
194
224
Test const & test,
225
+ std::size_t clients,
195
226
MQTT_NS::optional<MQTT_NS::protocol_version> v = MQTT_NS::nullopt) {
196
227
boost::asio::io_context iocb;
197
228
MQTT_NS::broker::broker_t b (iocb);
@@ -207,22 +238,32 @@ inline void do_tls_ws_test(
207
238
);
208
239
f.wait ();
209
240
boost::asio::io_context ioc;
210
- auto c =
241
+ auto cs =
211
242
[&] {
243
+ BOOST_ASSERT (clients > 0 );
244
+ std::vector<decltype (cc (ioc, broker_url, broker_tls_ws_port))> cs;
245
+ cs.reserve (clients);
212
246
if (v) {
213
- return cc (ioc, broker_url, broker_tls_ws_port, " /" , v.value ());
247
+ for (std::size_t i = 0 ; i != clients; ++i) {
248
+ cs.push_back (cc (ioc, broker_url, broker_tls_ws_port, " /" , v.value ()));
249
+ }
214
250
}
215
251
else {
216
- return cc (ioc, broker_url, broker_tls_ws_port);
252
+ for (std::size_t i = 0 ; i != clients; ++i) {
253
+ cs.push_back (cc (ioc, broker_url, broker_tls_ws_port));
254
+ }
217
255
}
256
+ return cs;
218
257
} ();
219
258
std::string path = boost::unit_test::framework::master_test_suite ().argv [0 ];
220
259
std::size_t pos = path.find_last_of (" /\\ " );
221
260
std::string base = (pos == std::string::npos) ? " " : path.substr (0 , pos + 1 );
222
- c->get_ssl_context ().load_verify_file (base + " cacert.pem" );
261
+ for (auto & c : cs) {
262
+ c->get_ssl_context ().load_verify_file (base + " cacert.pem" );
263
+ }
223
264
test (
224
265
ioc,
225
- c ,
266
+ cs ,
226
267
[&] {
227
268
as::post (
228
269
iocb,
@@ -243,137 +284,161 @@ inline void do_tls_ws_test(
243
284
244
285
245
286
template <typename Test>
246
- inline void do_combi_test (Test const & test) {
287
+ inline void do_combi_test (Test const & test, std:: size_t clients = 1 ) {
247
288
do_test (
248
289
[&](auto &&... args) { return MQTT_NS::make_client (std::forward<decltype (args)>(args)...); },
249
- test
290
+ test,
291
+ clients
250
292
);
251
293
do_test (
252
294
[&](auto &&... args) { return MQTT_NS::make_client (std::forward<decltype (args)>(args)...); },
253
295
test,
296
+ clients,
254
297
MQTT_NS::protocol_version::v5
255
298
);
256
299
#if defined(MQTT_USE_TLS)
257
300
do_tls_test (
258
301
[&](auto &&... args) { return MQTT_NS::make_tls_client (std::forward<decltype (args)>(args)...); },
259
- test
302
+ test,
303
+ clients
260
304
);
261
305
do_tls_test (
262
306
[&](auto &&... args) { return MQTT_NS::make_tls_client (std::forward<decltype (args)>(args)...); },
263
307
test,
308
+ clients,
264
309
MQTT_NS::protocol_version::v5
265
310
);
266
311
#endif // defined(MQTT_USE_TLS)
267
312
#if defined(MQTT_USE_WS)
268
313
do_ws_test (
269
314
[&](auto &&... args) { return MQTT_NS::make_client_ws (std::forward<decltype (args)>(args)...); },
270
- test
315
+ test,
316
+ clients
271
317
);
272
318
do_ws_test (
273
319
[&](auto &&... args) { return MQTT_NS::make_client_ws (std::forward<decltype (args)>(args)...); },
274
320
test,
321
+ clients,
275
322
MQTT_NS::protocol_version::v5
276
323
);
277
324
#if defined(MQTT_USE_TLS)
278
325
do_tls_ws_test (
279
326
[&](auto &&... args) { return MQTT_NS::make_tls_client_ws (std::forward<decltype (args)>(args)...); },
280
- test
327
+ test,
328
+ clients
281
329
);
282
330
do_tls_ws_test (
283
331
[&](auto &&... args) { return MQTT_NS::make_tls_client_ws (std::forward<decltype (args)>(args)...); },
284
332
test,
333
+ clients,
285
334
MQTT_NS::protocol_version::v5
286
335
);
287
336
#endif // defined(MQTT_USE_TLS)
288
337
#endif // defined(MQTT_USE_WS)
289
338
}
290
339
291
340
template <typename Test>
292
- inline void do_combi_test_sync (Test const & test) {
341
+ inline void do_combi_test_sync (Test const & test, std:: size_t clients = 1 ) {
293
342
do_test (
294
343
[&](auto &&... args) { return MQTT_NS::make_sync_client (std::forward<decltype (args)>(args)...); },
295
- test
344
+ test,
345
+ clients
296
346
);
297
347
do_test (
298
348
[&](auto &&... args) { return MQTT_NS::make_sync_client (std::forward<decltype (args)>(args)...); },
299
349
test,
350
+ clients,
300
351
MQTT_NS::protocol_version::v5
301
352
);
302
353
#if defined(MQTT_USE_TLS)
303
354
do_tls_test (
304
355
[&](auto &&... args) { return MQTT_NS::make_tls_sync_client (std::forward<decltype (args)>(args)...); },
305
- test
356
+ test,
357
+ clients
306
358
);
307
359
do_tls_test (
308
360
[&](auto &&... args) { return MQTT_NS::make_tls_sync_client (std::forward<decltype (args)>(args)...); },
309
361
test,
362
+ clients,
310
363
MQTT_NS::protocol_version::v5
311
364
);
312
365
#endif // defined(MQTT_USE_TLS)
313
366
#if defined(MQTT_USE_WS)
314
367
do_ws_test (
315
368
[&](auto &&... args) { return MQTT_NS::make_sync_client_ws (std::forward<decltype (args)>(args)...); },
316
- test
369
+ test,
370
+ clients
317
371
);
318
372
do_ws_test (
319
373
[&](auto &&... args) { return MQTT_NS::make_sync_client_ws (std::forward<decltype (args)>(args)...); },
320
374
test,
375
+ clients,
321
376
MQTT_NS::protocol_version::v5
322
377
);
323
378
#if defined(MQTT_USE_TLS)
324
379
do_tls_ws_test (
325
380
[&](auto &&... args) { return MQTT_NS::make_tls_sync_client_ws (std::forward<decltype (args)>(args)...); },
326
- test
381
+ test,
382
+ clients
327
383
);
328
384
do_tls_ws_test (
329
385
[&](auto &&... args) { return MQTT_NS::make_tls_sync_client_ws (std::forward<decltype (args)>(args)...); },
330
386
test,
387
+ clients,
331
388
MQTT_NS::protocol_version::v5
332
389
);
333
390
#endif // defined(MQTT_USE_TLS)
334
391
#endif // defined(MQTT_USE_WS)
335
392
}
336
393
337
394
template <typename Test>
338
- inline void do_combi_test_async (Test const & test) {
395
+ inline void do_combi_test_async (Test const & test, std:: size_t clients = 1 ) {
339
396
do_test (
340
397
[&](auto &&... args) { return MQTT_NS::make_async_client (std::forward<decltype (args)>(args)...); },
341
- test
398
+ test,
399
+ clients
342
400
);
343
401
do_test (
344
402
[&](auto &&... args) { return MQTT_NS::make_async_client (std::forward<decltype (args)>(args)...); },
345
403
test,
404
+ clients,
346
405
MQTT_NS::protocol_version::v5
347
406
);
348
407
#if defined(MQTT_USE_TLS)
349
408
do_tls_test (
350
409
[&](auto &&... args) { return MQTT_NS::make_tls_async_client (std::forward<decltype (args)>(args)...); },
351
- test
410
+ test,
411
+ clients
352
412
);
353
413
do_tls_test (
354
414
[&](auto &&... args) { return MQTT_NS::make_tls_async_client (std::forward<decltype (args)>(args)...); },
355
415
test,
416
+ clients,
356
417
MQTT_NS::protocol_version::v5
357
418
);
358
419
#endif // defined(MQTT_USE_TLS)
359
420
#if defined(MQTT_USE_WS)
360
421
do_ws_test (
361
422
[&](auto &&... args) { return MQTT_NS::make_async_client_ws (std::forward<decltype (args)>(args)...); },
362
- test
423
+ test,
424
+ clients
363
425
);
364
426
do_ws_test (
365
427
[&](auto &&... args) { return MQTT_NS::make_async_client_ws (std::forward<decltype (args)>(args)...); },
366
428
test,
429
+ clients,
367
430
MQTT_NS::protocol_version::v5
368
431
);
369
432
#if defined(MQTT_USE_TLS)
370
433
do_tls_ws_test (
371
434
[&](auto &&... args) { return MQTT_NS::make_tls_async_client_ws (std::forward<decltype (args)>(args)...); },
372
- test
435
+ test,
436
+ clients
373
437
);
374
438
do_tls_ws_test (
375
439
[&](auto &&... args) { return MQTT_NS::make_tls_async_client_ws (std::forward<decltype (args)>(args)...); },
376
440
test,
441
+ clients,
377
442
MQTT_NS::protocol_version::v5
378
443
);
379
444
#endif // defined(MQTT_USE_TLS)
0 commit comments