userver: testsuite::TestsuiteTasks Class Reference
Loading...
Searching...
No Matches
testsuite::TestsuiteTasks Class Referencefinal

#include <userver/testsuite/tasks.hpp>

Detailed Description

Testsuite tasks support.

A testsuite task is a function that can be called from testsuite by its name. Only one task with the same name can be run simultaneously.

Definition at line 37 of file tasks.hpp.

Public Types

using TaskCallback = std::function<void()>
 Task function type.
 

Public Member Functions

 TestsuiteTasks (bool is_enabled)
 
bool IsEnabled () const
 Are testsuite tasks enabled or not.
 
void RegisterTask (const std::string &name, TaskCallback callback)
 Register new task.
 
void UnregisterTask (const std::string &name)
 Unregister task.
 
void RunTask (const std::string &name)
 Run task by name and waits for it to finish.
 
std::string SpawnTask (const std::string &name)
 Asynchronously starts the task.
 
void StopSpawnedTask (const std::string &task_id)
 Stop previously spawned task.
 
void CheckNoRunningTasks () noexcept
 Checks that there are no running tasks left.
 
std::vector< std::string > GetTaskNames () const
 Returns list of registered task names.
 

Member Typedef Documentation

◆ TaskCallback

using testsuite::TestsuiteTasks::TaskCallback = std::function<void()>

Task function type.

Definition at line 40 of file tasks.hpp.

Member Function Documentation

◆ CheckNoRunningTasks()

void testsuite::TestsuiteTasks::CheckNoRunningTasks ( )
noexcept

Checks that there are no running tasks left.

Must be called on service shutdown. Aborts process when there are tasks running.

◆ IsEnabled()

bool testsuite::TestsuiteTasks::IsEnabled ( ) const
inline

Are testsuite tasks enabled or not.

It is recommended to register tasks only for testsuite environment. Use this method to test weather or not you are running under testsuite:

if (testsuite_tasks.IsEnabled()) {
// testsuite code goes here...
} else {
// production code goes here...
}

Definition at line 56 of file tasks.hpp.

◆ RegisterTask()

void testsuite::TestsuiteTasks::RegisterTask ( const std::string & name,
TaskCallback callback )

Register new task.

Parameters
nameTask name
callbackTestsuite task callback function
Exceptions
std::runtime_errorWhen task with name is already registered.

◆ RunTask()

void testsuite::TestsuiteTasks::RunTask ( const std::string & name)

Run task by name and waits for it to finish.

Parameters
nameTask name
Exceptions
TaskAlreadyRunningWhen task name is already running.

◆ SpawnTask()

std::string testsuite::TestsuiteTasks::SpawnTask ( const std::string & name)

Asynchronously starts the task.

Parameters
nameTask name
Returns
Task id
Exceptions
TaskAlreadyRunningWhen task name is already running.

◆ StopSpawnedTask()

void testsuite::TestsuiteTasks::StopSpawnedTask ( const std::string & task_id)

Stop previously spawned task.

Parameters
task_idTask id returned by SpawnTask()
Exceptions
TaskNotFoundWhen task task_id is not known.

◆ UnregisterTask()

void testsuite::TestsuiteTasks::UnregisterTask ( const std::string & name)

Unregister task.

Parameters
nameTask name
Exceptions
std::runtime_errorWhen task name is not known.

The documentation for this class was generated from the following file: