-
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 #1014 from bugsnag/nickdowell/fix-app-duration
[PLAT-6134] Fix inaccurate app.duration values
- Loading branch information
Showing
10 changed files
with
78 additions
and
12 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
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
37 changes: 37 additions & 0 deletions
37
features/fixtures/shared/scenarios/AppDurationScenario.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,37 @@ | ||
// | ||
// AppDurationScenario.swift | ||
// macOSTestApp | ||
// | ||
// Created by Nick Dowell on 26/02/2021. | ||
// Copyright © 2021 Bugsnag Inc. All rights reserved. | ||
// | ||
|
||
import Bugsnag | ||
|
||
class AppDurationScenario: Scenario { | ||
|
||
var startDate: Date! | ||
var startTime: DispatchTime! | ||
|
||
override func startBugsnag() { | ||
config.autoTrackSessions = false | ||
config.sendThreads = .never | ||
startDate = Date() | ||
startTime = .now() | ||
super.startBugsnag() | ||
} | ||
|
||
override func run() { | ||
DispatchQueue(label: "AppDurationScenario").async { | ||
// If the events are too close together, they will not be sent in the correct order. | ||
// This is because -[BugsnagFileStore allFilesByName] returns files in a random order. | ||
// The 1 second delay in -[BugsnagApiClient flushPendingData] means the spacing needs | ||
// to be quite large in order to get correct ordering of events. | ||
for delay in [0.0, 2.7, 5.5] { | ||
// DispatchQueue.asyncAfter was found to be too inaccurate for this scenario | ||
Thread.sleep(until: self.startDate.addingTimeInterval(delay)) | ||
Bugsnag.notifyError(NSError(domain: "AppDurationScenario", code: Int(delay * 1000.0))) | ||
} | ||
} | ||
} | ||
} |
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