aboutsummaryrefslogtreecommitdiffstats
path: root/kikimr/persqueue/sdk/deprecated/cpp/v2/impl/queue_pool_ut.cpp
blob: 9f8d792e52b7aa2db40aa238bce5d25a9e95303b (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
#include "queue_pool.h"

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

#include <unordered_map>

namespace NPersQueue {
Y_UNIT_TEST_SUITE(TQueuePoolTest) {
    Y_UNIT_TEST(QueuesDistribution) {
        TQueuePool pool;
        pool.Start(10);
        size_t addresses[10000] = {};
        std::unordered_map<IThreadPool*, size_t> queueAddresses;
        for (size_t& address : addresses) {
            IThreadPool* q = &pool.GetQueue(&address);
            ++queueAddresses[q];
            UNIT_ASSERT_EQUAL(q, &pool.GetQueue(&address)); // one address always leads to one queue
        }
        UNIT_ASSERT_VALUES_EQUAL(queueAddresses.size(), 10);
        for (const auto& queueToCount : queueAddresses) {
            UNIT_ASSERT_C(queueToCount.second >= 850, "Count: " << queueToCount.second);
            UNIT_ASSERT_C(queueToCount.second <= 1150, "Count: " << queueToCount.second);
        }
    }
}
} // namespace NPersQueue