-
Notifications
You must be signed in to change notification settings - Fork 207
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 #403 from bugsnag/init-safety
Prevent Bugsnag.init from instantiating more than one client
- Loading branch information
Showing
5 changed files
with
74 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
Feature: Reporting app version | ||
|
||
Scenario: Test handled Android Exception | ||
When I run "BugsnagInitScenario" | ||
Then I should receive a request | ||
And the request is a valid for the error reporting API | ||
And the event "metaData.client.count" equals 1 |
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
39 changes: 39 additions & 0 deletions
39
.../mazerunner/src/main/java/com/bugsnag/android/mazerunner/scenarios/BugsnagInitScenario.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,39 @@ | ||
package com.bugsnag.android.mazerunner.scenarios | ||
|
||
import android.content.Context | ||
import com.bugsnag.android.Bugsnag | ||
import com.bugsnag.android.Client | ||
import com.bugsnag.android.Configuration | ||
import java.lang.RuntimeException | ||
import java.util.concurrent.Callable | ||
import java.util.concurrent.Executors | ||
|
||
internal class BugsnagInitScenario( | ||
config: Configuration, | ||
context: Context | ||
) : Scenario(config, context) { | ||
|
||
init { | ||
config.setAutoCaptureSessions(false) | ||
} | ||
|
||
override fun run() { | ||
val threadPool = Executors.newFixedThreadPool(8) | ||
val callables = mutableListOf<Callable<Client?>>() | ||
|
||
IntRange(1, 25).forEach { | ||
callables.add(Callable { Bugsnag.init(context) }) | ||
callables.add(Callable { Bugsnag.init(context, config.apiKey) }) | ||
callables.add(Callable { Bugsnag.init(context, config.apiKey, false) }) | ||
callables.add(Callable { Bugsnag.init(context, Configuration(config.apiKey)) }) | ||
} | ||
|
||
val futures = threadPool.invokeAll(callables) | ||
val uniqueClients = futures.map { it.get() }.distinct() | ||
|
||
val bugsnag = uniqueClients.first()!! | ||
bugsnag.addToTab("client", "count", uniqueClients.size) | ||
bugsnag.notify(RuntimeException()) | ||
} | ||
|
||
} |
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