Skip to content

Commit

Permalink
test: rethrow in automated test mode
Browse files Browse the repository at this point in the history
  • Loading branch information
vaind committed Sep 13, 2024
1 parent 4baf6aa commit b8bd4f1
Show file tree
Hide file tree
Showing 23 changed files with 104 additions and 38 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,9 @@ class IoEnricherEventProcessor implements EnricherEventProcessor {
exception: exception,
stackTrace: stackTrace,
);
if (_options.automatedTestMode) {
rethrow;
}
}
}

Expand Down
3 changes: 3 additions & 0 deletions dart/lib/src/event_processor/enricher/io_platform_memory.dart
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,9 @@ class PlatformMemory {
}
} catch (e) {
options.logger(SentryLevel.warning, "Failed to run process: $e");
if (options.automatedTestMode) {
rethrow;
}
}
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,9 @@ class IoExceptionEventProcessor implements ExceptionEventProcessor {
exception: exception,
stackTrace: stackTrace,
);
if (_options.automatedTestMode) {
rethrow;
}
}

return event.copyWith(
Expand Down
27 changes: 27 additions & 0 deletions dart/lib/src/hub.dart
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,9 @@ class Hub {
exception: exception,
stackTrace: stackTrace,
);
if (_options.automatedTestMode) {
rethrow;
}
} finally {
_lastEventId = sentryId;
}
Expand Down Expand Up @@ -183,6 +186,9 @@ class Hub {
exception: exception,
stackTrace: stackTrace,
);
if (_options.automatedTestMode) {
rethrow;
}
} finally {
_lastEventId = sentryId;
}
Expand Down Expand Up @@ -238,6 +244,9 @@ class Hub {
exception: exception,
stackTrace: stackTrace,
);
if (_options.automatedTestMode) {
rethrow;
}
} finally {
_lastEventId = sentryId;
}
Expand Down Expand Up @@ -271,6 +280,9 @@ class Hub {
exception: exception,
stackTrace: stacktrace,
);
if (_options.automatedTestMode) {
rethrow;
}
}
}

Expand Down Expand Up @@ -364,6 +376,9 @@ class Hub {
exception: exception,
stackTrace: stackTrace,
);
if (_options.automatedTestMode) {
rethrow;
}
}

_isEnabled = false;
Expand Down Expand Up @@ -565,6 +580,9 @@ class Hub {
exception: exception,
stackTrace: stackTrace,
);
if (_options.automatedTestMode) {
rethrow;
}
}
}
}
Expand Down Expand Up @@ -602,6 +620,9 @@ class Hub {
exception: exception,
stackTrace: stackTrace,
);
if (_options.automatedTestMode) {
rethrow;
}
}
}
return sentryId;
Expand Down Expand Up @@ -682,6 +703,9 @@ class _WeakMap {
exception: exception,
stackTrace: stackTrace,
);
if (_options.automatedTestMode) {
rethrow;
}
}
}

Expand All @@ -699,6 +723,9 @@ class _WeakMap {
exception: exception,
stackTrace: stackTrace,
);
if (_options.automatedTestMode) {
rethrow;
}
}
return null;
}
Expand Down
3 changes: 3 additions & 0 deletions dart/lib/src/load_dart_debug_images_integration.dart
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ class _LoadImageIntegrationEventProcessor implements EventProcessor {
exception: e,
stackTrace: stackTrace,
);
if (_options.automatedTestMode) {
rethrow;
}
return event;
}
}
Expand Down
3 changes: 3 additions & 0 deletions dart/lib/src/recursive_exception_cause_extractor.dart
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ class RecursiveExceptionCauseExtractor {
exception: exception,
stackTrace: stackTrace,
);
if (_options.automatedTestMode) {
rethrow;
}
break;
}
}
Expand Down
1 change: 1 addition & 0 deletions dart/lib/src/sentry_baggage.dart
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ class SentryBaggage {
exception: exception,
stackTrace: stackTrace,
);
// TODO rehtow in automatedTestMode
}
}

