Skip to content

Commit

Permalink
test: profiler integration test
Browse files Browse the repository at this point in the history
  • Loading branch information
vaind committed Sep 18, 2023
1 parent 5218efa commit 4c8f2bf
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 3 deletions.
64 changes: 64 additions & 0 deletions flutter/example/integration_test/profiling_test.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
import 'dart:convert';

import 'package:flutter_test/flutter_test.dart';
import 'package:sentry_flutter/sentry_flutter.dart';
import '../../../dart/test/mocks/mock_transport.dart';

void main() {
TestWidgetsFlutterBinding.ensureInitialized();

final transport = MockTransport();

setUp(() async {
await SentryFlutter.init((options) {
// ignore: invalid_use_of_internal_member
options.devMode = true;
options.dsn = 'https://abc@def.ingest.sentry.io/1234567';
options.debug = true;
options.transport = transport;
options.tracesSampleRate = 1.0;
options.profilesSampleRate = 1.0;
});
});

tearDown(() async {
await Sentry.close();
transport.reset();
});

test('native binding is initialized', () async {
// ignore: invalid_use_of_internal_member
expect(SentryFlutter.native, isNotNull);
});

test('profile is captured', () async {
final tx = Sentry.startTransaction("name", "op");
await Future.delayed(const Duration(milliseconds: 1000));
await tx.finish();
expect(transport.calls, 1);

final envelope = transport.envelopes.first;
expect(envelope.items.length, 2);
expect(envelope.items[0].header.type, "transaction");
expect(await envelope.items[0].header.length(), greaterThan(0));
expect(envelope.items[1].header.type, "profile");
expect(await envelope.items[1].header.length(), greaterThan(0));

final txJson = utf8.decode(await envelope.items[0].dataFactory());
final txData = json.decode(txJson) as Map<String, dynamic>;

final profileJson = utf8.decode(await envelope.items[1].dataFactory());
final profileData = json.decode(profileJson) as Map<String, dynamic>;

expect(txData["event_id"], isNotNull);
expect(txData["event_id"], profileData["transaction"]["id"]);
expect(txData["contexts"]["trace"]["trace_id"], isNotNull);
expect(txData["contexts"]["trace"]["trace_id"],
profileData["transaction"]["trace_id"]);
expect(profileData["debug_meta"]["images"], isNotEmpty);
expect(profileData["profile"]["thread_metadata"], isNotEmpty);
expect(profileData["profile"]["samples"], isNotEmpty);
expect(profileData["profile"]["stacks"], isNotEmpty);
expect(profileData["profile"]["frames"], isNotEmpty);
});
}
1 change: 1 addition & 0 deletions flutter/example/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ dev_dependencies:
sdk: flutter
flutter_test:
sdk: flutter
test: ^1.21.1

flutter:
uses-material-design: true
Expand Down
3 changes: 0 additions & 3 deletions flutter/lib/src/profiling.dart
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,6 @@ class NativeProfilerFactory implements ProfilerFactory {
return NativeProfiler(_native, startTime, context.traceId, _clock);
}
}

// TODO this may move to the native code in the future - instead of unit-testing,
// do an integration test once https://github.com/getsentry/sentry-dart/issues/1605 is done.
// ignore: invalid_use_of_internal_member
class NativeProfiler implements Profiler {
final SentryNative _native;
Expand Down

0 comments on commit 4c8f2bf

Please sign in to comment.