Skip to content

Commit 2133991

Browse files
authored
[path_provider] De-flake getExternalStorageDirectories test (flutter#5628)
Fixes the flaky path provider test. Directories.listSync will sometimes not return the files in the directory (as discussed in flutter#139378), but the files are there and (after letting it loop for quite a while and comparing to current flake) they always appear in the output of `Process.runSync('ls', ...)`.
1 parent b08f915 commit 2133991

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

packages/path_provider/path_provider/example/integration_test/path_provider_test.dart

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,13 @@ void _verifySampleFile(Directory? directory, String name) {
117117

118118
file.writeAsStringSync('Hello world!');
119119
expect(file.readAsStringSync(), 'Hello world!');
120-
expect(directory.listSync(), isNotEmpty);
120+
// This check intentionally avoids using Directory.listSync on Android due to
121+
// https://github.com/dart-lang/sdk/issues/54287.
122+
if (Platform.isAndroid) {
123+
expect(
124+
Process.runSync('ls', <String>[directory.path]).stdout, contains(name));
125+
} else {
126+
expect(directory.listSync(), isNotEmpty);
127+
}
121128
file.deleteSync();
122129
}

packages/path_provider/path_provider_android/example/integration_test/path_provider_test.dart

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,9 @@ void _verifySampleFile(String? directoryPath, String name) {
101101

102102
file.writeAsStringSync('Hello world!');
103103
expect(file.readAsStringSync(), 'Hello world!');
104-
expect(directory.listSync(), isNotEmpty);
104+
// This check intentionally avoids using Directory.listSync due to
105+
// https://github.com/dart-lang/sdk/issues/54287.
106+
expect(
107+
Process.runSync('ls', <String>[directory.path]).stdout, contains(name));
105108
file.deleteSync();
106109
}

0 commit comments

Comments
 (0)