Skip to content

Commit

Permalink
Merge branch 'feat/use-app-launched-in-foreground-to-determinate-inva…
Browse files Browse the repository at this point in the history
…lid-app-start-data-on-android' of https://github.com/getsentry/sentry-dart into feat/use-app-launched-in-foreground-to-determinate-invalid-app-start-data-on-android

* 'feat/use-app-launched-in-foreground-to-determinate-invalid-app-start-data-on-android' of https://github.com/getsentry/sentry-dart:
  test: rethrow exceptions (#2290)
  • Loading branch information
martinhaintz committed Sep 17, 2024
2 parents 7067094 + cf64268 commit fad381e
Show file tree
Hide file tree
Showing 140 changed files with 846 additions and 514 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 rethrow in options.automatedTestMode (currently not available here to check)
}
}

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 options.automatedTestMode (currently not available here to check)
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
5 changes: 2 additions & 3 deletions dart/test/debug_image_extractor_test.dart
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import 'package:test/test.dart';
import 'package:sentry/sentry.dart';
import 'package:sentry/src/debug_image_extractor.dart';

import 'mocks/mock_platform.dart';
import 'mocks/mock_platform_checker.dart';
import 'test_utils.dart';

void main() {
group(DebugImageExtractor, () {
Expand Down Expand Up @@ -112,8 +112,7 @@ isolate_dso_base: 10000000

class Fixture {
DebugImageExtractor getSut({required MockPlatform platform}) {
final options = SentryOptions(dsn: 'https://public@sentry.example.com/1')
..platformChecker = MockPlatformChecker(platform: platform);
final options = defaultTestOptions(MockPlatformChecker(platform: platform));
return DebugImageExtractor(options);
}
}
4 changes: 3 additions & 1 deletion dart/test/diagnostic_logger_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import 'package:sentry/sentry.dart';
import 'package:sentry/src/diagnostic_logger.dart';
import 'package:test/test.dart';

import 'test_utils.dart';

void main() {
late Fixture fixture;

Expand Down Expand Up @@ -44,7 +46,7 @@ void main() {
}

class Fixture {
var options = SentryOptions();
var options = defaultTestOptions();

Object? loggedMessage;

Expand Down
9 changes: 4 additions & 5 deletions dart/test/environment_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import 'package:test/test.dart';

import 'mocks.dart';
import 'mocks/mock_environment_variables.dart';
import 'test_utils.dart';

void main() {
// See https://docs.sentry.io/platforms/dart/configuration/options/
Expand All @@ -13,7 +14,7 @@ void main() {
});

test('SentryOptions are not overriden by environment', () async {
final options = SentryOptions(dsn: fakeDsn);
final options = defaultTestOptions();
options.release = 'release-1.2.3';
options.dist = 'foo';
options.environment = 'prod';
Expand All @@ -23,28 +24,26 @@ void main() {
release: 'release-9.8.7',
dist: 'bar',
);
options.automatedTestMode = true;

await Sentry.init(
(options) => options,
options: options,
);

expect(options.dsn, fakeDsn);
expect(options.dsn, testDsn);
expect(options.environment, 'prod');
expect(options.release, 'release-1.2.3');
expect(options.dist, 'foo');
});

test('SentryOptions are overriden by environment', () async {
final options = SentryOptions();
final options = defaultTestOptions()..dsn = null;
options.environmentVariables = MockEnvironmentVariables(
dsn: fakeDsn,
environment: 'staging',
release: 'release-9.8.7',
dist: 'bar',
);
options.automatedTestMode = true;

await Sentry.init(
(options) => options,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import 'package:test/test.dart';
import '../mocks.dart';
import '../mocks/mock_hub.dart';
import '../mocks/mock_transport.dart';
import '../test_utils.dart';

void main() {
group('$DeduplicationEventProcessor', () {
Expand Down Expand Up @@ -77,14 +78,13 @@ void main() {

final transport = MockTransport();

final options = SentryOptions(dsn: fakeDsn)..automatedTestMode = true;
await Sentry.init(
(options) {
options.dsn = fakeDsn;
options.transport = transport;
options.enableDeduplication = true;
},
options: options,
options: defaultTestOptions(),
);

// The test doesn't work if `outerTestMethod` is passed as
Expand Down Expand Up @@ -114,7 +114,7 @@ class Fixture {

DeduplicationEventProcessor getSut(bool enabled,
[int? maxDeduplicationItems]) {
final options = SentryOptions(dsn: fakeDsn)
final options = defaultTestOptions()
..enableDeduplication = enabled
..maxDeduplicationItems = maxDeduplicationItems ?? 5;

Expand Down
16 changes: 6 additions & 10 deletions dart/test/event_processor/enricher/io_enricher_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import 'package:test/test.dart';

import '../../mocks.dart';
import '../../mocks/mock_platform_checker.dart';
import '../../test_utils.dart';

void main() {
group('io_enricher', () {
Expand Down Expand Up @@ -164,20 +165,17 @@ void main() {
});

test('$IoEnricherEventProcessor gets added on init', () async {
final options = SentryOptions(dsn: fakeDsn)..automatedTestMode = true;
late SentryOptions configuredOptions;
final options = defaultTestOptions();
await Sentry.init(
(options) {
options.dsn = fakeDsn;
configuredOptions = options;
},
options: options,
);
await Sentry.close();

final ioEnricherCount = configuredOptions.eventProcessors
.whereType<IoEnricherEventProcessor>()
.length;
final ioEnricherCount =
options.eventProcessors.whereType<IoEnricherEventProcessor>().length;
expect(ioEnricherCount, 1);
});
});
Expand All @@ -188,10 +186,8 @@ class Fixture {
bool hasNativeIntegration = false,
bool includePii = false,
}) {
final options = SentryOptions(
dsn: fakeDsn,
checker:
MockPlatformChecker(hasNativeIntegration: hasNativeIntegration))
final options = defaultTestOptions(
MockPlatformChecker(hasNativeIntegration: hasNativeIntegration))
..sendDefaultPii = includePii;

return IoEnricherEventProcessor(options);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@ library dart_test;

import 'dart:io';

import 'package:sentry/sentry.dart';
import 'package:sentry/src/event_processor/enricher/io_platform_memory.dart';
import 'package:test/test.dart';

import '../../test_utils.dart';

void main() {
late Fixture fixture;

Expand Down Expand Up @@ -52,7 +53,7 @@ void main() {
}

class Fixture {
var options = SentryOptions();
var options = defaultTestOptions();

PlatformMemory getSut() {
return PlatformMemory(options);
Expand Down
6 changes: 3 additions & 3 deletions dart/test/event_processor/enricher/web_enricher_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import 'package:test/test.dart';

import '../../mocks.dart';
import '../../mocks/mock_platform_checker.dart';
import '../../test_utils.dart';

// can be tested on command line with
// `dart test -p chrome --name web_enricher`
Expand Down Expand Up @@ -201,9 +202,8 @@ void main() {

class Fixture {
WebEnricherEventProcessor getSut() {
final options = SentryOptions(
dsn: fakeDsn,
checker: MockPlatformChecker(hasNativeIntegration: false));
final options =
defaultTestOptions(MockPlatformChecker(hasNativeIntegration: false));
return enricherEventProcessor(options) as WebEnricherEventProcessor;
}
}
Loading

0 comments on commit fad381e

Please sign in to comment.