| 92 | |
| 93 | |
| 94 | TEST_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 | |
| 147 | INSTANTIATE_TEST_SUITE_P( |
| 148 | TFreeListTest, |
nothing calls this directly
no test coverage detected