36#include <gtest/gtest.h>
60 static std::atomic<int> live;
63 Probe()
noexcept { live.fetch_add(1, std::memory_order_relaxed); }
66 live.fetch_add(1, std::memory_order_relaxed);
70 live.fetch_add(1, std::memory_order_relaxed);
74 live.fetch_add(1, std::memory_order_relaxed);
76 Probe & operator=(
const Probe &) =
default;
78 ~Probe() { live.fetch_sub(1, std::memory_order_relaxed); }
81 std::atomic<int> Probe::live{0};
85 static bool should_throw;
88 explicit Throwing_Ctor(
int v) :
value(v)
91 throw std::runtime_error(
"Throwing_Ctor: constructor failed");
95 bool Throwing_Ctor::should_throw =
false;
127 q.
push(std::string(
"alpha"));
128 q.
push(std::string(
"beta"));
145 constexpr int N = 1000;
146 for (
int i = 0; i <
N; ++i)
149 for (
int i = 0; i <
N; ++i)
161 q.
push(std::make_unique<int>(10));
162 q.
emplace(std::make_unique<int>(20));
164 std::unique_ptr<int>
out;
202 for (
int i = 0; i < 50; ++i)
215 Throwing_Ctor::should_throw =
true;
217 Throwing_Ctor::should_throw =
false;
221 Throwing_Ctor
out(0);
235 config.
timeout = std::chrono::seconds(30);
246 for (
size_t i = 0; i < result.consumed.size(); ++i)
255 constexpr size_t items_per_producer = 20000;
263 config.
timeout = std::chrono::seconds(30);
280 for (
const size_t value : result.consumed)
282 const size_t producer =
value / items_per_producer;
283 const size_t seq =
value % items_per_producer;
286 <<
"producer " << producer <<
" delivered out of FIFO order";
287 last_seq[producer] =
static_cast<long long>(seq);
290 auto sorted = result.consumed;
292 for (
size_t i = 0; i <
total; ++i)
304 5000, 0xC0FFEE, 1000, {Trace_Operation_Kind::insert});
306 std::vector<size_t>
model;
309 for (
const auto &op :
trace)
311 model.push_back(op.key);
size_t size_t int32_t value
size_t size_t int32_t * out
Unbounded lock-free multi-producer/single-consumer queue.
void emplace(Args &&... args)
Construct a new element in place at the back of the queue.
void push(const T &value)
Push a copy of value onto the queue.
bool is_empty() const noexcept
Advisory check for whether the queue currently has no elements.
bool try_pop(T &out)
Attempt to pop the front element into out.
Minimal std::expected-style result type for C++20.
Reusable helpers for concurrent data-structure tests.
size_t blossom_maximum_cardinality_matching(const GT &g, DynDlist< typename GT::Arc * > &matching, SA sa=SA())
Alias of compute_maximum_cardinality_general_matching().
Producer_Consumer_Stress_Result run_producer_consumer_stress(const Producer_Consumer_Stress_Config &config, Push push, TryPop try_pop)
Run a deterministic producer/consumer stress scenario.
std::vector< Trace_Operation > make_random_operation_trace(const size_t count, const uint32_t seed, const size_t key_range, const std::initializer_list< Trace_Operation_Kind > kinds={ Trace_Operation_Kind::insert, Trace_Operation_Kind::erase, Trace_Operation_Kind::contains })
Build a deterministic pseudo-random operation trace.
Main namespace for Aleph-w library functions.
Configuration for producer/consumer stress helpers.
size_t items_per_producer
std::chrono::milliseconds timeout
Unbounded lock-free multi-producer/single-consumer queue (Aleph::MpscQueue).