Expand Down
1 change: 1 addition & 0 deletions dart/lib/src/sentry_envelope_item.dart
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ class SentryEnvelopeItem {
// TODO the data copy could be avoided - this would be most significant with attachments.
return [...itemHeader, ...newLine, ...data];
} catch (e) {
// TODO rethrow in automatedTestMode
return [];
}
}
Expand Down
3 changes: 3 additions & 0 deletions dart/lib/src/transport/http_transport.dart
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,9 @@ class HttpTransport implements Transport {
return eventId != null ? SentryId.fromId(eventId) : null;
} catch (e) {
_options.logger(SentryLevel.error, 'Error parsing response: $e');
if (_options.automatedTestMode) {
rethrow;
}
return null;
}
}
Expand Down
3 changes: 3 additions & 0 deletions dart/lib/src/transport/spotlight_http_transport.dart
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ class SpotlightHttpTransport extends Transport {
} catch (e) {
_options.logger(
SentryLevel.warning, 'Failed to send envelope to Spotlight: $e');
if (_options.automatedTestMode) {
rethrow;
}
}
return _transport.send(envelope);
}
Expand Down
3 changes: 3 additions & 0 deletions flutter/lib/src/binding_wrapper.dart
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ class BindingWrapper {
stackTrace: s,
logger: 'BindingWrapper',
);
if (_hub.options.automatedTestMode) {
rethrow;
}
return null;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,10 @@ class AndroidPlatformExceptionEventProcessor implements EventProcessor {
exception: e,
stackTrace: stackTrace,
);
// ignore: invalid_use_of_internal_member
if (_options.automatedTestMode) {
rethrow;
}
return event;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,9 @@ class NativeAppStartEventProcessor implements EventProcessor {
} catch (e) {
_hub.options.logger(SentryLevel.warning,
'Failed to attach native span to app start transaction: $e');
if (_hub.options.automatedTestMode) {
rethrow;
}
}
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,10 @@ class ScreenshotEventProcessor implements EventProcessor {
exception: exception,
stackTrace: stackTrace,
);
// ignore: invalid_use_of_internal_member
if (_options.automatedTestMode) {
rethrow;
}
}
return null;
}
Expand Down
4 changes: 4 additions & 0 deletions flutter/lib/src/file_system_transport.dart
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ class FileSystemTransport implements Transport {
exception: exception,
stackTrace: stackTrace,
);
// ignore: invalid_use_of_internal_member
if (_options.automatedTestMode) {
rethrow;
}
return SentryId.empty();
}

Expand Down
4 changes: 4 additions & 0 deletions flutter/lib/src/integrations/load_contexts_integration.dart
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,10 @@ class _LoadContextsIntegrationEventProcessor implements EventProcessor {
exception: exception,
stackTrace: stackTrace,
);
// ignore: invalid_use_of_internal_member
if (_options.automatedTestMode) {
rethrow;
}
}
return event;
}
Expand Down
4 changes: 4 additions & 0 deletions flutter/lib/src/integrations/load_release_integration.dart
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@ class LoadReleaseIntegration extends Integration<SentryFlutterOptions> {
exception: exception,
stackTrace: stackTrace,
);
// ignore: invalid_use_of_internal_member
if (options.automatedTestMode) {
rethrow;
}
}

