aboutsummaryrefslogtreecommitdiffstats
path: root/library/cpp/threading/queue/basic_ut.cpp
diff options
context:
space:
mode:
authoragri <agri@yandex-team.ru>2022-02-10 16:48:12 +0300
committerDaniil Cherednik <dcherednik@yandex-team.ru>2022-02-10 16:48:12 +0300
commit2909866fbc652492b7d7cab3023cb19489dc4fd8 (patch)
treeb222e5ac2e2e98872661c51ccceee5da0d291e13 /library/cpp/threading/queue/basic_ut.cpp
parentd3530b2692e400bd4d29bd4f07cafaee139164e7 (diff)
downloadydb-2909866fbc652492b7d7cab3023cb19489dc4fd8.tar.gz
Restoring authorship annotation for <agri@yandex-team.ru>. Commit 2 of 2.
Diffstat (limited to 'library/cpp/threading/queue/basic_ut.cpp')
-rw-r--r--library/cpp/threading/queue/basic_ut.cpp168
1 files changed, 84 insertions, 84 deletions
diff --git a/library/cpp/threading/queue/basic_ut.cpp b/library/cpp/threading/queue/basic_ut.cpp
index 2db5d6e8e8..5f56f8583e 100644
--- a/library/cpp/threading/queue/basic_ut.cpp
+++ b/library/cpp/threading/queue/basic_ut.cpp
@@ -1,92 +1,92 @@
#include <library/cpp/testing/unittest/registar.h>
-#include <util/generic/vector.h>
-#include <util/system/thread.h>
-
-#include "ut_helpers.h"
-
+#include <util/generic/vector.h>
+#include <util/system/thread.h>
+
+#include "ut_helpers.h"
+
template <typename TQueueType>
-class TQueueTestsInSingleThread: public TTestBase {
-private:
+class TQueueTestsInSingleThread: public TTestBase {
+private:
using TSelf = TQueueTestsInSingleThread<TQueueType>;
- using TLink = TIntrusiveLink;
-
- UNIT_TEST_SUITE_DEMANGLE(TSelf);
- UNIT_TEST(OnePushOnePop)
- UNIT_TEST(OnePushOnePop_Repeat1M)
- UNIT_TEST(Threads8_Repeat1M_Push1Pop1)
- UNIT_TEST_SUITE_END();
-
-public:
- void OnePushOnePop() {
+ using TLink = TIntrusiveLink;
+
+ UNIT_TEST_SUITE_DEMANGLE(TSelf);
+ UNIT_TEST(OnePushOnePop)
+ UNIT_TEST(OnePushOnePop_Repeat1M)
+ UNIT_TEST(Threads8_Repeat1M_Push1Pop1)
+ UNIT_TEST_SUITE_END();
+
+public:
+ void OnePushOnePop() {
TQueueType queue;
-
- auto popped = queue.Pop();
- UNIT_ASSERT_VALUES_EQUAL(popped, nullptr);
-
- TLink msg;
- queue.Push(&msg);
- popped = queue.Pop();
- UNIT_ASSERT_VALUES_EQUAL(&msg, popped);
-
- popped = queue.Pop();
- UNIT_ASSERT_VALUES_EQUAL(popped, nullptr);
- };
-
- void OnePushOnePop_Repeat1M() {
+
+ auto popped = queue.Pop();
+ UNIT_ASSERT_VALUES_EQUAL(popped, nullptr);
+
+ TLink msg;
+ queue.Push(&msg);
+ popped = queue.Pop();
+ UNIT_ASSERT_VALUES_EQUAL(&msg, popped);
+
+ popped = queue.Pop();
+ UNIT_ASSERT_VALUES_EQUAL(popped, nullptr);
+ };
+
+ void OnePushOnePop_Repeat1M() {
TQueueType queue;
- TLink msg;
-
- auto popped = queue.Pop();
- UNIT_ASSERT_VALUES_EQUAL(popped, nullptr);
-
- for (int i = 0; i < 1000000; ++i) {
- queue.Push(&msg);
- popped = queue.Pop();
- UNIT_ASSERT_VALUES_EQUAL(&msg, popped);
-
- popped = queue.Pop();
- UNIT_ASSERT_VALUES_EQUAL(popped, nullptr);
- }
- }
-
- template <size_t NUMBER_OF_THREADS>
- void RepeatPush1Pop1_InManyThreads() {
+ TLink msg;
+
+ auto popped = queue.Pop();
+ UNIT_ASSERT_VALUES_EQUAL(popped, nullptr);
+
+ for (int i = 0; i < 1000000; ++i) {
+ queue.Push(&msg);
+ popped = queue.Pop();
+ UNIT_ASSERT_VALUES_EQUAL(&msg, popped);
+
+ popped = queue.Pop();
+ UNIT_ASSERT_VALUES_EQUAL(popped, nullptr);
+ }
+ }
+
+ template <size_t NUMBER_OF_THREADS>
+ void RepeatPush1Pop1_InManyThreads() {
class TCycleThread: public ISimpleThread {
- public:
- void* ThreadProc() override {
+ public:
+ void* ThreadProc() override {
TQueueType queue;
- TLink msg;
- auto popped = queue.Pop();
- UNIT_ASSERT_VALUES_EQUAL(popped, nullptr);
-
- for (size_t i = 0; i < 1000000; ++i) {
- queue.Push(&msg);
- popped = queue.Pop();
- UNIT_ASSERT_VALUES_EQUAL(popped, &msg);
-
- popped = queue.Pop();
- UNIT_ASSERT_VALUES_EQUAL(popped, nullptr);
- }
- return nullptr;
- }
- };
-
+ TLink msg;
+ auto popped = queue.Pop();
+ UNIT_ASSERT_VALUES_EQUAL(popped, nullptr);
+
+ for (size_t i = 0; i < 1000000; ++i) {
+ queue.Push(&msg);
+ popped = queue.Pop();
+ UNIT_ASSERT_VALUES_EQUAL(popped, &msg);
+
+ popped = queue.Pop();
+ UNIT_ASSERT_VALUES_EQUAL(popped, nullptr);
+ }
+ return nullptr;
+ }
+ };
+
TVector<TAutoPtr<TCycleThread>> cyclers;
-
- for (size_t i = 0; i < NUMBER_OF_THREADS; ++i) {
- cyclers.emplace_back(new TCycleThread);
- cyclers.back()->Start();
- }
-
- for (size_t i = 0; i < NUMBER_OF_THREADS; ++i) {
- cyclers[i]->Join();
- }
- }
-
- void Threads8_Repeat1M_Push1Pop1() {
- RepeatPush1Pop1_InManyThreads<8>();
- }
-};
-
-REGISTER_TESTS_FOR_ALL_ORDERED_QUEUES(TQueueTestsInSingleThread);
-REGISTER_TESTS_FOR_ALL_UNORDERED_QUEUES(TQueueTestsInSingleThread)
+
+ for (size_t i = 0; i < NUMBER_OF_THREADS; ++i) {
+ cyclers.emplace_back(new TCycleThread);
+ cyclers.back()->Start();
+ }
+
+ for (size_t i = 0; i < NUMBER_OF_THREADS; ++i) {
+ cyclers[i]->Join();
+ }
+ }
+
+ void Threads8_Repeat1M_Push1Pop1() {
+ RepeatPush1Pop1_InManyThreads<8>();
+ }
+};
+
+REGISTER_TESTS_FOR_ALL_ORDERED_QUEUES(TQueueTestsInSingleThread);
+REGISTER_TESTS_FOR_ALL_UNORDERED_QUEUES(TQueueTestsInSingleThread)