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

Commit b4d8158

Browse files
authored
Shuffle test order and repeat test runs once. (#12275)
The tests we write must be resilient to the order in which they are run in the harness. That is, they must not rely on global state set by other tests that have already run in the process. Also, these tests must themselves be repeatable. That is, they must correctly clean up after themselves and be able to run successfully again in the same process. This patch adds some safeguards against (but does NOT guarantee) the addition of tests that violate the dictum. Additionally, test failures must be easily reproducible for folks investigating the test failure. Also, tests that assert correctness of unrelated code must not stop progress on the authors patch. This changes does not hinder reproducibility of test failures because the random seed is printed in the logs before running each test. Developers attempting to reproduce the failure locally can do the same via the following invocation `--gtest_shuffle --gtest_repeat=<the count> --gtest_random_seed=<seed from failing run>`. This change does introduce potential burden on patch authors that may see failures in unrelated code as a newly failing shuffle seed is used on their runs. To ameliorate this, we will formulate guidance for them to aggressively mark such tests as disabled and file bugs to enable the same. The test seed is intentionally kept low because it’s purpose is to test that individual tests are repeatable. It must not be used as a replacement for fuzzing.
1 parent d1692d4 commit b4d8158

File tree

2 files changed

+16
-10
lines changed

2 files changed

+16
-10
lines changed

shell/platform/embedder/tests/embedder_unittests.cc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,7 @@ TEST_F(EmbedderTest, CanSpecifyCustomTaskRunner) {
218218
kill_latch.Wait();
219219

220220
ASSERT_TRUE(signaled_once);
221+
signaled_once = false;
221222
}
222223

223224
TEST(EmbedderTestNoFixture, CanGetCurrentTimeInNanoseconds) {

testing/run_tests.py

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -71,39 +71,44 @@ def RunEngineExecutable(build_dir, executable_name, filter, flags=[], cwd=buildr
7171
def RunCCTests(build_dir, filter):
7272
print "Running Engine Unit-tests."
7373

74-
RunEngineExecutable(build_dir, 'client_wrapper_glfw_unittests', filter)
74+
shuffle_flags = [
75+
"--gtest_shuffle",
76+
"--gtest_repeat=2",
77+
]
78+
79+
RunEngineExecutable(build_dir, 'client_wrapper_glfw_unittests', filter, shuffle_flags)
7580

76-
RunEngineExecutable(build_dir, 'client_wrapper_unittests', filter)
81+
RunEngineExecutable(build_dir, 'client_wrapper_unittests', filter, shuffle_flags)
7782

7883
# https://github.com/flutter/flutter/issues/36294
7984
if not IsWindows():
80-
RunEngineExecutable(build_dir, 'embedder_unittests', filter)
85+
RunEngineExecutable(build_dir, 'embedder_unittests', filter, shuffle_flags)
8186

8287
flow_flags = ['--gtest_filter=-PerformanceOverlayLayer.Gold']
8388
if IsLinux():
8489
flow_flags = [
8590
'--golden-dir=%s' % golden_dir,
8691
'--font-file=%s' % roboto_font_path,
8792
]
88-
RunEngineExecutable(build_dir, 'flow_unittests', filter, flow_flags)
93+
RunEngineExecutable(build_dir, 'flow_unittests', filter, flow_flags + shuffle_flags)
8994

90-
RunEngineExecutable(build_dir, 'fml_unittests', filter, [ time_sensitve_test_flag ])
95+
RunEngineExecutable(build_dir, 'fml_unittests', filter, [ time_sensitve_test_flag ] + shuffle_flags)
9196

92-
RunEngineExecutable(build_dir, 'runtime_unittests', filter)
97+
RunEngineExecutable(build_dir, 'runtime_unittests', filter, shuffle_flags)
9398

9499
# https://github.com/flutter/flutter/issues/36295
95100
if not IsWindows():
96-
RunEngineExecutable(build_dir, 'shell_unittests', filter)
101+
RunEngineExecutable(build_dir, 'shell_unittests', filter, shuffle_flags)
97102

98-
RunEngineExecutable(build_dir, 'ui_unittests', filter)
103+
RunEngineExecutable(build_dir, 'ui_unittests', filter, shuffle_flags)
99104

100105
# These unit-tests are Objective-C and can only run on Darwin.
101106
if IsMac():
102-
RunEngineExecutable(build_dir, 'flutter_channels_unittests', filter)
107+
RunEngineExecutable(build_dir, 'flutter_channels_unittests', filter, shuffle_flags)
103108

104109
# https://github.com/flutter/flutter/issues/36296
105110
if IsLinux():
106-
RunEngineExecutable(build_dir, 'txt_unittests', filter, [ fonts_dir_flag ])
111+
RunEngineExecutable(build_dir, 'txt_unittests', filter, [ fonts_dir_flag ] + shuffle_flags)
107112

108113

109114
def RunEngineBenchmarks(build_dir, filter):

0 commit comments

Comments
 (0)