@@ -183,7 +183,7 @@ class FindAppropriateSliceNumTest : public testing::TestWithParam<FindAppropriat
183
183
TEST_P (FindAppropriateSliceNumTest, run) {
184
184
const auto & p = GetParam ();
185
185
186
- const uint64_t test_time_sec = 10 ;
186
+ const uint64_t test_time_sec = 5 ;
187
187
const uint64_t bw = 100'000'000UL ;
188
188
const uint64_t time_window = 1'000'000UL ;
189
189
const uint64_t slice_num = p.slice_num ;
@@ -205,10 +205,10 @@ TEST_P(FindAppropriateSliceNumTest, run) {
205
205
t.consume (bs_per_io);
206
206
bytes += bs_per_io;
207
207
}
208
- auto goal = bw * 10 ;
208
+ auto goal = bw * test_time_sec ;
209
209
auto diff = int64_t (bytes) - int64_t (goal);
210
210
auto loss = double (std::abs (diff)) / double (goal);
211
- LOG_INFO (" Consume ` bytes in 10 seconds, loss ratio `" , bytes, loss);
211
+ LOG_INFO (" Consume ` bytes in ` seconds, loss ratio `" , bytes, test_time_sec , loss);
212
212
GTEST_ASSERT_LE (loss, p.performance_loss_max_ratio );
213
213
}
214
214
@@ -320,24 +320,24 @@ INSTANTIATE_TEST_P(Throttle, ThrottlePriorityTest, testing::Values(
320
320
PriorityTestSuite{
321
321
// 7. Real socket. Low priority gets the rest BW that high priority doesn't need
322
322
PriorityTestSuite::RealSocket,
323
- 10 '000'000 ,
324
- {5 '000'000 , 10'000 , photon::throttle::Priority::High},
325
- {100 '000'000 , 4'000'000 , photon::throttle::Priority::Low},
323
+ 100 '000'000 ,
324
+ {50 '000'000 , 10'000 , photon::throttle::Priority::High},
325
+ {1'000 '000'000 , 4'000'000 , photon::throttle::Priority::Low},
326
326
0.4 , 0.6 ,
327
327
0.4 , 0.6 ,
328
328
}
329
329
));
330
330
331
- static void run_real_socket (const std::atomic<bool >& running, const PriorityTestSuite& p,
331
+ static void run_real_socket (const std::shared_ptr<std:: atomic<bool > >& running, const PriorityTestSuite& p,
332
332
uint64_t & bw1, uint64_t & bw2) {
333
333
photon::throttle t (p.limit_bw );
334
334
uint64_t buf_size = std::max (p.io1 .bs , p.io2 .bs );
335
335
auto server = photon::net::new_tcp_socket_server ();
336
336
DEFER (delete server);
337
337
338
- auto handler = [&](photon::net::ISocketStream* sock) -> int {
338
+ auto handler = [&, _running=running ](photon::net::ISocketStream* sock) -> int {
339
339
char buf[buf_size];
340
- while (running ) {
340
+ while (_running-> load () ) {
341
341
ssize_t ret = sock->recv (buf, buf_size);
342
342
if (ret <= 0 ) break ;
343
343
photon::thread_yield ();
@@ -355,12 +355,12 @@ static void run_real_socket(const std::atomic<bool>& running, const PriorityTest
355
355
auto cli = photon::net::new_tcp_socket_client ();
356
356
DEFER (delete cli);
357
357
358
- photon::thread_create11 ([&] {
358
+ photon::thread_create11 ([&, _running=running ] {
359
359
photon::throttle src (p.io1 .bw );
360
360
auto conn = cli->connect (server_ep);
361
361
DEFER (delete conn);
362
362
char buf[buf_size];
363
- while (running ) {
363
+ while (_running-> load () ) {
364
364
src.consume (p.io1 .bs );
365
365
ssize_t ret = conn->send (buf, p.io1 .bs );
366
366
if (ret <= 0 ) break ;
@@ -369,12 +369,12 @@ static void run_real_socket(const std::atomic<bool>& running, const PriorityTest
369
369
}
370
370
sem.signal (1 );
371
371
});
372
- photon::thread_create11 ([&] {
372
+ photon::thread_create11 ([&, _running=running ] {
373
373
photon::throttle src (p.io2 .bw );
374
374
auto conn = cli->connect (server_ep);
375
375
DEFER (delete conn);
376
376
char buf[buf_size];
377
- while (running ) {
377
+ while (_running-> load () ) {
378
378
src.consume (p.io2 .bs );
379
379
ssize_t ret = conn->send (buf, p.io2 .bs );
380
380
if (ret <= 0 ) break ;
@@ -386,22 +386,22 @@ static void run_real_socket(const std::atomic<bool>& running, const PriorityTest
386
386
sem.wait (2 );
387
387
}
388
388
389
- static void run_simulate (const std::atomic<bool >& running, const PriorityTestSuite& p,
389
+ static void run_simulate (const std::shared_ptr<std:: atomic<bool > >& running, const PriorityTestSuite& p,
390
390
uint64_t & bw1, uint64_t & bw2) {
391
391
photon::throttle t (p.limit_bw );
392
392
photon::semaphore sem;
393
- photon::thread_create11 ([&] {
393
+ photon::thread_create11 ([&, _running=running ] {
394
394
uint64_t sleep_interval = 1'000'000UL / (p.io1 .bw / p.io1 .bs );
395
- while (running ) {
395
+ while (_running-> load () ) {
396
396
photon::thread_usleep (sleep_interval);
397
397
t.consume (p.io1 .bs , p.io1 .prio );
398
398
bw1 += p.io1 .bs ;
399
399
}
400
400
sem.signal (1 );
401
401
});
402
- photon::thread_create11 ([&] {
402
+ photon::thread_create11 ([&, _running=running ] {
403
403
uint64_t sleep_interval = 1'000'000UL / (p.io2 .bw / p.io2 .bs );
404
- while (running ) {
404
+ while (_running-> load () ) {
405
405
photon::thread_usleep (sleep_interval);
406
406
t.consume (p.io2 .bs , p.io2 .prio );
407
407
bw2 += p.io2 .bs ;
@@ -413,13 +413,13 @@ static void run_simulate(const std::atomic<bool>& running, const PriorityTestSui
413
413
414
414
TEST_P (ThrottlePriorityTest, run) {
415
415
const auto & p = GetParam ();
416
- const uint64_t test_time_sec = 10 ;
416
+ const uint64_t test_time_sec = 5 ;
417
417
uint64_t bw1 = 0 , bw2 = 0 ;
418
418
419
- std::atomic<bool > running{ true } ;
419
+ auto running = std::make_shared<std:: atomic<bool >>( true ) ;
420
420
std::thread ([&] {
421
421
::sleep (test_time_sec);
422
- running = false ;
422
+ running-> store ( false ) ;
423
423
}).detach ();
424
424
425
425
if (p.type == PriorityTestSuite::Simulate)
0 commit comments