Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit 14c78ff

Browse files
authored
Make sure the native callback is registered before running the test. (#18981)
Otherwise, this is a race condition. Fixes flutter/flutter#58785
1 parent 592cbab commit 14c78ff

File tree

1 file changed

+10
-9
lines changed

1 file changed

+10
-9
lines changed

shell/platform/embedder/tests/embedder_unittests.cc

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2841,6 +2841,16 @@ TEST_F(EmbedderTest, CanUpdateLocales) {
28412841
CREATE_NATIVE_ENTRY(
28422842
[&latch](Dart_NativeArguments args) { latch.Signal(); }));
28432843

2844+
fml::AutoResetWaitableEvent check_latch;
2845+
context.AddNativeCallback(
2846+
"SignalNativeCount",
2847+
CREATE_NATIVE_ENTRY([&check_latch](Dart_NativeArguments args) {
2848+
ASSERT_EQ(tonic::DartConverter<int>::FromDart(
2849+
Dart_GetNativeArgument(args, 0)),
2850+
2);
2851+
check_latch.Signal();
2852+
}));
2853+
28442854
auto engine = builder.LaunchEngine();
28452855
ASSERT_TRUE(engine.is_valid());
28462856

@@ -2876,15 +2886,6 @@ TEST_F(EmbedderTest, CanUpdateLocales) {
28762886
FlutterEngineUpdateLocales(engine.get(), locales.data(), locales.size()),
28772887
kSuccess);
28782888

2879-
fml::AutoResetWaitableEvent check_latch;
2880-
context.AddNativeCallback(
2881-
"SignalNativeCount",
2882-
CREATE_NATIVE_ENTRY([&check_latch](Dart_NativeArguments args) {
2883-
ASSERT_EQ(tonic::DartConverter<int>::FromDart(
2884-
Dart_GetNativeArgument(args, 0)),
2885-
2);
2886-
check_latch.Signal();
2887-
}));
28882889
check_latch.Wait();
28892890
}
28902891

0 commit comments

Comments
 (0)