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
9192UTEST (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
109113UTEST_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
133140UTEST (Testpoint, Inactive) {
134141 testsuite::TestpointControl testpoint_control;
0 commit comments