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.
|
/// 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 {
|
class DiagnosticTestError implements Exception {
|
||||||
const DiagnosticTestError();
|
DiagnosticTestError();
|
||||||
|
|
||||||
@override
|
@override
|
||||||
String toString() => 'DiagnosticTestError';
|
String toString() => 'DiagnosticTestError';
|
||||||
|
|||||||
@@ -78,7 +78,7 @@ class SentryDiagnosticReporter implements DiagnosticReporter {
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
void sendTestReport() => reportError(
|
void sendTestReport() => reportError(
|
||||||
const DiagnosticTestError(),
|
DiagnosticTestError(),
|
||||||
StackTrace.current,
|
StackTrace.current,
|
||||||
operation: DiagnosticOperation.testReport,
|
operation: DiagnosticOperation.testReport,
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -14,6 +14,8 @@ import 'package:flutter/widgets.dart';
|
|||||||
import 'package:flutter_test/flutter_test.dart';
|
import 'package:flutter_test/flutter_test.dart';
|
||||||
import 'package:hooks_riverpod/hooks_riverpod.dart';
|
import 'package:hooks_riverpod/hooks_riverpod.dart';
|
||||||
import 'package:nostr/nostr.dart' as nostr;
|
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';
|
import 'package:sentry_flutter/sentry_flutter.dart';
|
||||||
// The SDK's own processors and integrations, so tests see what it really
|
// The SDK's own processors and integrations, so tests see what it really
|
||||||
// sends rather than hand-built events.
|
// sends rather than hand-built events.
|
||||||
@@ -154,10 +156,11 @@ void main() {
|
|||||||
transport = _MemoryTransport();
|
transport = _MemoryTransport();
|
||||||
options = SentryFlutterOptions();
|
options = SentryFlutterOptions();
|
||||||
configureDiagnostics(options, 'https://key@example.org/1');
|
configureDiagnostics(options, 'https://key@example.org/1');
|
||||||
// The processors SentryFlutter.init installs, in its order.
|
// The processors Sentry.init and SentryFlutter.init install.
|
||||||
options
|
options
|
||||||
..transport = transport
|
..transport = transport
|
||||||
..sendClientReports = false
|
..sendClientReports = false
|
||||||
|
..addEventProcessor(DeduplicationEventProcessor(options))
|
||||||
..addEventProcessor(FlutterExceptionEventProcessor())
|
..addEventProcessor(FlutterExceptionEventProcessor())
|
||||||
..addEventProcessor(FlutterEnricherEventProcessor(options))
|
..addEventProcessor(FlutterEnricherEventProcessor(options))
|
||||||
..addEventProcessor(WidgetEventProcessor())
|
..addEventProcessor(WidgetEventProcessor())
|
||||||
@@ -217,6 +220,15 @@ void main() {
|
|||||||
expect(sent['tags']['operation'], 'testReport');
|
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 {
|
testWidgets('sends only the allowed contexts', (tester) async {
|
||||||
tester.platformDispatcher.accessibilityFeaturesTestValue =
|
tester.platformDispatcher.accessibilityFeaturesTestValue =
|
||||||
const FakeAccessibilityFeatures(accessibleNavigation: true);
|
const FakeAccessibilityFeatures(accessibleNavigation: true);
|
||||||
@@ -458,9 +470,15 @@ class _ReleaseChecker extends RuntimeChecker {
|
|||||||
class _MemoryTransport implements Transport {
|
class _MemoryTransport implements Transport {
|
||||||
final events = <Map<String, dynamic>>[];
|
final events = <Map<String, dynamic>>[];
|
||||||
final _first = Completer<void>();
|
final _first = Completer<void>();
|
||||||
|
final _added = StreamController<void>.broadcast();
|
||||||
|
|
||||||
Future<void> first() => _first.future;
|
Future<void> first() => _first.future;
|
||||||
|
|
||||||
|
Future<void> count(int n) async {
|
||||||
|
if (events.length >= n) return;
|
||||||
|
await _added.stream.firstWhere((_) => events.length >= n);
|
||||||
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Future<SentryId?> send(SentryEnvelope envelope) async {
|
Future<SentryId?> send(SentryEnvelope envelope) async {
|
||||||
for (final item in envelope.items) {
|
for (final item in envelope.items) {
|
||||||
@@ -468,6 +486,7 @@ class _MemoryTransport implements Transport {
|
|||||||
final bytes = await item.dataFactory();
|
final bytes = await item.dataFactory();
|
||||||
events.add(jsonDecode(utf8.decode(bytes)) as Map<String, dynamic>);
|
events.add(jsonDecode(utf8.decode(bytes)) as Map<String, dynamic>);
|
||||||
if (!_first.isCompleted) _first.complete();
|
if (!_first.isCompleted) _first.complete();
|
||||||
|
_added.add(null);
|
||||||
}
|
}
|
||||||
return envelope.header.eventId;
|
return envelope.header.eventId;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user