MCPcopy Create free account
hub / github.com/Icinga/icinga2 / ExpectLogPattern

Method ExpectLogPattern

test/base-testloggerfixture.hpp:27–54  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

25 };
26
27 auto ExpectLogPattern(const std::string& pattern,
28 const std::chrono::milliseconds& timeout = std::chrono::seconds(0))
29 {
30 std::unique_lock lock(m_Mutex);
31 for (const auto& logEntry : m_LogEntries) {
32 if (boost::regex_match(logEntry.Message.GetData(), boost::regex(pattern))) {
33 return boost::test_tools::assertion_result{true};
34 }
35 }
36
37 if (timeout == std::chrono::seconds(0)) {
38 return boost::test_tools::assertion_result{false};
39 }
40
41 auto expect = std::make_shared<Expect>(Expect{pattern, std::promise<bool>()});
42 m_Expects.emplace_back(expect);
43 lock.unlock();
44
45 auto future = expect->prom.get_future();
46 auto status = future.wait_for(timeout);
47 boost::test_tools::assertion_result ret{status == std::future_status::ready && future.get()};
48 ret.message() << "Pattern \"" << pattern << "\" in log within " << timeout.count() << "ms";
49
50 lock.lock();
51 m_Expects.erase(boost::range::remove(m_Expects, expect), m_Expects.end());
52
53 return ret;
54 }
55
56 void Clear()
57 {

Callers 1

ExpectLogPatternMethod · 0.45

Calls 4

countMethod · 0.80
getMethod · 0.45
eraseMethod · 0.45
endMethod · 0.45

Tested by

no test coverage detected