Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 48 additions & 8 deletions fml/message_loop_unittests.cc
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,12 @@ TEST(MessageLoop, NonDelayedTasksAreRunInOrder) {
auto& loop = fml::MessageLoop::GetCurrent();
size_t current = 0;
for (size_t i = 0; i < count; i++) {
loop.GetTaskRunner()->PostTask([&terminated, i, &current, count]() {
loop.GetTaskRunner()->PostTask([&terminated, i, &current
#if OS_WIN
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have no idea what issue this is trying to work around on Windows. This is not maintainable and I am sure the next time anyone tries to modify such TUs, he/she is going to miss one of these preprocessor guards.

,
count
#endif
]() {
ASSERT_EQ(current, i);
current++;
if (count == i + 1) {
Expand Down Expand Up @@ -105,7 +110,12 @@ TEST(MessageLoop, DelayedTasksAtSameTimeAreRunInOrder) {
fxl::TimePoint::Now() + fxl::TimeDelta::FromMilliseconds(2);
for (size_t i = 0; i < count; i++) {
loop.GetTaskRunner()->PostTaskForTime(
[&terminated, i, &current, count]() {
[&terminated, i, &current
#if OS_WIN
,
count
#endif
]() {
ASSERT_EQ(current, i);
current++;
if (count == i + 1) {
Expand Down Expand Up @@ -187,13 +197,23 @@ TEST(MessageLoop, TIME_SENSITIVE(SingleDelayedTaskForTime)) {
TEST(MessageLoop, TIME_SENSITIVE(MultipleDelayedTasksWithIncreasingDeltas)) {
const auto count = 10;
int checked = false;
std::thread thread([&checked, count]() {
std::thread thread([&checked
#if OS_WIN
,
count
#endif
]() {
fml::MessageLoop::EnsureInitializedForCurrentThread();
auto& loop = fml::MessageLoop::GetCurrent();
for (int target_ms = 0 + 2; target_ms < count + 2; target_ms++) {
auto begin = fxl::TimePoint::Now();
loop.GetTaskRunner()->PostDelayedTask(
[begin, target_ms, &checked, count]() {
[begin, target_ms, &checked
#if OS_WIN
,
count
#endif
]() {
auto delta = fxl::TimePoint::Now() - begin;
auto ms = delta.ToMillisecondsF();
ASSERT_GE(ms, target_ms - 2);
Expand All @@ -214,13 +234,23 @@ TEST(MessageLoop, TIME_SENSITIVE(MultipleDelayedTasksWithIncreasingDeltas)) {
TEST(MessageLoop, TIME_SENSITIVE(MultipleDelayedTasksWithDecreasingDeltas)) {
const auto count = 10;
int checked = false;
std::thread thread([&checked, count]() {
std::thread thread([&checked
#if OS_WIN
,
count
#endif
]() {
fml::MessageLoop::EnsureInitializedForCurrentThread();
auto& loop = fml::MessageLoop::GetCurrent();
for (int target_ms = count + 2; target_ms > 0 + 2; target_ms--) {
auto begin = fxl::TimePoint::Now();
loop.GetTaskRunner()->PostDelayedTask(
[begin, target_ms, &checked, count]() {
[begin, target_ms, &checked
#if OS_WIN
,
count
#endif
]() {
auto delta = fxl::TimePoint::Now() - begin;
auto ms = delta.ToMillisecondsF();
ASSERT_GE(ms, target_ms - 2);
Expand Down Expand Up @@ -263,9 +293,19 @@ TEST(MessageLoop, TaskObserverFire) {
auto& loop = fml::MessageLoop::GetCurrent();
size_t task_count = 0;
size_t obs_count = 0;
CustomTaskObserver obs([&obs_count, count]() { obs_count++; });
CustomTaskObserver obs([&obs_count
#if OS_WIN
,
count
#endif
]() { obs_count++; });
for (size_t i = 0; i < count; i++) {
loop.GetTaskRunner()->PostTask([&terminated, i, &task_count, count]() {
loop.GetTaskRunner()->PostTask([&terminated, i, &task_count
#if OS_WIN
,
count
#endif
]() {
ASSERT_EQ(task_count, i);
task_count++;
if (count == i + 1) {
Expand Down