Skip to content

Commit 097fe12

Browse files
committed
Attempt to fix flaky tests caused by modifying the same test apps.
1 parent 3870ab5 commit 097fe12

2 files changed

Lines changed: 9 additions & 32 deletions

File tree

packages/devtools_app/test/screens/inspector/inspector_integration_test.dart

Lines changed: 5 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -31,39 +31,19 @@ import '../../test_infra/matchers/matchers.dart';
3131
// reduced to under 1 second without introducing flakes.
3232
const inspectorChangeSettleTime = Duration(seconds: 2);
3333

34-
void _copyDirectorySync(Directory source, Directory destination) {
35-
if (!destination.existsSync()) {
36-
destination.createSync(recursive: true);
37-
}
38-
for (final entity in source.listSync()) {
39-
final newPath = p.join(destination.path, p.basename(entity.path));
40-
if (entity is Directory) {
41-
_copyDirectorySync(entity, Directory(newPath));
42-
} else if (entity is File) {
43-
entity.copySync(newPath);
44-
}
45-
}
46-
}
4734

4835
void main() {
4936
// We need to use real async in this test so we need to use this binding.
5037
initializeLiveTestWidgetsFlutterBindingWithAssets();
5138
const windowSize = Size(2600.0, 1200.0);
5239

53-
// We copy the fixture app to a temporary directory because the
54-
// auto-refresh tests modify lib/main.dart in-place. If this used the shared
55-
// 'inspector_app' fixture, it could cause flaky test failures in other tests
56-
// (like inspector_service_test.dart) that run in parallel.
57-
final tempAppDir =
58-
'test/test_infra/fixtures/inspector_app_temp_${DateTime.now().millisecondsSinceEpoch}';
59-
_copyDirectorySync(
60-
Directory('test/test_infra/fixtures/inspector_app'),
61-
Directory(tempAppDir),
62-
);
63-
40+
// The auto-refresh tests modify lib/main.dart in-place.
41+
// We use `useTempDirectory: true` (default in FlutterTestEnvironment) to
42+
// copy the fixture app to a temporary directory. This prevents flaky test
43+
// failures in other tests (like inspector_service_test.dart) that run in parallel.
6444
final env = FlutterTestEnvironment(
6545
const FlutterRunConfiguration(withDebugger: true),
66-
testAppDirectory: tempAppDir,
46+
testAppDirectory: 'test/test_infra/fixtures/inspector_app',
6747
);
6848

6949
env.afterEverySetup = () async {
@@ -92,10 +72,6 @@ void main() {
9272

9373
tearDownAll(() {
9474
env.finalTeardown();
95-
final dir = Directory(tempAppDir);
96-
if (dir.existsSync()) {
97-
dir.deleteSync(recursive: true);
98-
}
9975
});
10076

10177
group('screenshot tests', () {

packages/devtools_app/test/test_infra/flutter_test_environment.dart

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,15 @@ class FlutterTestEnvironment {
2828
FlutterTestEnvironment(
2929
this._runConfig, {
3030
String testAppDirectory = 'test/test_infra/fixtures/flutter_app',
31-
bool useTempDirectory = false,
31+
bool useTempDirectory = true,
3232
FlutterDriverFactory? flutterDriverFactory,
3333
}) : _testAppDirectory = testAppDirectory,
3434
_flutterDriverFactory = flutterDriverFactory ?? defaultFlutterRunDriver,
3535
_flutterExe = _parseFlutterExeFromEnv() {
3636
if (useTempDirectory) {
37-
final tempDirectory = Directory.systemTemp.createTempSync(
38-
'flutter_test_temp',
37+
final parentDir = p.dirname(testAppDirectory);
38+
final tempDirectory = Directory(parentDir).createTempSync(
39+
'flutter_test_temp_',
3940
);
4041
_tempTestAppDirectory = tempDirectory.path;
4142
_copyToTempDirectory(testAppDirectory, tempDirectory);

0 commit comments

Comments
 (0)