options.sdk.addIntegration('loadReleaseIntegration');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,9 @@ class NativeAppStartIntegration extends Integration<SentryFlutterOptions> {
} catch (e) {
_hub.options.logger(
SentryLevel.warning, 'Failed to parse native span times: $e');
if (_hub.options.automatedTestMode) {
rethrow;
}
continue;
}
}
Expand Down
4 changes: 4 additions & 0 deletions flutter/lib/src/integrations/on_error_integration.dart
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,10 @@ class PlatformDispatcherWrapper {
exception: exception,
stackTrace: stacktrace,
);
// ignore: invalid_use_of_internal_member
if (options.automatedTestMode) {
rethrow;
}
return false;
}
return true;
Expand Down
6 changes: 6 additions & 0 deletions flutter/lib/src/navigation/sentry_navigator_observer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,9 @@ class SentryNavigatorObserver extends RouteObserver<PageRoute<dynamic>> {
exception: exception,
stackTrace: stacktrace,
);
if (_hub.options.automatedTestMode) {
rethrow;
}
} finally {
await transaction?.finish();
if (clearAfter) {
Expand Down Expand Up @@ -379,6 +382,9 @@ class SentryNavigatorObserver extends RouteObserver<PageRoute<dynamic>> {
exception: exception,
stackTrace: stacktrace,
);
if (_hub.options.automatedTestMode) {
rethrow;
}
} finally {
_clear();
}
Expand Down
Binary file added flutter/temp/native-test/dist/sentry.dll
Binary file not shown.
48 changes: 11 additions & 37 deletions flutter/test/initialization_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,48 +14,22 @@ void main() {
await Sentry.close();
});

test('async re-initilization', () async {
await SentryFlutter.init(
(options) {
options.dsn = fakeDsn;
// ignore: invalid_use_of_internal_member
options.automatedTestMode = true;
},
);

await Sentry.close();
void optionsInitializer(SentryFlutterOptions options) {
options.dsn = fakeDsn;
// ignore: invalid_use_of_internal_member
options.automatedTestMode = true;

await SentryFlutter.init(
(options) {
options.dsn = fakeDsn;
// ignore: invalid_use_of_internal_member
options.automatedTestMode = true;
},
);
// LoadReleaseIntegration throws because package_info channel is not available
options.removeIntegration(
options.integrations.firstWhere((i) => i is LoadReleaseIntegration));
}

await Sentry.close();
});

// This is the failure from
// https://github.com/getsentry/sentry-dart/issues/508
test('re-initilization', () async {
await SentryFlutter.init(
(options) {
options.dsn = fakeDsn;
// ignore: invalid_use_of_internal_member
options.automatedTestMode = true;
},
);
test('async re-initilization', () async {
await SentryFlutter.init(optionsInitializer);

await Sentry.close();

await SentryFlutter.init(
(options) {
options.dsn = fakeDsn;
// ignore: invalid_use_of_internal_member
options.automatedTestMode = true;
},
);
await SentryFlutter.init(optionsInitializer);

await Sentry.close();
});
Expand Down
5 changes: 4 additions & 1 deletion flutter/test/sentry_navigator_observer_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -598,6 +598,7 @@ void main() {
const op = 'navigation';
final hub = _MockHub();
final span = getMockSentryTracer(name: oldRouteName);
when(span.children).thenReturn([]);
when(span.context).thenReturn(SentrySpanContext(operation: op));
when(span.status).thenReturn(null);
when(span.finished).thenReturn(false);
Expand Down Expand Up @@ -982,6 +983,7 @@ void main() {
final secondRoute = route(RouteSettings(name: 'testRoute'));

final hub = _MockHub();
_whenAnyStart(hub, NoOpSentrySpan());

final sut = fixture.getSut(hub: hub, ignoreRoutes: ["testRoute"]);

Expand All @@ -1002,6 +1004,7 @@ void main() {
final secondRoute = route(RouteSettings(name: 'testRoute'));

final hub = _MockHub();
_whenAnyStart(hub, NoOpSentrySpan());

final sut = fixture.getSut(hub: hub, ignoreRoutes: ["testRoute"]);

Expand Down Expand Up @@ -1086,7 +1089,7 @@ class _MockHub extends MockHub {
}
}

ISentrySpan getMockSentryTracer({String? name, bool? finished}) {
MockSentryTracer getMockSentryTracer({String? name, bool? finished}) {
final tracer = MockSentryTracer();
when(tracer.name).thenReturn(name ?? 'name');
when(tracer.finished).thenReturn(finished ?? true);
Expand Down

0 comments on commit b8bd4f1

Please sign in to comment.