12class PendingTests :
public std::enable_shared_from_this<PendingTests> {
14 static std::shared_ptr<PendingTests>
Create(
17 return std::shared_ptr<PendingTests>(
24 FML_CHECK(tests_.find(test_name) == tests_.end())
25 <<
"Attempting to start a test that is already pending.";
26 tests_[test_name] = test_time;
29 [weak = weak_from_this()] {
30 if (
auto strong = weak.lock()) {
31 strong->CheckTimedOutTests();
37 void OnTestEnd(
const std::string& test_name) { tests_.erase(test_name); }
42 for (
const auto& test : tests_) {
43 auto delay = now - test.second;
45 <<
"Test " << test.first <<
" did not complete in "
47 <<
" seconds and is assumed to be hung. Killing the test harness.";
52 using TestData = std::map<std::string, fml::TimePoint>;
60 : host_task_runner_(
std::move(host_task_runner)), timeout_(timeout) {}
66auto WeakPtr(
const std::shared_ptr<T>& pointer) {
67 return std::weak_ptr<T>{pointer};
72 listener_thread_(
"test_timeout_listener"),
73 listener_thread_runner_(listener_thread_.GetTaskRunner()),
74 pending_tests_(
PendingTests::Create(listener_thread_runner_, timeout_)) {
76 <<
" seconds per test case will be enforced.";
81 [tests = std::move(pending_tests_)]()
mutable { tests.reset(); });
86 const ::testing::TestInfo& test_info) {
87 std::stringstream stream;
88 stream << test_info.test_suite_name();
90 stream << test_info.name();
91 if (
auto type_param = test_info.type_param()) {
92 stream <<
"/" << type_param;
94 if (
auto value_param = test_info.value_param()) {
95 stream <<
"/" << value_param;
101void TestTimeoutListener::OnTestStart(const ::testing::TestInfo& test_info) {
102 listener_thread_runner_->
PostTask([weak_tests =
WeakPtr(pending_tests_),
105 if (
auto tests = weak_tests.lock()) {
106 tests->OnTestBegin(name, now);
112void TestTimeoutListener::OnTestEnd(const ::testing::TestInfo& test_info) {
114 [weak_tests =
WeakPtr(pending_tests_),
116 if (
auto tests = weak_tests.lock()) {
117 tests->OnTestEnd(name);
void OnTestEnd(const std::string &test_name)
void OnTestBegin(const std::string &test_name, fml::TimePoint test_time)
static std::shared_ptr< PendingTests > Create(fml::RefPtr< fml::TaskRunner > host_task_runner, fml::TimeDelta timeout)
void CheckTimedOutTests() const
TestTimeoutListener(fml::TimeDelta timeout)
virtual void PostTask(const fml::closure &task) override
virtual void PostDelayedTask(const fml::closure &task, fml::TimeDelta delay)
constexpr int64_t ToSeconds() const
#define FML_LOG(severity)
#define FML_CHECK(condition)
#define FML_DISALLOW_COPY_AND_ASSIGN(TypeName)
static std::string GetTestNameFromTestInfo(const ::testing::TestInfo &test_info)
auto WeakPtr(const std::shared_ptr< T > &pointer)
DEF_SWITCHES_START aot vmservice shared library name