factory_ut.cpp 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. #include "factory.h"
  2. #include "pool.h"
  3. #include <library/cpp/testing/unittest/registar.h>
  4. class TThrPoolTest: public TTestBase {
  5. UNIT_TEST_SUITE(TThrPoolTest);
  6. UNIT_TEST(TestSystemPool)
  7. UNIT_TEST(TestAdaptivePool)
  8. UNIT_TEST_SUITE_END();
  9. struct TRunAble: public IThreadFactory::IThreadAble {
  10. inline TRunAble()
  11. : done(false)
  12. {
  13. }
  14. ~TRunAble() override = default;
  15. void DoExecute() override {
  16. done = true;
  17. }
  18. bool done;
  19. };
  20. private:
  21. inline void TestSystemPool() {
  22. TRunAble r;
  23. {
  24. THolder<IThreadFactory::IThread> thr = SystemThreadFactory()->Run(&r);
  25. thr->Join();
  26. }
  27. UNIT_ASSERT_EQUAL(r.done, true);
  28. }
  29. inline void TestAdaptivePool() {
  30. TRunAble r;
  31. {
  32. TAdaptiveThreadPool pool;
  33. pool.Start(0);
  34. THolder<IThreadFactory::IThread> thr = pool.Run(&r);
  35. thr->Join();
  36. }
  37. UNIT_ASSERT_EQUAL(r.done, true);
  38. }
  39. };
  40. UNIT_TEST_SUITE_REGISTRATION(TThrPoolTest);