userver: userver/testsuite/testpoint.hpp File Reference
Loading...
Searching...
No Matches
testpoint.hpp File Reference

Detailed Description

Send testpoint notification. Works only if testpoint support is enabled (e.g. in components::TestsControl), otherwise does nothing.

Definition in file testpoint.hpp.

Go to the source code of this file.

#include <string>
#include <userver/engine/task/task_processor_fwd.hpp>
#include <userver/formats/json/value.hpp>
#include <userver/testsuite/testpoint_control.hpp>
#include <userver/utils/function_ref.hpp>
#include <fmt/format.h>
#include <atomic>
#include <chrono>
#include <userver/rcu/rcu.hpp>
#include <userver/utils/async.hpp>
+ Include dependency graph for testpoint.hpp:

Namespaces

namespace  testsuite
 Testsuite integration.
 

Macros

#define TESTPOINT_CALLBACK(name, json, callback)
 Send testpoint notification and receive data. Works only if testpoint support is enabled (e.g. in components::TestsControl), otherwise does nothing.
 
#define TESTPOINT(name, json)
 Send testpoint notification. Works only if testpoint support is enabled (e.g. in components::TestsControl), otherwise does nothing.
 
#define TESTPOINT_CALLBACK_NONCORO(name, json, task_processor, callback)
 Same as TESTPOINT_CALLBACK but must be called outside of coroutine (e.g. from std::thread routine).
 
#define TESTPOINT_NONCORO(name, json, task_processor)
 Same as TESTPOINT but must be called outside of coroutine (e.g. from std::thread routine).
 

Functions

bool testsuite::AreTestpointsAvailable () noexcept
 

Macro Definition Documentation

◆ TESTPOINT

#define TESTPOINT ( name,
json )

Send testpoint notification. Works only if testpoint support is enabled (e.g. in components::TestsControl), otherwise does nothing.

Example usage:

TESTPOINT("simple-testpoint", [] {
builder["payload"] = "Hello, world!";
return builder.ExtractValue();
}());
async def test_basic(service_client, testpoint):
@testpoint('simple-testpoint')
def simple_testpoint(data):
assert data == {'payload': 'Hello, world!'}
response = await service_client.get('/testpoint')
assert response.status == 200
assert simple_testpoint.times_called == 1

noexcept if server::handlers::TestsControl is not loaded or it is disabled in static config via load-enabled: false.

Examples
postgresql/functional_tests/basic_chaos/postgres_service.cpp, samples/testsuite-support/src/tasks.cpp, and samples/testsuite-support/src/testpoint.cpp.

Definition at line 101 of file testpoint.hpp.

◆ TESTPOINT_CALLBACK

#define TESTPOINT_CALLBACK ( name,
json,
callback )

Send testpoint notification and receive data. Works only if testpoint support is enabled (e.g. in components::TestsControl), otherwise does nothing.

Example usage:

[&result](const formats::json::Value& doc) {
result["value"] = doc["value"].As<std::string>("");
});
async def test_injection(service_client, testpoint):
@testpoint('injection-point')
def injection_point(data):
return {'value': 'injected'}
response = await service_client.get('/testpoint')
assert response.status == 200
assert response.json() == {'value': 'injected'}
# testpoint supports callqueue interface
assert injection_point.times_called == 1

noexcept if server::handlers::TestsControl is not loaded or it is disabled in static config via load-enabled: false.

Examples
samples/testsuite-support/src/testpoint.cpp.

Definition at line 75 of file testpoint.hpp.

◆ TESTPOINT_CALLBACK_NONCORO

#define TESTPOINT_CALLBACK_NONCORO ( name,
json,
task_processor,
callback )

Same as TESTPOINT_CALLBACK but must be called outside of coroutine (e.g. from std::thread routine).

noexcept if server::handlers::TestsControl is not loaded or it is disabled in static config via load-enabled: false.

Definition at line 112 of file testpoint.hpp.

◆ TESTPOINT_NONCORO

#define TESTPOINT_NONCORO ( name,
json,
task_processor )

Same as TESTPOINT but must be called outside of coroutine (e.g. from std::thread routine).

noexcept if server::handlers::TestsControl is not loaded or it is disabled in static config via load-enabled: false.

Definition at line 127 of file testpoint.hpp.