Deflake wildcard asset test (#42597)
diff --git a/packages/flutter_tools/lib/src/asset.dart b/packages/flutter_tools/lib/src/asset.dart
index 67c24ae..84dad92 100644
--- a/packages/flutter_tools/lib/src/asset.dart
+++ b/packages/flutter_tools/lib/src/asset.dart
@@ -91,12 +91,17 @@
}
for (Directory directory in _wildcardDirectories.values) {
- final DateTime dateTime = directory.statSync().modified;
- if (dateTime == null) {
- continue;
+ if (!directory.existsSync()) {
+ return true; // directory was deleted.
}
- if (dateTime.isAfter(_lastBuildTimestamp)) {
- return true;
+ for (File file in directory.listSync()) {
+ final DateTime dateTime = file.statSync().modified;
+ if (dateTime == null) {
+ continue;
+ }
+ if (dateTime.isAfter(_lastBuildTimestamp)) {
+ return true;
+ }
}
}
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 4335fcb..537ccd5 100644
--- a/packages/flutter_tools/test/general.shard/asset_bundle_test.dart
+++ b/packages/flutter_tools/test/general.shard/asset_bundle_test.dart
@@ -60,7 +60,7 @@
});
testUsingContext('wildcard directories are updated when filesystem changes', () async {
- fs.file('.packages').createSync();
+ final File packageFile = fs.file('.packages')..createSync();
fs.file(fs.path.join('assets', 'foo', 'bar.txt')).createSync(recursive: true);
fs.file('pubspec.yaml')
..createSync()
@@ -80,11 +80,10 @@
expect(bundle.entries.length, 4);
expect(bundle.needsBuild(manifestPath: 'pubspec.yaml'), false);
- // Adding a file should update the stat of the directory, but instead
- // we need to fully recreate it.
- fs.directory(fs.path.join('assets', 'foo')).deleteSync(recursive: true);
- fs.file(fs.path.join('assets', 'foo', 'fizz.txt')).createSync(recursive: true);
- fs.file(fs.path.join('assets', 'foo', 'bar.txt')).createSync();
+ // Simulate modifying the files by updating the filestat time manually.
+ fs.file(fs.path.join('assets', 'foo', 'fizz.txt'))
+ ..createSync(recursive: true)
+ ..setLastModifiedSync(packageFile.lastModifiedSync().add(const Duration(hours: 1)));
expect(bundle.needsBuild(manifestPath: 'pubspec.yaml'), true);
await bundle.build(manifestPath: 'pubspec.yaml');
@@ -102,7 +101,7 @@
testUsingContext('handle removal of wildcard directories', () async {
fs.file(fs.path.join('assets', 'foo', 'bar.txt')).createSync(recursive: true);
- fs.file('pubspec.yaml')
+ final File pubspec = fs.file('pubspec.yaml')
..createSync()
..writeAsStringSync(r'''
name: example
@@ -122,14 +121,17 @@
expect(bundle.needsBuild(manifestPath: 'pubspec.yaml'), false);
// Delete the wildcard directory and update pubspec file.
+ final DateTime modifiedTime = pubspec.lastModifiedSync().add(const Duration(hours: 1));
fs.directory(fs.path.join('assets', 'foo')).deleteSync(recursive: true);
fs.file('pubspec.yaml')
..createSync()
..writeAsStringSync(r'''
-name: example''');
+name: example''')
+ ..setLastModifiedSync(modifiedTime);
// touch .packages to make sure its change time is after pubspec.yaml's
- fs.file('.packages').createSync();
+ fs.file('.packages')
+ ..setLastModifiedSync(modifiedTime);
// Even though the previous file was removed, it is left in the
// asset manifest and not updated. This is due to the devfs not
@@ -145,7 +147,7 @@
}, overrides: <Type, Generator>{
FileSystem: () => testFileSystem,
ProcessManager: () => FakeProcessManager(<FakeCommand>[]),
- }, skip: true); // https://github.com/flutter/flutter/issues/34446
+ });
});
}