Skip to content

Commit 56d2381

Browse files
rxduclaude
andcommitted
[Fix] Skip intentional race tests under ThreadSanitizer
Tests that intentionally trigger data races to document unsafe patterns (ConcurrentEdgeAdditions, MixedReadWriteOperations) are now skipped when running under TSAN since TSAN will detect the races and abort. The RUNNING_UNDER_TSAN macro detects both GCC/Clang TSAN instrumentation. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <[email protected]>
1 parent 49e5c18 commit 56d2381

File tree

1 file changed

+27
-2
lines changed

1 file changed

+27
-2
lines changed

tests/unit_test/thread_safety_test.cpp

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,19 @@
1616

1717
#include "gtest/gtest.h"
1818

19+
// Detect if running under ThreadSanitizer
20+
// Tests that intentionally trigger races should be skipped under TSAN
21+
#if defined(__SANITIZE_THREAD__)
22+
#define RUNNING_UNDER_TSAN 1
23+
#elif defined(__has_feature)
24+
#if __has_feature(thread_sanitizer)
25+
#define RUNNING_UNDER_TSAN 1
26+
#endif
27+
#endif
28+
#ifndef RUNNING_UNDER_TSAN
29+
#define RUNNING_UNDER_TSAN 0
30+
#endif
31+
1932
#include "graph/graph.hpp"
2033
#include "graph/tree.hpp"
2134
#include "graph/search/astar.hpp"
@@ -232,8 +245,14 @@ TEST_F(ThreadSafetyTest, DISABLED_ConcurrentVertexAdditions) {
232245
}
233246

234247
TEST_F(ThreadSafetyTest, ConcurrentEdgeAdditions) {
248+
// This test intentionally triggers race conditions to document unsafe patterns
249+
// Skip under TSAN since it will detect the intentional races and abort
250+
if (RUNNING_UNDER_TSAN) {
251+
GTEST_SKIP() << "Skipping intentional race test under ThreadSanitizer";
252+
}
253+
235254
Graph<ThreadSafeState> graph;
236-
255+
237256
// Pre-create vertices
238257
const int VERTEX_COUNT = 20;
239258
for (int i = 0; i < VERTEX_COUNT; ++i) {
@@ -276,8 +295,14 @@ TEST_F(ThreadSafetyTest, ConcurrentEdgeAdditions) {
276295
// ===== MIXED READ/WRITE OPERATIONS =====
277296

278297
TEST_F(ThreadSafetyTest, MixedReadWriteOperations) {
298+
// This test intentionally triggers race conditions to document unsafe patterns
299+
// Skip under TSAN since it will detect the intentional races and abort
300+
if (RUNNING_UNDER_TSAN) {
301+
GTEST_SKIP() << "Skipping intentional race test under ThreadSanitizer";
302+
}
303+
279304
Graph<ThreadSafeState> graph;
280-
305+
281306
// Pre-populate with some vertices
282307
for (int i = 0; i < 50; ++i) {
283308
graph.AddVertex(ThreadSafeState(i));

0 commit comments

Comments
 (0)