From 2133991a460e7a53ada690e596000ec5993d308c Mon Sep 17 00:00:00 2001
From: Gray Mackall <34871572+gmackall@users.noreply.github.com>
Date: Wed, 13 Dec 2023 12:26:56 -0800
Subject: [PATCH] [path_provider] De-flake getExternalStorageDirectories test
 (#5628)

Fixes the flaky path provider test.

Directories.listSync will sometimes not return the files in the directory (as discussed in https://github.com/flutter/flutter/issues/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', ...)`.
---
 .../example/integration_test/path_provider_test.dart     | 9 ++++++++-
 .../example/integration_test/path_provider_test.dart     | 5 ++++-
 2 files changed, 12 insertions(+), 2 deletions(-)

diff --git a/packages/path_provider/path_provider/example/integration_test/path_provider_test.dart b/packages/path_provider/path_provider/example/integration_test/path_provider_test.dart
index f26f88b465..9a4a5d6b21 100644
--- a/packages/path_provider/path_provider/example/integration_test/path_provider_test.dart
+++ b/packages/path_provider/path_provider/example/integration_test/path_provider_test.dart
@@ -117,6 +117,13 @@ void _verifySampleFile(Directory? directory, String name) {
 
   file.writeAsStringSync('Hello world!');
   expect(file.readAsStringSync(), 'Hello world!');
-  expect(directory.listSync(), isNotEmpty);
+  // This check intentionally avoids using Directory.listSync on Android due to
+  // https://github.com/dart-lang/sdk/issues/54287.
+  if (Platform.isAndroid) {
+    expect(
+        Process.runSync('ls', <String>[directory.path]).stdout, contains(name));
+  } else {
+    expect(directory.listSync(), isNotEmpty);
+  }
   file.deleteSync();
 }
diff --git a/packages/path_provider/path_provider_android/example/integration_test/path_provider_test.dart b/packages/path_provider/path_provider_android/example/integration_test/path_provider_test.dart
index e48cdf1796..104a7e1aaf 100644
--- a/packages/path_provider/path_provider_android/example/integration_test/path_provider_test.dart
+++ b/packages/path_provider/path_provider_android/example/integration_test/path_provider_test.dart
@@ -101,6 +101,9 @@ void _verifySampleFile(String? directoryPath, String name) {
 
   file.writeAsStringSync('Hello world!');
   expect(file.readAsStringSync(), 'Hello world!');
-  expect(directory.listSync(), isNotEmpty);
+  // This check intentionally avoids using Directory.listSync due to
+  // https://github.com/dart-lang/sdk/issues/54287.
+  expect(
+      Process.runSync('ls', <String>[directory.path]).stdout, contains(name));
   file.deleteSync();
 }