From 3ac2dba58dcc69493938caa270cbeaf406c44c3b Mon Sep 17 00:00:00 2001 From: Andrew Kolos Date: Tue, 2 Jan 2024 16:15:51 -0800 Subject: [PATCH] Fix setup race in asset bundle tests (#140832) Fixes https://github.com/flutter/flutter/issues/140665 by replacing use of `setUpAll` and `teardownAll` with `setUp` and `teardown` respectively. My theory has to how this issue happened (and how this PR fixes it) is that `setUpAll` is not guaranteed to run after any `setUp` in any parent test groups. However, `setUp` is guaranteed to run after any set-up callbacks in parent groups. From the [documentation](https://api.flutter.dev/flutter/flutter_test/setUp.html): > If this is called within a test group, it applies only to tests in that group. The body will be run after any set-up callbacks in parent groups or at the top level. Meanwhile, [`setUpAll`](https://api.flutter.dev/flutter/flutter_test/setUpAll.html) has a weaker documented guarantee that applies only to other `setUpAll` calls: > If this is called within a test group, The body will run before all tests in that group. It will be run after any [setUpAll](https://api.flutter.dev/flutter/flutter_test/setUpAll.html) callbacks in parent groups or at the top level. It won't be run if none of the tests in the group are run. --- .../test/general.shard/asset_bundle_test.dart | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) diff --git a/packages/flutter_tools/test/general.shard/asset_bundle_test.dart b/packages/flutter_tools/test/general.shard/asset_bundle_test.dart index 9d1cb37fc1..d325616dbc 100644 --- a/packages/flutter_tools/test/general.shard/asset_bundle_test.dart +++ b/packages/flutter_tools/test/general.shard/asset_bundle_test.dart @@ -2,13 +2,6 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -// TODO(andrewkolos): Remove this tag once this test's state leaks/test -// dependencies have been fixed. -// https://github.com/flutter/flutter/issues/140665 -// Fails with "flutter test --test-randomize-ordering-seed=20231227" -@Tags(['no-shuffle']) -library; - import 'dart:convert'; import 'dart:typed_data'; @@ -356,14 +349,14 @@ flutter: return bundle; } - late final String? previousCacheFlutterRootValue; + late String? previousCacheFlutterRootValue; - setUpAll(() { + setUp(() { previousCacheFlutterRootValue = Cache.flutterRoot; Cache.flutterRoot = Cache.defaultFlutterRoot(platform: platform, fileSystem: testFileSystem, userMessages: UserMessages()); }); - tearDownAll(() => Cache.flutterRoot = previousCacheFlutterRootValue); + tearDown(() => Cache.flutterRoot = previousCacheFlutterRootValue); testWithoutContext('correctly bundles assets given a simple asset manifest with flavors', () async { testFileSystem.file('.packages').createSync();