## Summary - Increases the retry delays in `_resolveDatabasePath()` from `[100, 300, 600]` ms (~1 s) to `[200, 500, 1000, 2000]` ms (~3.7 s). - Adds a regression test (`test/unit/database_path_test.dart`) that verifies `initDatabasePath()` does not throw when the `path_provider` channel is unavailable. ## Root cause On some slow Android devices (e.g. the Motorola reported in #166), the `path_provider` Pigeon channel is not ready even several seconds after `runApp()` returns. The previous back-off budget of ~1 s was not enough, causing `_resolveDatabasePath()` to exhaust all retries and throw a `PlatformException`, crashing the app with the message shown in the issue. ## Test plan - [ ] `flutter test test/unit/database_path_test.dart` passes (new regression test) - [ ] `flutter test test/unit/` — all 325 unit tests pass - [ ] `flutter analyze` — no issues Fixes #166 Co-authored-by: Thomas SharedInbox <sharedinbox@thomas-guettler.de> Reviewed-on: https://codeberg.org/guettli/sharedinbox/pulls/169
42 lines
1.6 KiB
Dart
42 lines
1.6 KiB
Dart
import 'package:flutter/services.dart';
|
|
import 'package:flutter_test/flutter_test.dart';
|
|
import 'package:path_provider_platform_interface/path_provider_platform_interface.dart';
|
|
import 'package:plugin_platform_interface/plugin_platform_interface.dart';
|
|
|
|
import 'package:sharedinbox/data/db/database.dart';
|
|
|
|
// Fake PathProviderPlatform that always throws PlatformException(channel-error)
|
|
// to simulate the Pigeon channel not being ready at startup (issue #166).
|
|
class _UnavailablePathProvider extends Fake
|
|
with MockPlatformInterfaceMixin
|
|
implements PathProviderPlatform {
|
|
@override
|
|
Future<String?> getApplicationSupportPath() async {
|
|
throw PlatformException(
|
|
code: 'channel-error',
|
|
message: 'Simulated: path_provider channel not ready',
|
|
);
|
|
}
|
|
}
|
|
|
|
void main() {
|
|
TestWidgetsFlutterBinding.ensureInitialized();
|
|
|
|
// Regression test for https://codeberg.org/guettli/sharedinbox/issues/166:
|
|
// On some slow Android devices the path_provider Pigeon channel is not ready
|
|
// when initDatabasePath() runs before runApp(). initDatabasePath() must
|
|
// absorb the PlatformException and let the app start; _resolveDatabasePath()
|
|
// then retries with back-off on first DB access.
|
|
test(
|
|
'initDatabasePath completes without throwing when path_provider is unavailable',
|
|
() async {
|
|
final prev = PathProviderPlatform.instance;
|
|
PathProviderPlatform.instance = _UnavailablePathProvider();
|
|
addTearDown(() => PathProviderPlatform.instance = prev);
|
|
|
|
// Must not throw — the exception is swallowed so the app can continue.
|
|
await expectLater(initDatabasePath(), completes);
|
|
},
|
|
);
|
|
}
|