Skip to content

Commit

Permalink
test: Fix failing UIViewController tests
Browse files Browse the repository at this point in the history
The with GH-3529 added test method writeProfileFile crashed when a
profile file already existed. Now, the writeProfileFile method exists
and prints a debug message when a profiling file already exists and logs
an error when it can't write the profile.
  • Loading branch information
philipphofmann committed Feb 20, 2024
1 parent 01ea580 commit 758ceb9
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions Sources/Sentry/SentryProfiler.mm
Original file line number Diff line number Diff line change
Expand Up @@ -469,15 +469,19 @@ + (nullable SentryEnvelopeItem *)createEnvelopeItemForProfilePayload:
}

if ([fm fileExistsAtPath:pathToWrite]) {
SENTRY_LOG_DEBUG(@"Already a%@ profile file present; make sure to remove them right after "
SENTRY_LOG_DEBUG(@"Already a %@ profile file present; make sure to remove them right after "
@"using them, and that tests clean state in between so there isn't "
@"leftover config producing one when it isn't expected.",
isTracingAppLaunch ? @" launch" : @"");
return;
}

SENTRY_LOG_DEBUG(@"Writing%@ profile to file.", isTracingAppLaunch ? @" launch" : @"");
SENTRY_CASSERT(
[data writeToFile:pathToWrite atomically:YES], @"Failed to write profile to test file");

NSError *error;
if (![data writeToFile:pathToWrite options:NSDataWritingAtomic error:&error]) {
SENTRY_LOG_ERROR(@"Failed to write data to path %@: %@", pathToWrite, error);
}
}
# endif // defined(TEST) || defined(TESTCI) || defined(DEBUG)

Expand Down

0 comments on commit 758ceb9

Please sign in to comment.