aboutsummaryrefslogtreecommitdiffstats
path: root/library/cpp/messagebus/scheduler/scheduler_ut.cpp
blob: a5ea641c108e7f6bb92f2b64bf6a1634e41e1c1e (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#include <library/cpp/testing/unittest/registar.h>

#include "scheduler.h"

#include <library/cpp/messagebus/misc/test_sync.h>

using namespace NBus;
using namespace NBus::NPrivate;

Y_UNIT_TEST_SUITE(TSchedulerTests) {
    struct TSimpleScheduleItem: public IScheduleItem {
        TTestSync* const TestSync;

        TSimpleScheduleItem(TTestSync* testSync)
            : IScheduleItem((TInstant::Now() + TDuration::MilliSeconds(1)))
            , TestSync(testSync)
        {
        }

        void Do() override {
            TestSync->WaitForAndIncrement(0);
        }
    };

    Y_UNIT_TEST(Simple) {
        TTestSync testSync;

        TScheduler scheduler;

        scheduler.Schedule(new TSimpleScheduleItem(&testSync));

        testSync.WaitForAndIncrement(1);

        scheduler.Stop();
    }
}