diff --git a/common/test/test_throttle.cpp b/common/test/test_throttle.cpp index 24b04409..618412be 100644 --- a/common/test/test_throttle.cpp +++ b/common/test/test_throttle.cpp @@ -166,7 +166,8 @@ TEST(Throttle, try_consume) { } //////////////////////////////////////// -#if defined(NDEBUG) && !defined(__APPLE__) +// The sleep and semaphore in macOS is less efficient and always cause variance, so skip macOS +#ifndef __APPLE__ struct FindAppropriateSliceNumSuite { uint64_t slice_num; @@ -177,6 +178,8 @@ class FindAppropriateSliceNumTest : public testing::TestWithParam { INSTANTIATE_TEST_P(Throttle, ThrottlePriorityTest, testing::Values( PriorityTestSuite{ - // 0 + // 0. Simulate same priority and equally divide the BW PriorityTestSuite::Simulate, 100'000'000, {50'000'000, 100'000, photon::throttle::Priority::High}, @@ -260,7 +263,7 @@ INSTANTIATE_TEST_P(Throttle, ThrottlePriorityTest, testing::Values( 0.4, 0.6, }, PriorityTestSuite{ - // 1 + // 1. Simulate same priority but different BW, results are still the same PriorityTestSuite::Simulate, 100'000'000, {50'000'000, 1'000'000, photon::throttle::Priority::High}, @@ -269,7 +272,7 @@ INSTANTIATE_TEST_P(Throttle, ThrottlePriorityTest, testing::Values( 0.4, 0.6, }, PriorityTestSuite{ - // 2 + // 2. Simulate different priorities with the same BW. Total BW exceeds limit PriorityTestSuite::Simulate, 100'000'000, {100'000'000, 500'000, photon::throttle::Priority::High}, @@ -278,7 +281,7 @@ INSTANTIATE_TEST_P(Throttle, ThrottlePriorityTest, testing::Values( 0.0, 0.1, }, PriorityTestSuite{ - // 3 + // 3. Simulate different priorities with the same BW. Total BW under the limit PriorityTestSuite::Simulate, 100'000'000, {30'000'000, 1'000'000, photon::throttle::Priority::High}, @@ -287,7 +290,7 @@ INSTANTIATE_TEST_P(Throttle, ThrottlePriorityTest, testing::Values( 0.3, 0.7, }, PriorityTestSuite{ - // 4 + // 4. Simulate different priorities with different BW. Total BW exceeds limit PriorityTestSuite::Simulate, 100'000'000, {50'000'000, 5'000'000, photon::throttle::Priority::High}, @@ -296,7 +299,8 @@ INSTANTIATE_TEST_P(Throttle, ThrottlePriorityTest, testing::Values( 0.45, 0.6, }, PriorityTestSuite{ - // 5. For now there is no way to balance throttle throughput of the same priority. + // 5. Real socket. For now there is no way to balance throttle throughput of the same priority. + // Maybe we need a WFQ in the future. PriorityTestSuite::RealSocket, 1'000'000'000, {1'000'000'000, 1048576, photon::throttle::Priority::High}, @@ -305,7 +309,7 @@ INSTANTIATE_TEST_P(Throttle, ThrottlePriorityTest, testing::Values( 0.0, 1.0, }, PriorityTestSuite{ - // 6 + // 6. Real socket. High priority get most BW PriorityTestSuite::RealSocket, 1'000'000'000, {800'000'000, 32768, photon::throttle::Priority::High}, @@ -314,7 +318,7 @@ INSTANTIATE_TEST_P(Throttle, ThrottlePriorityTest, testing::Values( 0.1, 0.3, }, PriorityTestSuite{ - // 7 + // 7. Real socket. Low priority gets the rest BW that high priority doesn't need PriorityTestSuite::RealSocket, 10'000'000, {5'000'000, 10'000, photon::throttle::Priority::High}, @@ -436,8 +440,8 @@ TEST_P(ThrottlePriorityTest, run) { #endif int main(int argc, char** argv) { - if (!photon::is_using_default_engine()) return 0; - photon::init(0, 0); + int ret = photon::init(photon::INIT_EVENT_DEFAULT, photon::INIT_IO_NONE); + if (ret) return -1; DEFER(photon::fini()); testing::InitGoogleTest(&argc, argv); return RUN_ALL_TESTS(); diff --git a/common/throttle.h b/common/throttle.h index c3fcbb45..6cfde219 100644 --- a/common/throttle.h +++ b/common/throttle.h @@ -79,8 +79,8 @@ class throttle { if (sem.count() * 100 < m_limit * fulfil_percent) { // Request are fulfilled only if they saw enough percent of tokens, // otherwise wait a `time_window_per_slice`. - ret = photon::thread_usleep(m_time_window_per_slice); - if (ret != 0) { + int sleep_ret = photon::thread_usleep(m_time_window_per_slice); + if (sleep_ret != 0) { // Interrupted, just return return -1; }