From 097fe12a06c8588f8700ca8ed2daf447fd68c303 Mon Sep 17 00:00:00 2001 From: Kenzie Davisson Date: Wed, 29 Jul 2026 14:34:21 -0700 Subject: [PATCH 1/4] Attempt to fix flaky tests caused by modifying the same test apps. --- .../inspector/inspector_integration_test.dart | 34 +++---------------- .../test_infra/flutter_test_environment.dart | 7 ++-- 2 files changed, 9 insertions(+), 32 deletions(-) diff --git a/packages/devtools_app/test/screens/inspector/inspector_integration_test.dart b/packages/devtools_app/test/screens/inspector/inspector_integration_test.dart index 970108a134b..88883b13ab8 100644 --- a/packages/devtools_app/test/screens/inspector/inspector_integration_test.dart +++ b/packages/devtools_app/test/screens/inspector/inspector_integration_test.dart @@ -31,39 +31,19 @@ import '../../test_infra/matchers/matchers.dart'; // reduced to under 1 second without introducing flakes. const inspectorChangeSettleTime = Duration(seconds: 2); -void _copyDirectorySync(Directory source, Directory destination) { - if (!destination.existsSync()) { - destination.createSync(recursive: true); - } - for (final entity in source.listSync()) { - final newPath = p.join(destination.path, p.basename(entity.path)); - if (entity is Directory) { - _copyDirectorySync(entity, Directory(newPath)); - } else if (entity is File) { - entity.copySync(newPath); - } - } -} void main() { // We need to use real async in this test so we need to use this binding. initializeLiveTestWidgetsFlutterBindingWithAssets(); const windowSize = Size(2600.0, 1200.0); - // We copy the fixture app to a temporary directory because the - // auto-refresh tests modify lib/main.dart in-place. If this used the shared - // 'inspector_app' fixture, it could cause flaky test failures in other tests - // (like inspector_service_test.dart) that run in parallel. - final tempAppDir = - 'test/test_infra/fixtures/inspector_app_temp_${DateTime.now().millisecondsSinceEpoch}'; - _copyDirectorySync( - Directory('test/test_infra/fixtures/inspector_app'), - Directory(tempAppDir), - ); - + // The auto-refresh tests modify lib/main.dart in-place. + // We use `useTempDirectory: true` (default in FlutterTestEnvironment) to + // copy the fixture app to a temporary directory. This prevents flaky test + // failures in other tests (like inspector_service_test.dart) that run in parallel. final env = FlutterTestEnvironment( const FlutterRunConfiguration(withDebugger: true), - testAppDirectory: tempAppDir, + testAppDirectory: 'test/test_infra/fixtures/inspector_app', ); env.afterEverySetup = () async { @@ -92,10 +72,6 @@ void main() { tearDownAll(() { env.finalTeardown(); - final dir = Directory(tempAppDir); - if (dir.existsSync()) { - dir.deleteSync(recursive: true); - } }); group('screenshot tests', () { diff --git a/packages/devtools_app/test/test_infra/flutter_test_environment.dart b/packages/devtools_app/test/test_infra/flutter_test_environment.dart index bb81e3e1c1b..536a35967ae 100644 --- a/packages/devtools_app/test/test_infra/flutter_test_environment.dart +++ b/packages/devtools_app/test/test_infra/flutter_test_environment.dart @@ -28,14 +28,15 @@ class FlutterTestEnvironment { FlutterTestEnvironment( this._runConfig, { String testAppDirectory = 'test/test_infra/fixtures/flutter_app', - bool useTempDirectory = false, + bool useTempDirectory = true, FlutterDriverFactory? flutterDriverFactory, }) : _testAppDirectory = testAppDirectory, _flutterDriverFactory = flutterDriverFactory ?? defaultFlutterRunDriver, _flutterExe = _parseFlutterExeFromEnv() { if (useTempDirectory) { - final tempDirectory = Directory.systemTemp.createTempSync( - 'flutter_test_temp', + final parentDir = p.dirname(testAppDirectory); + final tempDirectory = Directory(parentDir).createTempSync( + 'flutter_test_temp_', ); _tempTestAppDirectory = tempDirectory.path; _copyToTempDirectory(testAppDirectory, tempDirectory); From 502c32102be726c0cfe973a971ebc9492b58e3d2 Mon Sep 17 00:00:00 2001 From: Kenzie Davisson Date: Wed, 29 Jul 2026 14:49:01 -0700 Subject: [PATCH 2/4] review comments --- .../test/screens/inspector/inspector_integration_test.dart | 7 ++++--- .../devtools_app/test/shared/eval_integration_test.dart | 1 + .../test/test_infra/flutter_test_environment.dart | 2 +- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/packages/devtools_app/test/screens/inspector/inspector_integration_test.dart b/packages/devtools_app/test/screens/inspector/inspector_integration_test.dart index 88883b13ab8..2f7e9a88797 100644 --- a/packages/devtools_app/test/screens/inspector/inspector_integration_test.dart +++ b/packages/devtools_app/test/screens/inspector/inspector_integration_test.dart @@ -38,12 +38,13 @@ void main() { const windowSize = Size(2600.0, 1200.0); // The auto-refresh tests modify lib/main.dart in-place. - // We use `useTempDirectory: true` (default in FlutterTestEnvironment) to - // copy the fixture app to a temporary directory. This prevents flaky test - // failures in other tests (like inspector_service_test.dart) that run in parallel. + // We use `useTempDirectory: true` to copy the fixture app to a temporary + // directory. This prevents flaky test failures in other tests (like + // inspector_service_test.dart) that run in parallel. final env = FlutterTestEnvironment( const FlutterRunConfiguration(withDebugger: true), testAppDirectory: 'test/test_infra/fixtures/inspector_app', + useTempDirectory: true, ); env.afterEverySetup = () async { diff --git a/packages/devtools_app/test/shared/eval_integration_test.dart b/packages/devtools_app/test/shared/eval_integration_test.dart index f6f16e637a5..3dea8867f24 100644 --- a/packages/devtools_app/test/shared/eval_integration_test.dart +++ b/packages/devtools_app/test/shared/eval_integration_test.dart @@ -14,6 +14,7 @@ import '../test_infra/flutter_test_environment.dart'; void main() { final env = FlutterTestEnvironment( const FlutterRunConfiguration(withDebugger: true), + useTempDirectory: true, ); late Disposable isAlive; diff --git a/packages/devtools_app/test/test_infra/flutter_test_environment.dart b/packages/devtools_app/test/test_infra/flutter_test_environment.dart index 536a35967ae..71104149633 100644 --- a/packages/devtools_app/test/test_infra/flutter_test_environment.dart +++ b/packages/devtools_app/test/test_infra/flutter_test_environment.dart @@ -28,7 +28,7 @@ class FlutterTestEnvironment { FlutterTestEnvironment( this._runConfig, { String testAppDirectory = 'test/test_infra/fixtures/flutter_app', - bool useTempDirectory = true, + bool useTempDirectory = false, FlutterDriverFactory? flutterDriverFactory, }) : _testAppDirectory = testAppDirectory, _flutterDriverFactory = flutterDriverFactory ?? defaultFlutterRunDriver, From 314c23f6ea081c69c1d000db3ed99080e9c60a38 Mon Sep 17 00:00:00 2001 From: Kenzie Davisson Date: Wed, 29 Jul 2026 14:54:59 -0700 Subject: [PATCH 3/4] formatting --- .../test/screens/inspector/inspector_integration_test.dart | 5 ++--- .../test/test_infra/flutter_test_environment.dart | 6 +++--- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/packages/devtools_app/test/screens/inspector/inspector_integration_test.dart b/packages/devtools_app/test/screens/inspector/inspector_integration_test.dart index 2f7e9a88797..3f09b29eb1f 100644 --- a/packages/devtools_app/test/screens/inspector/inspector_integration_test.dart +++ b/packages/devtools_app/test/screens/inspector/inspector_integration_test.dart @@ -31,15 +31,14 @@ import '../../test_infra/matchers/matchers.dart'; // reduced to under 1 second without introducing flakes. const inspectorChangeSettleTime = Duration(seconds: 2); - void main() { // We need to use real async in this test so we need to use this binding. initializeLiveTestWidgetsFlutterBindingWithAssets(); const windowSize = Size(2600.0, 1200.0); // The auto-refresh tests modify lib/main.dart in-place. - // We use `useTempDirectory: true` to copy the fixture app to a temporary - // directory. This prevents flaky test failures in other tests (like + // We use `useTempDirectory: true` to copy the fixture app to a temporary + // directory. This prevents flaky test failures in other tests (like // inspector_service_test.dart) that run in parallel. final env = FlutterTestEnvironment( const FlutterRunConfiguration(withDebugger: true), diff --git a/packages/devtools_app/test/test_infra/flutter_test_environment.dart b/packages/devtools_app/test/test_infra/flutter_test_environment.dart index 71104149633..d85b3281dd2 100644 --- a/packages/devtools_app/test/test_infra/flutter_test_environment.dart +++ b/packages/devtools_app/test/test_infra/flutter_test_environment.dart @@ -35,9 +35,9 @@ class FlutterTestEnvironment { _flutterExe = _parseFlutterExeFromEnv() { if (useTempDirectory) { final parentDir = p.dirname(testAppDirectory); - final tempDirectory = Directory(parentDir).createTempSync( - 'flutter_test_temp_', - ); + final tempDirectory = Directory( + parentDir, + ).createTempSync('flutter_test_temp_'); _tempTestAppDirectory = tempDirectory.path; _copyToTempDirectory(testAppDirectory, tempDirectory); } From fd313fcd9f5c0de70c06075993d3654b5a5454d2 Mon Sep 17 00:00:00 2001 From: Kenzie Davisson Date: Wed, 29 Jul 2026 16:10:31 -0700 Subject: [PATCH 4/4] use temp directory with inspector service --- .../test/shared/diagnostics/inspector_service_test.dart | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/devtools_app/test/shared/diagnostics/inspector_service_test.dart b/packages/devtools_app/test/shared/diagnostics/inspector_service_test.dart index 63657deee0c..99b29293730 100644 --- a/packages/devtools_app/test/shared/diagnostics/inspector_service_test.dart +++ b/packages/devtools_app/test/shared/diagnostics/inspector_service_test.dart @@ -26,6 +26,7 @@ void main() { final env = FlutterTestEnvironment( const FlutterRunConfiguration(withDebugger: true), testAppDirectory: 'test/test_infra/fixtures/inspector_app', + useTempDirectory: true, ); InspectorService? inspectorService;