scheduler_actor_ut.cpp 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. #include <library/cpp/testing/unittest/registar.h>
  2. #include "scheduler_actor.h"
  3. #include "misc/test_sync.h"
  4. using namespace NBus;
  5. using namespace NBus::NPrivate;
  6. using namespace NActor;
  7. Y_UNIT_TEST_SUITE(TSchedulerActorTests) {
  8. struct TMyActor: public TAtomicRefCount<TMyActor>, public TActor<TMyActor>, public TScheduleActor<TMyActor> {
  9. TTestSync TestSync;
  10. TMyActor(TExecutor* executor, TScheduler* scheduler)
  11. : TActor<TMyActor>(executor)
  12. , TScheduleActor<TMyActor>(scheduler)
  13. , Iteration(0)
  14. {
  15. }
  16. unsigned Iteration;
  17. void Act(TDefaultTag) {
  18. if (!Alarm.FetchTask()) {
  19. Y_ABORT("must not have no spurious wakeups in test");
  20. }
  21. TestSync.WaitForAndIncrement(Iteration++);
  22. if (Iteration <= 5) {
  23. ScheduleAt(TInstant::Now() + TDuration::MilliSeconds(Iteration));
  24. }
  25. }
  26. };
  27. Y_UNIT_TEST(Simple) {
  28. TExecutor executor(1);
  29. TScheduler scheduler;
  30. TIntrusivePtr<TMyActor> actor(new TMyActor(&executor, &scheduler));
  31. actor->ScheduleAt(TInstant::Now() + TDuration::MilliSeconds(1));
  32. actor->TestSync.WaitForAndIncrement(6);
  33. // TODO: stop in destructor
  34. scheduler.Stop();
  35. }
  36. }