Skip to content

Commit

Permalink
Fix test flake in in LastRunInfoScenario (#1345)
Browse files Browse the repository at this point in the history
  • Loading branch information
nickdowell committed Apr 25, 2022
1 parent 4c24847 commit fe25e21
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions features/fixtures/shared/scenarios/LastRunInfoScenario.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ class LastRunInfoScenario: Scenario {

override func startBugsnag() {
config.launchDurationMillis = 0
config.sendLaunchCrashesSynchronously = false
config.addOnSendError {
if let lastRunInfo = Bugsnag.lastRunInfo {
$0.addMetadata(
Expand All @@ -24,9 +25,29 @@ class LastRunInfoScenario: Scenario {
}

override func run() {
// Ensure we don't crash the fixture while the previous run's launch crash is being sent.
// Don't rely on synchronous launch crash sending because that will only wait up to 2
// seconds, and delivery occasionally takes longer than that on BrowserStack devices.
waitForDelivery();

if Bugsnag.lastRunInfo?.consecutiveLaunchCrashes == 3 {
Bugsnag.markLaunchCompleted()
}

fatalError("Oh no, the app crashed!")
}

func waitForDelivery() {
let dir = FileManager.default.urls(for: .applicationSupportDirectory, in: .userDomainMask)[0]
.appendingPathComponent("com.bugsnag.Bugsnag")
.appendingPathComponent(Bundle.main.bundleIdentifier!)
.appendingPathComponent("v1")
.appendingPathComponent("KSCrashReports")

while try! !FileManager.default.contentsOfDirectory(at: dir, includingPropertiesForKeys: nil, options: [])
.filter({ $0.lastPathComponent.hasPrefix("CrashReport-") }).isEmpty {
NSLog("LastRunInfoScenario: waiting for delivery of crash reports...")
Thread.sleep(forTimeInterval: 0.1)
}
}
}

0 comments on commit fe25e21

Please sign in to comment.