aboutsummaryrefslogtreecommitdiffstats
path: root/util/thread/factory_ut.cpp
blob: d9a38c5e0e73c44c25567f152c4fd2f206225ea0 (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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#include "factory.h"
#include "pool.h"

#include <library/cpp/testing/unittest/registar.h> 

class TThrPoolTest: public TTestBase {
    UNIT_TEST_SUITE(TThrPoolTest);
    UNIT_TEST(TestSystemPool)
    UNIT_TEST(TestAdaptivePool)
    UNIT_TEST_SUITE_END();

    struct TRunAble: public IThreadFactory::IThreadAble {
        inline TRunAble()
            : done(false)
        {
        }

        ~TRunAble() override = default;

        void DoExecute() override {
            done = true;
        }

        bool done;
    };

private:
    inline void TestSystemPool() {
        TRunAble r;

        {
            THolder<IThreadFactory::IThread> thr = SystemThreadFactory()->Run(&r);

            thr->Join();
        }

        UNIT_ASSERT_EQUAL(r.done, true);
    }

    inline void TestAdaptivePool() {
        TRunAble r;

        {
            TAdaptiveThreadPool pool;

            pool.Start(0);

            THolder<IThreadFactory::IThread> thr = pool.Run(&r);

            thr->Join();
        }

        UNIT_ASSERT_EQUAL(r.done, true);
    }
};

UNIT_TEST_SUITE_REGISTRATION(TThrPoolTest);