fix(mobile): retry diagnostics teardown

Co-authored-by: npub1ft62tztwwm2x9xamk25smmuaj4sfckdkldksruf2x2jwqalffkrq0g7arr <4af4a5896e76d4629bbbb2a90def9d95609c59b6fb6d01f12a32a4e077e94d86@sprout-oss.stage.blox.sqprod.co>
Signed-off-by: npub1ft62tztwwm2x9xamk25smmuaj4sfckdkldksruf2x2jwqalffkrq0g7arr <4af4a5896e76d4629bbbb2a90def9d95609c59b6fb6d01f12a32a4e077e94d86@sprout-oss.stage.blox.sqprod.co>
This commit is contained in:
npub1ft62tztwwm2x9xamk25smmuaj4sfckdkldksruf2x2jwqalffkrq0g7arr
2026-07-19 17:11:52 -07:00
parent a072957adb
commit e73f3c2288
2 changed files with 18 additions and 1 deletions
@@ -61,6 +61,12 @@ class DiagnosticsController extends ChangeNotifier {
Future<void> setConsent(bool granted) {
return _serialize(() async {
if (_consentGranted == granted) {
// A failed close keeps the runtime initialized even though the
// persisted preference and visible control are already off. Allow the
// same revocation to retry teardown until it succeeds.
if (!granted && _initialized) {
await _applyCurrentConsent();
}
return;
}
@@ -207,7 +207,7 @@ void main() {
expect(reporter.initializeCalls, 1);
});
test('close failure preserves persisted revocation', () async {
test('close failure preserves revocation and retries teardown', () async {
final controller = await createController(
storedValues: {diagnosticsConsentPreferenceKey: true},
);
@@ -219,6 +219,17 @@ void main() {
expect(controller.consentGranted, isFalse);
expect(preferences.getBool(diagnosticsConsentPreferenceKey), isFalse);
expect(reporter.closeCalls, 1);
reporter.closeError = null;
await controller.setConsent(false);
expect(controller.consentGranted, isFalse);
expect(preferences.getBool(diagnosticsConsentPreferenceKey), isFalse);
expect(reporter.closeCalls, 2);
expect(
logs,
contains('Diagnostics disabled: user consent is off; Sentry closed.'),
);
});
test('continues accepting changes after a failed operation', () async {