Skip to content

Commit 54988db

Browse files
author
Nic Holthaus
committed
fix: test hardening
1 parent ca3ec86 commit 54988db

2 files changed

Lines changed: 54 additions & 19 deletions

File tree

README.md

Lines changed: 39 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,64 @@
1-
![Build Status](https://github.com/nholthaus/queue/actions/workflows/cmake-multi-platform.yml/badge.svg) ![language](https://img.shields.io/badge/language-c++20-blue.svg) ![license](https://img.shields.io/badge/license-MIT-orange.svg) ![copyright](https://img.shields.io/badge/%C2%A9-Nic_Holthaus-orange.svg) ![msvc2022](https://img.shields.io/badge/MSVC-2022-ff69b4.svg) ![gcc-11.4.0](https://img.shields.io/badge/GCC-11.4.0-ff69b4.svg)
1+
![Build Status](https://github.com/nholthaus/queue/actions/workflows/cmake-multi-platform.yml/badge.svg) ![language](https://img.shields.io/badge/language-c++23-blue.svg) ![license](https://img.shields.io/badge/license-MIT-orange.svg) ![copyright](https://img.shields.io/badge/%C2%A9-Nic_Holthaus-orange.svg) ![msvc2022](https://img.shields.io/badge/MSVC-2022-ff69b4.svg) ![gcc-13](https://img.shields.io/badge/GCC-13-ff69b4.svg) ![clang-18](https://img.shields.io/badge/Clang-18-ff69b4.svg)
22

33
A modern C++ header-only library of various types of queue
44

5+
- `concurrent_queue` provides synchronized FIFO access for multiple producers and consumers. In addition to `push` and `emplace`, consumers can use non-blocking `try_pop` or bounded-wait `try_pop_for` operations.
6+
- `circular_queue` is an allocator-aware, fixed-capacity contiguous container with random-access iterators. When full, insertion overwrites the oldest element at the opposite end.
7+
58
# Table of Contents
69

710
- [Table of Contents](#table-of-contents)
11+
- [Compatibility](#compatibility)
12+
- [Release 1.2.0](#release-120)
813
- [Build Instructions](#build-instructions)
914
- [Usage](#usage)
1015
- [Concurrent Queue](#concurrent-queue)
1116
- [Example](#example)
1217
- [Circular Queue](#circular-queue)
1318
- [Example](#example-1)
1419

20+
# Compatibility
21+
22+
Release 1.2.0 requires C++23. The versions below are the minimum compiler baselines exercised by each release's CI or explicitly documented by that release; newer compiler releases are expected to work as well.
23+
24+
| Release | Language standard | Minimum tested compilers | Minimum CMake |
25+
| --- | --- | --- | --- |
26+
| 1.2.0 | C++23 | GCC 13, Clang 18, MSVC 2022 | 3.25 |
27+
| 1.1.x | C++20 | GCC 11.4, Clang 14, MSVC 2022 | 3.7 |
28+
| 1.0.x | C++17 | GCC 9.3, MSVC 2019 | 3.7 |
29+
30+
Compiler versions not listed for an older release were not pinned by that release's build configuration and are therefore not part of its documented compatibility baseline. Other compilers may work, but are not supported unless covered by CI.
31+
32+
# Release 1.2.0
33+
34+
The 1.2.0 release moves the library to C++23 and adds range-aware construction, `assign_range`, and `insert_range` to `circular_queue`. Both queue types support three-way comparison when their stored types and underlying containers support it. This release also expands the GCC, Clang, and MSVC CI matrix with coverage and sanitizer builds.
35+
1536
# Build Instructions
1637

1738
Each class in the library itself is a single header only. You can use the included CMake in a subdirectory and add the interface library, or just copy the `*.h` files (and license) into your project.
1839

40+
Building the repository requires CMake 3.25 or newer and a C++23 compiler from the 1.2.0 compatibility row above. The queue headers themselves have no third-party runtime dependency. Tests require a thread library and GoogleTest 1.17 (fetched automatically when it is not installed); documentation generation requires Doxygen, with `pdflatex` needed only for the optional PDF.
41+
42+
When the repository is included with `add_subdirectory`, link the header-only interface target to inherit its include path:
43+
44+
``` cmake
45+
add_subdirectory(queue)
46+
target_link_libraries(my_target PRIVATE queue)
47+
```
48+
1949
To build and run the unit tests:
2050

2151
``` bash
22-
mkdir build
23-
cd build
24-
cmake -DBUILD_TESTS=ON ..
25-
cmake --build . --config Release
26-
ctest
52+
cmake -S . -B build -DQUEUE_BUILD_TESTS=ON -DQUEUE_BUILD_DOCUMENTATION=OFF
53+
cmake --build build --config Release
54+
ctest --test-dir build --build-config Release --output-on-failure
2755
```
2856

29-
To build the documentation, replace the above `cmake` command with the following:
57+
To configure and build the generated documentation:
3058

31-
```
32-
cmake -DBUILD_TESTS=ON -DBUILD_DOCUMENTATION=ON ..
59+
``` bash
60+
cmake -S . -B build -DQUEUE_BUILD_TESTS=OFF -DQUEUE_BUILD_DOCUMENTATION=ON
61+
cmake --build build --target queue_documentation
3362
```
3463

3564
# Usage
@@ -137,4 +166,4 @@ int main()
137166
}
138167
}
139168
140-
```
169+
```

test/concurrent_queue_test.h

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1262,12 +1262,14 @@ namespace
12621262
return std::this_thread::get_id(); });
12631263
auto consumer = std::async(std::launch::async, [&queue, &numbers_out, test_size, &iteration]
12641264
{
1265-
int val;
1265+
int val = 0;
12661266
for (int i = 0; i < test_size; ++i)
12671267
{
12681268
iteration.arrive_and_wait();
1269-
EXPECT_TRUE(queue.try_pop_for(val, 100ms));
1270-
numbers_out.push_back(val);
1269+
if (queue.try_pop_for(val, 1s))
1270+
numbers_out.push_back(val);
1271+
else
1272+
ADD_FAILURE() << "timed out waiting for item " << i;
12711273
iteration.arrive_and_wait();
12721274
}
12731275
return std::this_thread::get_id(); });
@@ -1335,23 +1337,27 @@ namespace
13351337
return std::this_thread::get_id(); });
13361338
auto consumer1 = std::async(std::launch::async, [&queue, &out1, &iteration]
13371339
{
1338-
int val;
1340+
int val = 0;
13391341
for (int i = 0; i < 100; ++i)
13401342
{
13411343
iteration.arrive_and_wait();
1342-
EXPECT_TRUE(queue.try_pop_for(val, 100ms));
1343-
out1.push_back(val);
1344+
if (queue.try_pop_for(val, 1s))
1345+
out1.push_back(val);
1346+
else
1347+
ADD_FAILURE() << "consumer 1 timed out on iteration " << i;
13441348
iteration.arrive_and_wait();
13451349
}
13461350
return std::this_thread::get_id(); });
13471351
auto consumer2 = std::async(std::launch::async, [&queue, &out2, &iteration]
13481352
{
1349-
int val;
1353+
int val = 0;
13501354
for (int i = 0; i < 100; ++i)
13511355
{
13521356
iteration.arrive_and_wait();
1353-
EXPECT_TRUE(queue.try_pop_for(val, 100ms));
1354-
out2.push_back(val);
1357+
if (queue.try_pop_for(val, 1s))
1358+
out2.push_back(val);
1359+
else
1360+
ADD_FAILURE() << "consumer 2 timed out on iteration " << i;
13551361
iteration.arrive_and_wait();
13561362
}
13571363
return std::this_thread::get_id(); });

0 commit comments

Comments
 (0)