Seastar
High performance C++ framework for concurrent servers
|
Allocation failure injection framework. Allows testing for exception safety.
To exhaustively inject failure at every allocation point:
uint64_t i = 0; while (true) { try { local_failure_injector().fail_after(i++); code_under_test(); local_failure_injector().cancel(); break; } catch (const std::bad_alloc&) { // expected } }
#include <seastar/util/alloc_failure_injector.hh>
Public Member Functions | |
void | on_alloc_point () |
Marks a point in code which should be considered for failure injection. | |
uint64_t | alloc_count () const |
Counts encountered allocation points which didn't fail and didn't have failure suppressed. | |
void | fail_after (uint64_t count) |
Will cause count-th allocation point from now to fail, counting from 0. | |
void | cancel () |
Cancels the failure scheduled by fail_after(). | |
bool | failed () const |
Returns true iff allocation was failed since last fail_after(). | |
void | run_with_callback (noncopyable_function< void()> callback, noncopyable_function< void()> to_run) |
Runs given function with a custom failure action instead of the default std::bad_alloc throw. | |