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

Fix flaky app start test #2157

Merged
merged 1 commit into from
Jul 11, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 18 additions & 17 deletions flutter/test/integrations/native_app_start_integration_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,15 @@ void main() {
.thenAnswer((_) async => SentryId.empty());
}

Future<void> registerIntegration(Fixture fixture) async {
await fixture.registerIntegration();
// Wait for the app start info to be fetched
// This ensures that setAppStartInfo has been called, which happens asynchronously
// in a post-frame callback. Waiting here prevents race conditions in subsequent tests
// that might depend on or modify the app start info.
await NativeAppStartIntegration.getAppStartInfo();
}

group('$NativeAppStartIntegration', () {
late Fixture fixture;

Expand All @@ -44,8 +53,7 @@ void main() {
NativeAppStartIntegration.appStartEnd =
DateTime.fromMillisecondsSinceEpoch(10);

await fixture.registerIntegration();

await registerIntegration(fixture);
final tracer = fixture.createTracer();
final transaction = SentryTransaction(tracer);

Expand All @@ -63,8 +71,7 @@ void main() {
NativeAppStartIntegration.appStartEnd =
DateTime.fromMillisecondsSinceEpoch(10);

await fixture.registerIntegration();

await registerIntegration(fixture);
final tracer = fixture.createTracer();
final transaction = SentryTransaction(tracer);

Expand All @@ -83,8 +90,7 @@ void main() {
DateTime.fromMillisecondsSinceEpoch(10);
final measurement = SentryMeasurement.warmAppStart(Duration(seconds: 1));

await fixture.registerIntegration();

await registerIntegration(fixture);
final tracer = fixture.createTracer();
final transaction = SentryTransaction(tracer).copyWith();
transaction.measurements[measurement.name] = measurement;
Expand All @@ -104,8 +110,7 @@ void main() {
NativeAppStartIntegration.appStartEnd =
DateTime.fromMillisecondsSinceEpoch(60001);

await fixture.registerIntegration();

await registerIntegration(fixture);
final tracer = fixture.createTracer();
final transaction = SentryTransaction(tracer);

Expand All @@ -121,8 +126,7 @@ void main() {
NativeAppStartIntegration.appStartEnd =
DateTime.fromMillisecondsSinceEpoch(10);

await fixture.registerIntegration();

await registerIntegration(fixture);
final appStartInfo = await NativeAppStartIntegration.getAppStartInfo();
expect(appStartInfo?.start, DateTime.fromMillisecondsSinceEpoch(0));
expect(appStartInfo?.end, DateTime.fromMillisecondsSinceEpoch(10));
Expand All @@ -133,7 +137,7 @@ void main() {
() async {
fixture.options.autoAppStart = false;

await fixture.registerIntegration();
await registerIntegration(fixture);

final tracer = fixture.createTracer();
final transaction = SentryTransaction(tracer);
Expand All @@ -155,8 +159,7 @@ void main() {
const Duration(seconds: 5));
fixture.options.autoAppStart = false;

await fixture.registerIntegration();

await registerIntegration(fixture);
final tracer = fixture.createTracer();
final transaction = SentryTransaction(tracer);

Expand All @@ -175,8 +178,7 @@ void main() {
() async {
fixture.options.autoAppStart = false;

await fixture.registerIntegration();

await registerIntegration(fixture);
SentryFlutter.setAppStartEnd(DateTime.fromMillisecondsSinceEpoch(10));

final tracer = fixture.createTracer();
Expand Down Expand Up @@ -272,8 +274,7 @@ void main() {
when(fixture.binding.fetchNativeAppStart())
.thenAnswer((_) async => appStartInfoSrc);

await fixture.registerIntegration();

await registerIntegration(fixture);
final processor = fixture.options.eventProcessors.first;
tracer = fixture.createTracer();
final transaction = SentryTransaction(tracer);
Expand Down
Loading