mirror of
https://github.com/block/buzz.git
synced 2026-11-24 02:02:07 +00:00
fix(mobile): send every test report, not only the first
Each test report used one const DiagnosticTestError, so Sentry's deduplication dropped every report after the first in a launch. Report a fresh instance per tap, and install the deduplication processor in the test hub so a second report is checked. Co-authored-by: studio <dc2fc481343672df31a689840c09299972e704dac592e0da6f18486646a7ee3e@localhost> Signed-off-by: Tom Brow <tomb@block.xyz>
This commit is contained in:
@@ -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';
|
||||
|
||||
@@ -78,7 +78,7 @@ class SentryDiagnosticReporter implements DiagnosticReporter {
|
||||
|
||||
@override
|
||||
void sendTestReport() => reportError(
|
||||
const DiagnosticTestError(),
|
||||
DiagnosticTestError(),
|
||||
StackTrace.current,
|
||||
operation: DiagnosticOperation.testReport,
|
||||
);
|
||||
|
||||
@@ -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 = <Map<String, dynamic>>[];
|
||||
final _first = Completer<void>();
|
||||
final _added = StreamController<void>.broadcast();
|
||||
|
||||
Future<void> first() => _first.future;
|
||||
|
||||
Future<void> count(int n) async {
|
||||
if (events.length >= n) return;
|
||||
await _added.stream.firstWhere((_) => events.length >= n);
|
||||
}
|
||||
|
||||
@override
|
||||
Future<SentryId?> 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<String, dynamic>);
|
||||
if (!_first.isCompleted) _first.complete();
|
||||
_added.add(null);
|
||||
}
|
||||
return envelope.header.eventId;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user