scheduler_ut.cpp 810 B

123456789101112131415161718192021222324252627282930313233343536
  1. #include <library/cpp/testing/unittest/registar.h>
  2. #include "scheduler.h"
  3. #include <library/cpp/messagebus/misc/test_sync.h>
  4. using namespace NBus;
  5. using namespace NBus::NPrivate;
  6. Y_UNIT_TEST_SUITE(TSchedulerTests) {
  7. struct TSimpleScheduleItem: public IScheduleItem {
  8. TTestSync* const TestSync;
  9. TSimpleScheduleItem(TTestSync* testSync)
  10. : IScheduleItem((TInstant::Now() + TDuration::MilliSeconds(1)))
  11. , TestSync(testSync)
  12. {
  13. }
  14. void Do() override {
  15. TestSync->WaitForAndIncrement(0);
  16. }
  17. };
  18. Y_UNIT_TEST(Simple) {
  19. TTestSync testSync;
  20. TScheduler scheduler;
  21. scheduler.Schedule(new TSimpleScheduleItem(&testSync));
  22. testSync.WaitForAndIncrement(1);
  23. scheduler.Stop();
  24. }
  25. }