MCPcopy Create free account
hub / github.com/catboost/catboost / Y_UNIT_TEST

Function Y_UNIT_TEST

library/cpp/threading/future/async_semaphore_ut.cpp:14–37  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

12
13Y_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);

Callers

nothing calls this directly

Calls 15

SleepFunction · 0.85
MilliSecondsFunction · 0.85
AcquireAsyncMethod · 0.80
MakeAutoReleaseMethod · 0.80
GetValueSyncMethod · 0.80
DeferReleaseMethod · 0.80
AsyncFunction · 0.70
TParamsClass · 0.50
WaitAllFunction · 0.50
StartMethod · 0.45
ApplyMethod · 0.45
GetValueMethod · 0.45

Tested by

no test coverage detected