| 12 | |
| 13 | Y_UNIT_TEST_SUITE(TSemaphoreAsync) { |
| 14 | Y_UNIT_TEST(SimplyAquired) { |
| 15 | const size_t MAX_IN_PROGRESS = 5; |
| 16 | |
| 17 | TSimpleThreadPool pool(TThreadPool::TParams().SetCatching(false)); |
| 18 | pool.Start(MAX_IN_PROGRESS * 2); |
| 19 | |
| 20 | TVector<TFuture<size_t>> futures; |
| 21 | auto semaphore = TAsyncSemaphore::Make(MAX_IN_PROGRESS); |
| 22 | for (size_t i = 0; i < 100; ++i) { |
| 23 | auto f = semaphore->AcquireAsync() |
| 24 | .Apply([&pool, i](const auto& f) -> TFuture<size_t> { |
| 25 | return Async([i, semaphore = f.GetValue()] { |
| 26 | auto guard = semaphore->MakeAutoRelease(); |
| 27 | Sleep(TDuration::MilliSeconds(100)); |
| 28 | return i; |
| 29 | }, pool); |
| 30 | }); |
| 31 | futures.push_back(f); |
| 32 | } |
| 33 | |
| 34 | for (size_t i = 0; i < 100; ++i) { |
| 35 | UNIT_ASSERT_VALUES_EQUAL(futures[i].GetValueSync(), i); |
| 36 | } |
| 37 | } |
| 38 | |
| 39 | Y_UNIT_TEST(AutoReleasedOnException) { |
| 40 | auto semaphore = TAsyncSemaphore::Make(1); |
nothing calls this directly
no test coverage detected