diff --git a/features/fixtures/shared/scenarios/LastRunInfoScenario.swift b/features/fixtures/shared/scenarios/LastRunInfoScenario.swift index c511cca43..735bbed14 100644 --- a/features/fixtures/shared/scenarios/LastRunInfoScenario.swift +++ b/features/fixtures/shared/scenarios/LastRunInfoScenario.swift @@ -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( @@ -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) + } + } }