main.cpp 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. #include <library/cpp/testing/unittest/registar.h>
  2. #include <library/cpp/bucket_quoter/bucket_quoter.h>
  3. #include "test_namespace.h"
  4. using NBucketQuoterTest::TMockTimer;
  5. #define TEST_RPS_EXACT(THREADS, RPS, EXPECTED_RESULT, TIMER) \
  6. Y_UNIT_TEST(Test##TIMER##RPS##Rps##THREADS##Threads) { \
  7. ui32 seconds = 10; \
  8. ui32 summary_requests = NBucketQuoterTest::Run<TIMER, NBucketQuoterTest::TTestScenario>\
  9. (THREADS, RPS, seconds);\
  10. ui32 total_rps = summary_requests / seconds; \
  11. UNIT_ASSERT_EQUAL(total_rps, EXPECTED_RESULT);\
  12. }
  13. #define TEST_RPS_LESS(THREADS, RPS, UPPER_BOUND, TIMER) \
  14. Y_UNIT_TEST(Test##TIMER##RPS##rps##THREADS##threads) { \
  15. ui32 seconds = 10; \
  16. ui32 summary_requests = NBucketQuoterTest::Run<TIMER, NBucketQuoterTest::TTestScenario>\
  17. (THREADS, RPS, seconds); \
  18. ui32 total_rps = summary_requests / seconds; \
  19. UNIT_ASSERT_LE(total_rps, UPPER_BOUND); \
  20. }
  21. Y_UNIT_TEST_SUITE(TMockTimerTest) {
  22. TEST_RPS_EXACT(1, 100, 100, TMockTimer)
  23. TEST_RPS_EXACT(1, 120, 60, TMockTimer)
  24. TEST_RPS_EXACT(1, 200, 200, TMockTimer)
  25. TEST_RPS_EXACT(1, 220, 110, TMockTimer)
  26. TEST_RPS_EXACT(1, 240, 120, TMockTimer)
  27. TEST_RPS_EXACT(1, 300, 150, TMockTimer)
  28. TEST_RPS_EXACT(1, 320, 320, TMockTimer)
  29. TEST_RPS_EXACT(1, 480, 240, TMockTimer)
  30. }
  31. Y_UNIT_TEST_SUITE(TInstantTimerTest) {
  32. TEST_RPS_LESS(1, 360, 300, TInstantTimerMs)
  33. TEST_RPS_LESS(1, 480, 400, TInstantTimerMs)
  34. TEST_RPS_LESS(5, 420, 350, TInstantTimerMs)
  35. TEST_RPS_LESS(5, 220, 185, TInstantTimerMs)
  36. }