From ad1f58b610beca27ddd5f5511abde3f1fd0670d3 Mon Sep 17 00:00:00 2001 From: Nils Reichardt Date: Wed, 9 Aug 2023 18:34:32 +0200 Subject: [PATCH] Ignore Remote Config errors in integration tests (#726) Should fix #725 --------- Co-authored-by: Jonas Sander <29028262+Jonas-Sander@users.noreply.github.com> --- app/lib/main/plugin_initializations.dart | 21 ++++++++++++++++++++- app/lib/main/sharezone.dart | 1 + 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/app/lib/main/plugin_initializations.dart b/app/lib/main/plugin_initializations.dart index c810041a6..527470c18 100644 --- a/app/lib/main/plugin_initializations.dart +++ b/app/lib/main/plugin_initializations.dart @@ -15,6 +15,7 @@ import 'package:flutter/foundation.dart'; import 'package:purchases_flutter/purchases_flutter.dart'; import 'package:remote_configuration/remote_configuration.dart'; import 'package:shared_preferences/shared_preferences.dart'; +import 'package:sharezone/main/sharezone.dart'; import 'package:sharezone_utils/platform.dart'; import 'package:streaming_shared_preferences/streaming_shared_preferences.dart'; @@ -84,7 +85,7 @@ class PluginInitializations { // fetch the remote config in the background. The next time the app starts, // the fetched remote config will be available. await remoteConfiguration.activate(); - unawaited(remoteConfiguration.fetch()); + unawaited(_fetchRemoteConfig(remoteConfiguration)); return remoteConfiguration; } @@ -101,6 +102,24 @@ class PluginInitializations { } } +Future _fetchRemoteConfig(RemoteConfiguration remoteConfiguration) async { + try { + await remoteConfiguration.fetch(); + } catch (e) { + if (isIntegrationTest && PlatformCheck.isAndroid) { + if ('$e'.contains( + '[firebase_remote_config/internal] internal remote config fetch error')) { + log("Catched '$e'. Ignoring because we're running an integration test."); + // Sometimes the remote config fetch fails on Android integration tests, + // see https://github.com/SharezoneApp/sharezone-app/issues/725. + return; + } + } + + rethrow; + } +} + Future runPluginInitializations() async { final futureRemoteConfiguration = PluginInitializations.initializeRemoteConfiguration(); diff --git a/app/lib/main/sharezone.dart b/app/lib/main/sharezone.dart index d30c4e95f..5a5a705ee 100644 --- a/app/lib/main/sharezone.dart +++ b/app/lib/main/sharezone.dart @@ -40,6 +40,7 @@ import 'package:sharezone_widgets/sharezone_widgets.dart'; /// * Firebase Messaging (throws SERVICE_NOT_AVAILABLE or AUTHENTICATION_FAILED /// when running on device farm devices, see /// https://github.com/SharezoneApp/sharezone-app/issues/420) +/// * Ignore Remote Config fetch failures on Android bool isIntegrationTest = false; /// StreamBuilder "above" the Auth and SharezoneApp.