-
Notifications
You must be signed in to change notification settings - Fork 130
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1176 from bugsnag/nickdowell/app-hang-in-will-ter…
…minate [PLAT-7151] Do not report fatal app hangs if terminating
- Loading branch information
Showing
9 changed files
with
89 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
features/fixtures/shared/scenarios/AppHangInTerminationScenario.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
// | ||
// AppHangInTerminationScenario.swift | ||
// iOSTestApp | ||
// | ||
// Created by Nick Dowell on 25/08/2021. | ||
// Copyright © 2021 Bugsnag. All rights reserved. | ||
// | ||
|
||
#if os(iOS) | ||
import UIKit | ||
#elseif os(macOS) | ||
import AppKit | ||
#endif | ||
|
||
class AppHangInTerminationScenario: Scenario { | ||
|
||
override func startBugsnag() { | ||
config.appHangThresholdMillis = 2_000 | ||
super.startBugsnag() | ||
} | ||
|
||
override func run() { | ||
#if os(iOS) | ||
let willTerminate = UIApplication.willTerminateNotification | ||
#elseif os(macOS) | ||
let willTerminate = NSApplication.willTerminateNotification | ||
#endif | ||
|
||
NotificationCenter.default.addObserver(forName: willTerminate, object: nil, queue: nil) { | ||
NSLog("Received \($0.name.rawValue), simulating an app hang...") | ||
Thread.sleep(forTimeInterval: 3) | ||
} | ||
|
||
#if os(iOS) | ||
// Appium is not able to close apps gracefully, so we simulate this using private API | ||
UIApplication.shared.perform(Selector(("terminateWithSuccess"))) | ||
#elseif os(macOS) | ||
NSApp.terminate(self) | ||
#endif | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters