summaryrefslogtreecommitdiffstats
path: root/yql/essentials/utils/multi_resource_lock_ut.cpp
diff options
context:
space:
mode:
authorvvvv <[email protected]>2024-11-01 15:41:40 +0300
committervvvv <[email protected]>2024-11-01 15:55:52 +0300
commit3325f745e67f7f442790822b5c9c5e9996708be7 (patch)
treef7318d68bbe8990092715436444b05297ce35777 /yql/essentials/utils/multi_resource_lock_ut.cpp
parent6dce3f1c71786f2694b73b1a5155efc58f4557dd (diff)
Moved yql/utils YQL-19206
Также была выделена жирная зависимость из yql/utils в yql/utils/network, в результате library/cpp/getopt была добавлена явно в те проекты, которые ее ранее наследовали, а не указывали явно commit_hash:36aa4c41f807b4cbbf70a3ed7ac0a1a5079bb75d
Diffstat (limited to 'yql/essentials/utils/multi_resource_lock_ut.cpp')
-rw-r--r--yql/essentials/utils/multi_resource_lock_ut.cpp54
1 files changed, 54 insertions, 0 deletions
diff --git a/yql/essentials/utils/multi_resource_lock_ut.cpp b/yql/essentials/utils/multi_resource_lock_ut.cpp
new file mode 100644
index 00000000000..0af9cea3fff
--- /dev/null
+++ b/yql/essentials/utils/multi_resource_lock_ut.cpp
@@ -0,0 +1,54 @@
+#include "multi_resource_lock.h"
+#include <util/generic/xrange.h>
+#include <library/cpp/threading/future/async.h>
+#include <library/cpp/testing/unittest/registar.h>
+
+namespace NYql {
+using namespace NThreading;
+
+Y_UNIT_TEST_SUITE(TMultiResourceLock) {
+ Y_UNIT_TEST(ManyResources) {
+ TMultiResourceLock multiLock;
+ const int workersCount = 3;
+ TVector<TVector<int>> workersData;
+ workersData.resize(workersCount);
+
+ TAdaptiveThreadPool queue;
+ queue.Start(0);
+
+ TVector<NThreading::TFuture<void>> workers;
+ workers.reserve(workersCount);
+ TManualEvent startEvent;
+
+ for (int i = 0; i < workersCount; ++i) {
+ TString resourceId = ToString(i);
+ TVector<int>& data = workersData.at(i);
+ NThreading::TFuture<void> f = NThreading::Async([&, resourceId]() {
+ startEvent.Wait();
+
+ for (int j = 0; j < 1000; ++j) {
+ const auto& l = multiLock.Acquire(resourceId);
+ Y_UNUSED(l);
+ data.push_back(j);
+ }
+ }, queue);
+
+ workers.push_back(std::move(f));
+ }
+
+ startEvent.Signal();
+
+ NThreading::TFuture<void> all = NThreading::WaitExceptionOrAll(workers);
+ all.GetValueSync();
+ queue.Stop();
+
+ // analyze workersData:
+ auto range0_999 = xrange(0, 1000);
+ for (auto& w : workersData) {
+ UNIT_ASSERT_VALUES_EQUAL(w.size(), 1000);
+ UNIT_ASSERT(std::equal(range0_999.begin(), range0_999.end(), w.begin()));
+ }
+ }
+}
+
+}