Flutter Engine Uber Docs
Docs for the entire Flutter Engine repo.
 
Loading...
Searching...
No Matches
task_runner_util_unittests.cc
Go to the documentation of this file.
1// Copyright 2013 The Flutter Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#include <atomic>
6#include <thread>
7
10#include "flutter/fml/thread.h"
11#include "gtest/gtest.h"
12
13namespace fml {
14namespace testing {
15
16TEST(TaskRunnerUtilTests, WrapperBasicTaskRunnerPostTask) {
17 fml::Thread thread;
18
19 WrapperBasicTaskRunner wrapper(thread.GetTaskRunner());
20
21 std::thread::id wrapper_thread_id;
22 wrapper.PostTask([&]() { wrapper_thread_id = std::this_thread::get_id(); });
23
24 thread.Join();
25
26 EXPECT_NE(wrapper_thread_id, std::this_thread::get_id());
27}
28
29TEST(TaskRunnerUtilTests, ConditionalBasicTaskRunnerPostTask) {
30 fml::Thread thread;
31 std::atomic_bool active = true;
33 [&active]() -> bool { return active; });
34
36 std::atomic_bool task1_called = false;
37 runner.PostTask([&]() {
38 task1_called.store(true);
39 latch.Signal();
40 });
41 latch.Wait();
42
43 active.store(false);
44
45 std::atomic_bool task2_called = false;
46 runner.PostTask([&]() { task2_called.store(true); });
47
48 thread.GetTaskRunner()->PostTask([&]() { latch.Signal(); });
49 latch.Wait();
50
51 thread.Join();
52
53 EXPECT_TRUE(task1_called.load());
54 EXPECT_FALSE(task2_called.load());
55}
56
57} // namespace testing
58} // namespace fml
void PostTask(const fml::closure &task) override
virtual void PostTask(const fml::closure &task) override
void Join()
Definition thread.cc:168
fml::RefPtr< fml::TaskRunner > GetTaskRunner() const
Definition thread.cc:164
void PostTask(const fml::closure &task) override
TEST(BacktraceTest, CanGatherBacktrace)