diff --git a/mobile/lib/shared/diagnostics/diagnostic_reporter.dart b/mobile/lib/shared/diagnostics/diagnostic_reporter.dart index b66f1d572f..5b43be168c 100644 --- a/mobile/lib/shared/diagnostics/diagnostic_reporter.dart +++ b/mobile/lib/shared/diagnostics/diagnostic_reporter.dart @@ -35,8 +35,11 @@ abstract interface class DiagnosticReporter { } /// The error a test report carries, so it is easy to tell apart. +/// +/// Not const: each report needs its own instance, or the destination's +/// deduplication drops every report after the first. class DiagnosticTestError implements Exception { - const DiagnosticTestError(); + DiagnosticTestError(); @override String toString() => 'DiagnosticTestError'; diff --git a/mobile/lib/shared/diagnostics/sentry_diagnostic_reporter.dart b/mobile/lib/shared/diagnostics/sentry_diagnostic_reporter.dart index 213285fd38..9e90ea3f80 100644 --- a/mobile/lib/shared/diagnostics/sentry_diagnostic_reporter.dart +++ b/mobile/lib/shared/diagnostics/sentry_diagnostic_reporter.dart @@ -78,7 +78,7 @@ class SentryDiagnosticReporter implements DiagnosticReporter { @override void sendTestReport() => reportError( - const DiagnosticTestError(), + DiagnosticTestError(), StackTrace.current, operation: DiagnosticOperation.testReport, ); diff --git a/mobile/test/shared/diagnostics/diagnostic_reporting_test.dart b/mobile/test/shared/diagnostics/diagnostic_reporting_test.dart index 98e31dcd4e..9d57b00891 100644 --- a/mobile/test/shared/diagnostics/diagnostic_reporting_test.dart +++ b/mobile/test/shared/diagnostics/diagnostic_reporting_test.dart @@ -14,6 +14,8 @@ import 'package:flutter/widgets.dart'; import 'package:flutter_test/flutter_test.dart'; import 'package:hooks_riverpod/hooks_riverpod.dart'; import 'package:nostr/nostr.dart' as nostr; +// ignore: depend_on_referenced_packages, implementation_imports +import 'package:sentry/src/deduplication/deduplication_event_processor.dart'; import 'package:sentry_flutter/sentry_flutter.dart'; // The SDK's own processors and integrations, so tests see what it really // sends rather than hand-built events. @@ -154,10 +156,11 @@ void main() { transport = _MemoryTransport(); options = SentryFlutterOptions(); configureDiagnostics(options, 'https://key@example.org/1'); - // The processors SentryFlutter.init installs, in its order. + // The processors Sentry.init and SentryFlutter.init install. options ..transport = transport ..sendClientReports = false + ..addEventProcessor(DeduplicationEventProcessor(options)) ..addEventProcessor(FlutterExceptionEventProcessor()) ..addEventProcessor(FlutterEnricherEventProcessor(options)) ..addEventProcessor(WidgetEventProcessor()) @@ -217,6 +220,15 @@ void main() { expect(sent['tags']['operation'], 'testReport'); }); + test('every test report is sent, not only the first', () async { + SentryDiagnosticReporter(hub: hub) + ..sendTestReport() + ..sendTestReport(); + await transport.count(2); + + expect(transport.events, hasLength(2)); + }); + testWidgets('sends only the allowed contexts', (tester) async { tester.platformDispatcher.accessibilityFeaturesTestValue = const FakeAccessibilityFeatures(accessibleNavigation: true); @@ -458,9 +470,15 @@ class _ReleaseChecker extends RuntimeChecker { class _MemoryTransport implements Transport { final events = >[]; final _first = Completer(); + final _added = StreamController.broadcast(); Future first() => _first.future; + Future count(int n) async { + if (events.length >= n) return; + await _added.stream.firstWhere((_) => events.length >= n); + } + @override Future send(SentryEnvelope envelope) async { for (final item in envelope.items) { @@ -468,6 +486,7 @@ class _MemoryTransport implements Transport { final bytes = await item.dataFactory(); events.add(jsonDecode(utf8.decode(bytes)) as Map); if (!_first.isCompleted) _first.complete(); + _added.add(null); } return envelope.header.eventId; }