Flutter Engine
The Flutter Engine
Public Member Functions | List of all members
flutter::testing::ThreadTest Class Reference

A fixture that creates threads with running message loops that are terminated when the test is done (the threads are joined then as well). While this fixture may be used on it's own, it is often sub-classed by other fixtures whose functioning requires threads to be created as necessary. More...

#include <thread_test.h>

Inheritance diagram for flutter::testing::ThreadTest:
flutter::testing::EmbedderTest flutter::testing::FixtureTest flutter::testing::SkiaGpuObjectTest flutter::testing::WindowsTest flutter::testing::EmbedderTestMultiBackend flutter::Fixture flutter::testing::DartIsolateTest flutter::testing::DartIsolateTest flutter::testing::DartIsolateTest flutter::testing::DartPersistentHandleTest flutter::testing::DartSecondaryIsolateTest flutter::testing::DartWeakPersistentHandle flutter::testing::FfiNativeTest flutter::testing::ImageDecoderFixtureTest flutter::testing::IsolateStartupFailureTest flutter::testing::PlatformIsolateManagerTest flutter::testing::ShellIOManagerTest flutter::testing::ShellTest flutter::testing::TypeConversionsTest flutter::testing::CursorHandlerTest flutter::testing::FlutterWindowsEngineTest flutter::testing::PlatformHandlerTest flutter::testing::TextInputPluginTest flutter::testing::WindowsLifecycleManagerTest

Public Member Functions

 ThreadTest ()
 
fml::RefPtr< fml::TaskRunnerGetCurrentTaskRunner ()
 Get the task runner for the thread that the current unit-test is running on. This creates a message loop as necessary. More...
 
fml::RefPtr< fml::TaskRunnerCreateNewThread (const std::string &name="")
 Creates a new thread, initializes a message loop on it, and, returns its task runner to the unit-test. The message loop is terminated (and its thread joined) when the test ends. This allows tests to create multiple named threads as necessary. More...
 

Detailed Description

A fixture that creates threads with running message loops that are terminated when the test is done (the threads are joined then as well). While this fixture may be used on it's own, it is often sub-classed by other fixtures whose functioning requires threads to be created as necessary.

Definition at line 27 of file thread_test.h.

Constructor & Destructor Documentation

◆ ThreadTest()

flutter::testing::ThreadTest::ThreadTest ( )

Definition at line 20 of file thread_test.cc.

20: current_task_runner_(GetDefaultTaskRunner()) {}

Member Function Documentation

◆ CreateNewThread()

fml::RefPtr< fml::TaskRunner > flutter::testing::ThreadTest::CreateNewThread ( const std::string &  name = "")

Creates a new thread, initializes a message loop on it, and, returns its task runner to the unit-test. The message loop is terminated (and its thread joined) when the test ends. This allows tests to create multiple named threads as necessary.

Parameters
[in]nameThe name of the OS thread created.
Returns
The task runner for the newly created thread.

Definition at line 26 of file thread_test.cc.

27 {
28 auto thread = std::make_unique<fml::Thread>(name);
29 auto runner = thread->GetTaskRunner();
30 extra_threads_.emplace_back(std::move(thread));
31 return runner;
32}
DEF_SWITCHES_START aot vmservice shared library name
Definition: switches.h:32

◆ GetCurrentTaskRunner()

fml::RefPtr< fml::TaskRunner > flutter::testing::ThreadTest::GetCurrentTaskRunner ( )

Get the task runner for the thread that the current unit-test is running on. This creates a message loop as necessary.

Attention
Unlike all other threads and task runners, this task runner is shared by all tests running in the process. Tests must ensure that all tasks posted to this task runner are executed before the test ends to prevent the task from one test being executed while another test is running. When in doubt, just create a bespoke thread and task running. These cannot be seen by other tests in the process.
See also
GetThreadTaskRunner, CreateNewThread.
Returns
The task runner for the thread the test is running on.

Definition at line 22 of file thread_test.cc.

22 {
23 return current_task_runner_;
24}

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