Flutter Engine
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::CanvasTestBase< ThreadTest > flutter::testing::EmbedderTest flutter::testing::FixtureTest flutter::testing::SkiaGpuObjectTest flutter::testing::LayerTestBase< ThreadTest > flutter::Fixture flutter::testing::DartIsolateTest flutter::testing::DartSecondaryIsolateTest flutter::testing::ImageDecoderFixtureTest flutter::testing::ShellTest flutter::testing::TypeConversionsTest flutter::testing::SkiaGPUObjectLayerTest flutter::testing::FuchsiaShellTest flutter::testing::ImageDisposeTest

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 (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 ( 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.

References name.

Referenced by flutter::testing::TypeConversionsTest::RunWithEntrypoint(), and flutter::testing::TEST_F().

26  {
27  auto thread = std::make_unique<fml::Thread>(name);
28  auto runner = thread->GetTaskRunner();
29  extra_threads_.emplace_back(std::move(thread));
30  return runner;
31 }
const char * name
Definition: fuchsia.cc:50

◆ 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.

Referenced by flutter::testing::TEST_F().

22  {
23  return current_task_runner_;
24 }

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