#include "multi_resource_lock.h" #include #include #include namespace NYql { using namespace NThreading; Y_UNIT_TEST_SUITE(TMultiResourceLock) { Y_UNIT_TEST(ManyResources) { TMultiResourceLock multiLock; const int workersCount = 3; TVector> workersData; workersData.resize(workersCount); TAdaptiveThreadPool queue; queue.Start(0); TVector> workers; workers.reserve(workersCount); TManualEvent startEvent; for (int i = 0; i < workersCount; ++i) { TString resourceId = ToString(i); TVector& data = workersData.at(i); NThreading::TFuture 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 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())); } } } }