-
Notifications
You must be signed in to change notification settings - Fork 205
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 #319 from bugsnag/android-p-flush-fix
Some unhandled error reports aren't being sent immediately on Android P and in situations with no connectivity. Internally `FileStore` retains a `Collection` of files which have previously been found for a request, to prevent duplicate reports being sent. This puts the onus on the calling code to cancel or delete the files once the request has been completed. This changeset ensures that these files are only requested once when calling `flushOnLaunch`, then cancels all files after delivery has taken place (successfully or not), which resets the `FileStore` state. After this, `flushAsync` is then called, which will flush any remaining reports that have not yet been delivered.
- Loading branch information
Showing
6 changed files
with
120 additions
and
32 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
Feature: All errors are flushed if a startup crash is persisted | ||
|
||
Scenario: 1 startup crash and 1 regular crash persisted | ||
When I configure the app to run in the "CrashOfflineWithDelay" state | ||
And I run "StartupCrashFlushScenario" with the defaults | ||
And I wait for 10 seconds | ||
|
||
And I configure the app to run in the "CrashOfflineAtStartup" state | ||
And I relaunch the app | ||
|
||
And I configure the app to run in the "No crash" state | ||
And I relaunch the app | ||
And I wait for 5 seconds | ||
Then I should receive 2 requests |
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
42 changes: 42 additions & 0 deletions
42
...unner/src/main/java/com/bugsnag/android/mazerunner/scenarios/StartupCrashFlushScenario.kt
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,42 @@ | ||
package com.bugsnag.android.mazerunner.scenarios | ||
|
||
import android.content.Context | ||
import android.os.Handler | ||
import com.bugsnag.android.* | ||
|
||
/** | ||
* Generates an uncaught exception, catches it, and persists it to disc, preventing any delivery. | ||
* | ||
* To generate a startup crash, set "eventMetaData" to "StartupCrash", otherwise the default | ||
* behaviour is to report a normal crash. | ||
* | ||
* The mazerunner scenario that tests this works in 3 parts: | ||
* | ||
* 1. Generate and persist a normal crash on disk, by waiting longer than the threshold for | ||
* a startup crash | ||
* 2. Generate and persist a startup crash on disk, by crashing as soon as the scenario starts | ||
* 3. Send the stored reports. The startup crash should be delivered synchronously on the main thread, | ||
* and the normal crash asynchronously. | ||
*/ | ||
internal class StartupCrashFlushScenario(config: Configuration, | ||
context: Context) : Scenario(config, context) { | ||
|
||
override fun run() { | ||
if ("CrashOfflineWithDelay" == eventMetaData) { | ||
// Part 1 - Persist a regular crash to disk | ||
disableAllDelivery(config) | ||
super.run() | ||
Handler().postDelayed({ | ||
throw RuntimeException("Regular crash") | ||
}, 6000) | ||
} else if ("CrashOfflineAtStartup" == eventMetaData) { | ||
// Part 2 - Persist a startup crash to disk | ||
disableAllDelivery(config) | ||
super.run() | ||
throw RuntimeException("Startup crash") | ||
} else { | ||
// Part 3 - Online, no crashes: send any cached reports | ||
super.run() | ||
} | ||
} | ||
} |
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