Skip to content

Commit

Permalink
Added integration test
Browse files Browse the repository at this point in the history
  • Loading branch information
kevinrenskers committed Nov 14, 2022
1 parent ced88b5 commit 1b40492
Showing 1 changed file with 22 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ class SentryAppStartTrackerTests: NotificationCenterTestCase {
func testSecondStart_AfterSystemReboot_IsColdStart() {
let previousBootTime = fixture.currentDate.date().addingTimeInterval(-1)
let appState = SentryAppState(releaseName: TestData.appState.releaseName, osVersion: UIDevice.current.systemVersion, vendorId: TestData.someUUID, isDebugging: false, systemBootTimestamp: previousBootTime)
givenPreviousAppState(appState: appState)
store(appState: appState)

startApp()

Expand All @@ -84,18 +84,33 @@ class SentryAppStartTrackerTests: NotificationCenterTestCase {

assertValidStart(type: .warm)
}

// Test for situation described in https://github.com/getsentry/sentry-cocoa/issues/2376
func testSecondStart_SystemNotRebooted_OOM_disabled_IsWarmStart() {
givenSystemNotRebooted()

fixture.options.enableOutOfMemoryTracking = false

fixture.fileManager.moveAppStateToPreviousAppState()
startApp()
assertValidStart(type: .warm)

fixture.fileManager.moveAppStateToPreviousAppState()
startApp()
assertValidStart(type: .warm)
}

func testAppUpgrade_IsColdStart() {
let appState = SentryAppState(releaseName: "0.9.0", osVersion: UIDevice.current.systemVersion, vendorId: TestData.someUUID, isDebugging: false, systemBootTimestamp: fixture.currentDate.date())
givenPreviousAppState(appState: appState)
store(appState: appState)

startApp()

assertValidStart(type: .cold)
}

func testAppWasInBackground_NoAppStartUp() {
givenPreviousAppState(appState: TestData.appState)
store(appState: TestData.appState)

startApp()

Expand All @@ -113,7 +128,7 @@ class SentryAppStartTrackerTests: NotificationCenterTestCase {
terminateApp()

let appState = SentryAppState(releaseName: "1.0.0", osVersion: "14.4.1", vendorId: TestData.someUUID, isDebugging: false, systemBootTimestamp: self.fixture.currentDate.date())
givenPreviousAppState(appState: appState)
store(appState: appState)

fixture.fileManager.moveAppStateToPreviousAppState()
startApp()
Expand All @@ -126,7 +141,7 @@ class SentryAppStartTrackerTests: NotificationCenterTestCase {
*/
func testAppLaunches_PreviousBootTimeInFuture_NoAppStartUp() {
let appState = SentryAppState(releaseName: TestData.appState.releaseName, osVersion: UIDevice.current.systemVersion, vendorId: TestData.someUUID, isDebugging: false, systemBootTimestamp: fixture.currentDate.date().addingTimeInterval(1))
givenPreviousAppState(appState: appState)
store(appState: appState)

fixture.fileManager.moveAppStateToPreviousAppState()
startApp()
Expand Down Expand Up @@ -271,15 +286,15 @@ class SentryAppStartTrackerTests: NotificationCenterTestCase {
assertValidHybridStart(type: .warm)
}

private func givenPreviousAppState(appState: SentryAppState) {
private func store(appState: SentryAppState) {
fixture.fileManager.store(appState)
}

private func givenSystemNotRebooted() {
let systemBootTimestamp = fixture.currentDate.date()
fixture.sysctl.setProcessStartTimestamp(value: fixture.currentDate.date())
let appState = SentryAppState(releaseName: TestData.appState.releaseName, osVersion: UIDevice.current.systemVersion, vendorId: TestData.someUUID, isDebugging: false, systemBootTimestamp: systemBootTimestamp)
givenPreviousAppState(appState: appState)
store(appState: appState)
}

private func givenProcessStartTimestamp(processStartTimestamp: Date? = nil) {
Expand Down

0 comments on commit 1b40492

Please sign in to comment.