Skip to content

Commit 15b7e60

Browse files
committed
cc tests: disable TSan-related tests in a more civilized way
commit_hash:b6365756619e2465873f447c059d078ee0c430c1
1 parent 10e258f commit 15b7e60

4 files changed

Lines changed: 46 additions & 32 deletions

File tree

core/src/components/common_server_component_list_test.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -286,8 +286,11 @@ TEST_F(CommonServerComponentList, Smoke) {
286286
);
287287
}
288288

289-
#if !USERVER_IMPL_HAS_TSAN
290289
TEST_F(CommonServerComponentList, Logger) {
290+
#if USERVER_IMPL_HAS_TSAN
291+
GTEST_SKIP() << "MemLogger default logger replacement is unstable under TSan";
292+
#endif
293+
291294
auto& old_logger = logging::GetDefaultLogger();
292295
logging::impl::SetDefaultLoggerRef(logging::impl::MemLogger::GetMemLogger());
293296

@@ -321,7 +324,6 @@ TEST_F(CommonServerComponentList, Logger) {
321324
logging::impl::MemLogger::GetMemLogger().ForwardTo(&old_logger);
322325
logging::impl::MemLogger::GetMemLogger().ForwardTo(nullptr);
323326
}
324-
#endif
325327

326328
TEST_F(CommonServerComponentList, TraceLogging) {
327329
fs::blocking::RewriteFileContents(

core/src/engine/single_use_event_test.cpp

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -172,8 +172,11 @@ UTEST_MT(SingleUseEvent, SendWaitRace, 2) {
172172
}
173173
}
174174

175-
#if !USERVER_IMPL_HAS_TSAN
176175
UTEST_MT(SingleUseEvent, SendCancelRace, 3) {
176+
#if USERVER_IMPL_HAS_TSAN
177+
GTEST_SKIP() << "The race relies on scheduler behavior that is not stable under TSan";
178+
#endif
179+
177180
const auto test_deadline = engine::Deadline::FromDuration(100ms);
178181

179182
bool is_ready_status_achieved = false;
@@ -210,7 +213,6 @@ UTEST_MT(SingleUseEvent, SendCancelRace, 3) {
210213
}
211214
}
212215
}
213-
#endif
214216

215217
namespace {
216218

@@ -262,8 +264,11 @@ UTEST_P_MT(SingleUseEventWaitAny, WaitSendRace, 2) {
262264
}
263265
}
264266

265-
#if !USERVER_IMPL_HAS_TSAN
266267
UTEST_P_MT(SingleUseEventWaitAny, SendCancelRace, 3) {
268+
#if USERVER_IMPL_HAS_TSAN
269+
GTEST_SKIP() << "The race relies on scheduler behavior that is not stable under TSan";
270+
#endif
271+
267272
const auto event_to_notify = GetParam();
268273
const auto test_deadline = engine::Deadline::FromDuration(50ms);
269274

@@ -298,6 +303,5 @@ UTEST_P_MT(SingleUseEventWaitAny, SendCancelRace, 3) {
298303
}
299304
}
300305
}
301-
#endif
302306

303307
USERVER_NAMESPACE_END

core/src/engine/thread_local_test.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -91,8 +91,6 @@ UTEST_MT(ThreadLocal, DISABLED_TaskUsesCorrectInstanceAfterSleep, 2) {
9191
UEXPECT_NO_THROW(sleep2.Get());
9292
}
9393

94-
// Test is not ready to TSan non-migrating scheduler
95-
#if !USERVER_IMPL_HAS_TSAN
9694
namespace {
9795

9896
auto& SafeGetThreadLocal() {
@@ -111,6 +109,10 @@ void SafeMultiplyThreadLocal(int new_value) noexcept {
111109
// This is a copy-paste from TaskUsesCorrectInstanceAfterSleep test.
112110
// While the test above consistently fails as of now, this test should pass.
113111
UTEST_MT(ThreadLocal, SafeThreadLocalWorks, 2) {
112+
#if USERVER_IMPL_HAS_TSAN
113+
GTEST_SKIP() << "The test is not ready for the TSan non-migrating scheduler";
114+
#endif
115+
114116
const auto thread1_id = pthread_self();
115117

116118
auto sleep2 = engine::AsyncNoTracing([&] {
@@ -160,7 +162,6 @@ UTEST_MT(ThreadLocal, SafeThreadLocalWorks, 2) {
160162

161163
UEXPECT_NO_THROW(sleep2.Get());
162164
}
163-
#endif
164165

165166
namespace {
166167

core/src/testsuite/testpoint_test.cpp

Lines changed: 30 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
#include <thread>
44

55
#include <userver/compiler/impl/tsan.hpp>
6+
#include <userver/engine/task/current_task.hpp>
67
#include <userver/engine/task/task_base.hpp>
78
#include <userver/formats/json/inline.hpp>
89
#include <userver/formats/json/value_builder.hpp>
@@ -20,6 +21,7 @@ class EchoTestpointClient final : public testsuite::TestpointClientBase {
2021
~EchoTestpointClient() override { Unregister(); }
2122

2223
void Execute(std::string_view name, const formats::json::Value& json, Callback callback) const override {
24+
EXPECT_TRUE(engine::current_task::IsTaskProcessorThread());
2325
callback(formats::json::MakeObject("name", name, "body", json));
2426
}
2527
};
@@ -87,23 +89,25 @@ UTEST(Testpoint, MultipleTestpointsInSameScope) {
8789
EXPECT_EQ(times_called, 4);
8890
}
8991

90-
#if !USERVER_IMPL_HAS_TSAN
9192
UTEST(Testpoint, Exceptions) {
9293
testsuite::TestpointControl testpoint_control;
9394
EchoTestpointClient testpoint_client;
9495
testpoint_control.SetClient(testpoint_client);
9596
testpoint_control.SetAllEnabled();
9697

97-
try {
98-
TESTPOINT_CALLBACK("name-throws", {}, [](const auto&) {
99-
// Callbacks may throw. It is fine and used in SQL drivers of userver for
100-
// error injection.
101-
throw Exception();
102-
return formats::json::Value{};
103-
});
104-
FAIL() << "Exception was swallowed";
105-
} catch (const Exception&) {
106-
}
98+
UEXPECT_THROW(
99+
TESTPOINT_CALLBACK(
100+
"name-throws",
101+
{},
102+
[](const auto&) {
103+
// Callbacks may throw. It is fine and used in SQL drivers of userver for
104+
// error injection.
105+
throw Exception();
106+
return formats::json::Value{};
107+
}
108+
),
109+
Exception
110+
);
107111
}
108112

109113
UTEST_MT(Testpoint, ExceptionsNoncoro, 2) {
@@ -115,20 +119,23 @@ UTEST_MT(Testpoint, ExceptionsNoncoro, 2) {
115119
auto& tp = engine::current_task::GetTaskProcessor();
116120

117121
std::thread([&] {
118-
try {
119-
TESTPOINT_CALLBACK_NONCORO("name-throws-noncoro", {}, tp, [](const auto&) {
120-
// Callbacks may throw. It is fine and used
121-
// in SQL drivers of userver for error
122-
// injection.
123-
throw Exception();
124-
return formats::json::Value{};
125-
});
126-
FAIL() << "Exception was swallowed";
127-
} catch (const Exception&) {
128-
}
122+
UEXPECT_THROW(
123+
TESTPOINT_CALLBACK_NONCORO(
124+
"name-throws-noncoro",
125+
{},
126+
tp,
127+
[](const auto&) {
128+
// Callbacks may throw. It is fine and used
129+
// in SQL drivers of userver for error
130+
// injection.
131+
throw Exception();
132+
return formats::json::Value{};
133+
}
134+
),
135+
Exception
136+
);
129137
}).join();
130138
}
131-
#endif
132139

133140
UTEST(Testpoint, Inactive) {
134141
testsuite::TestpointControl testpoint_control;

0 commit comments

Comments
 (0)