Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: rethrow exceptions #2290

Merged
merged 12 commits into from
Sep 16, 2024
Merged
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,9 @@
exception: exception,
stackTrace: stackTrace,
);
if (_options.automatedTestMode) {

Check warning on line 103 in dart/lib/src/event_processor/enricher/io_enricher_event_processor.dart

View check run for this annotation

Codecov / codecov/patch

dart/lib/src/event_processor/enricher/io_enricher_event_processor.dart#L103

Added line #L103 was not covered by tests
rethrow;
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,9 @@
}
} catch (e) {
options.logger(SentryLevel.warning, "Failed to run process: $e");
if (options.automatedTestMode) {

Check warning on line 78 in dart/lib/src/event_processor/enricher/io_platform_memory.dart

View check run for this annotation

Codecov / codecov/patch

dart/lib/src/event_processor/enricher/io_platform_memory.dart#L78

Added line #L78 was not covered by tests
rethrow;
}
}
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,9 @@
exception: exception,
stackTrace: stackTrace,
);
if (_options.automatedTestMode) {

Check warning on line 72 in dart/lib/src/event_processor/exception/io_exception_event_processor.dart

View check run for this annotation

Codecov / codecov/patch

dart/lib/src/event_processor/exception/io_exception_event_processor.dart#L72

Added line #L72 was not covered by tests
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 @@
exception: exception,
stackTrace: stackTrace,
);
if (_options.automatedTestMode) {

Check warning on line 127 in dart/lib/src/hub.dart

View check run for this annotation

Codecov / codecov/patch

dart/lib/src/hub.dart#L127

Added line #L127 was not covered by tests
rethrow;
}
} finally {
_lastEventId = sentryId;
}
Expand Down Expand Up @@ -183,6 +186,9 @@
exception: exception,
stackTrace: stackTrace,
);
if (_options.automatedTestMode) {

Check warning on line 189 in dart/lib/src/hub.dart

View check run for this annotation

Codecov / codecov/patch

dart/lib/src/hub.dart#L189

Added line #L189 was not covered by tests
rethrow;
}
} finally {
_lastEventId = sentryId;
}
Expand Down Expand Up @@ -238,6 +244,9 @@
exception: exception,
stackTrace: stackTrace,
);
if (_options.automatedTestMode) {

Check warning on line 247 in dart/lib/src/hub.dart

View check run for this annotation

Codecov / codecov/patch

dart/lib/src/hub.dart#L247

Added line #L247 was not covered by tests
rethrow;
}
} finally {
_lastEventId = sentryId;
}
Expand Down Expand Up @@ -271,6 +280,9 @@
exception: exception,
stackTrace: stacktrace,
);
if (_options.automatedTestMode) {
rethrow;
}
}
}

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

Check warning on line 379 in dart/lib/src/hub.dart

View check run for this annotation

Codecov / codecov/patch

dart/lib/src/hub.dart#L379

Added line #L379 was not covered by tests
rethrow;
}
}

_isEnabled = false;
Expand Down Expand Up @@ -565,6 +580,9 @@
exception: exception,
stackTrace: stackTrace,
);
if (_options.automatedTestMode) {

Check warning on line 583 in dart/lib/src/hub.dart

View check run for this annotation

Codecov / codecov/patch

dart/lib/src/hub.dart#L583

Added line #L583 was not covered by tests
rethrow;
}
}
}
}
Expand Down Expand Up @@ -602,6 +620,9 @@
exception: exception,
stackTrace: stackTrace,
);
if (_options.automatedTestMode) {

Check warning on line 623 in dart/lib/src/hub.dart

View check run for this annotation

Codecov / codecov/patch

dart/lib/src/hub.dart#L623

Added line #L623 was not covered by tests
rethrow;
}
}
}
return sentryId;
Expand Down Expand Up @@ -682,6 +703,9 @@
exception: exception,
stackTrace: stackTrace,
);
if (_options.automatedTestMode) {

Check warning on line 706 in dart/lib/src/hub.dart

View check run for this annotation

Codecov / codecov/patch

dart/lib/src/hub.dart#L706

Added line #L706 was not covered by tests
rethrow;
}
}
}

Expand All @@ -699,6 +723,9 @@
exception: exception,
stackTrace: stackTrace,
);
if (_options.automatedTestMode) {

Check warning on line 726 in dart/lib/src/hub.dart

View check run for this annotation

Codecov / codecov/patch

dart/lib/src/hub.dart#L726

Added line #L726 was not covered by tests
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 @@
exception: e,
stackTrace: stackTrace,
);
if (_options.automatedTestMode) {

Check warning on line 45 in dart/lib/src/load_dart_debug_images_integration.dart

View check run for this annotation

Codecov / codecov/patch

dart/lib/src/load_dart_debug_images_integration.dart#L45

Added line #L45 was not covered by tests
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 @@
return eventId != null ? SentryId.fromId(eventId) : null;
} catch (e) {
_options.logger(SentryLevel.error, 'Error parsing response: $e');
if (_options.automatedTestMode) {

Check warning on line 67 in dart/lib/src/transport/http_transport.dart

View check run for this annotation

Codecov / codecov/patch

dart/lib/src/transport/http_transport.dart#L67

Added line #L67 was not covered by tests
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 @@
} catch (e) {
_options.logger(
SentryLevel.warning, 'Failed to send envelope to Spotlight: $e');
if (_options.automatedTestMode) {

Check warning on line 34 in dart/lib/src/transport/spotlight_http_transport.dart

View check run for this annotation

Codecov / codecov/patch

dart/lib/src/transport/spotlight_http_transport.dart#L34

Added line #L34 was not covered by tests
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://[email protected]/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
Loading