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

Function TEST_P

library/cpp/yt/memory/unittests/free_list_ut.cpp:94–145  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

92
93
94TEST_P(TFreeListStressTest, Stress)
95{
96 TTestItemSet::Reset();
97 SetRandomSeed(0x424242);
98 auto params = GetParam();
99
100 TFreeList<TTestItem> list;
101
102 std::latch start(params.Threads);
103
104 std::atomic<bool> running{true};
105 std::atomic<ui64> put{0};
106 std::atomic<ui64> extracted{0};
107
108 std::vector<std::thread> workers;
109 for (ui64 i = 0; i < params.Threads; ++i) {
110 auto itemSet = TTestItemSet::Allocate(params.MaxBatchSize);
111 workers.emplace_back([&, params, itemSet = std::move(itemSet)]() mutable {
112 start.arrive_and_wait();
113
114 while (running.load(std::memory_order::relaxed)) {
115 // Push batch of items.
116 ui64 batchSize = 1 + RandomNumber<ui64>(params.MaxBatchSize);
117 for (ui64 i = 0; i < batchSize; ++i) {
118 auto* item = itemSet.Release();
119 item->Value = 1 + RandomNumber<ui64>(1e9);
120 put.fetch_add(item->Value, std::memory_order::relaxed);
121 list.Put(item);
122 }
123
124 // Pop batch of items.
125 for (ui64 i = 0; i < batchSize; ++i) {
126 auto* item = list.Extract();
127 ASSERT_NE(item, nullptr);
128 extracted.fetch_add(item->Value, std::memory_order::relaxed);
129 itemSet.Acquire(item);
130 }
131 }
132 });
133 }
134
135 Sleep(params.TimeLimit);
136 running.store(false);
137
138 for (auto& worker : workers) {
139 worker.join();
140 }
141
142 Cerr << "Put: " << put.load() << Endl;
143 Cerr << "Extracted: " << extracted.load() << Endl;
144 EXPECT_EQ(put.load(), extracted.load());
145}
146
147INSTANTIATE_TEST_SUITE_P(
148 TFreeListTest,

Callers

nothing calls this directly

Calls 14

SetRandomSeedFunction · 0.85
SleepFunction · 0.85
ResetFunction · 0.50
AllocateFunction · 0.50
moveFunction · 0.50
emplace_backMethod · 0.45
loadMethod · 0.45
ReleaseMethod · 0.45
fetch_addMethod · 0.45
PutMethod · 0.45
ExtractMethod · 0.45
AcquireMethod · 0.45

Tested by

no test coverage detected