-
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.
* feat(ExitInfo): ExitInfo setOnEventStoreEmptyCallback * feat(ExitInfo): ExitInfo setOnEventStoreEmptyCallback * refactor(EventStore): reworked the EventStore callback to only be called once, and only when the store is completely empty (no files in queue or in storage) * feat(ExitInfo): Track exitinfokey with event * feat(ExitInfo): ExitInfo setOnEventStoreEmptyCallback --------- Co-authored-by: jason <[email protected]>
- Loading branch information
1 parent
394f7d8
commit ee15c62
Showing
12 changed files
with
224 additions
and
10 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
156 changes: 156 additions & 0 deletions
156
bugsnag-android-core/src/test/java/com/bugsnag/android/EmptyEventCallbackTest.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,156 @@ | ||
package com.bugsnag.android | ||
|
||
import com.bugsnag.android.BugsnagTestUtils.generateConfiguration | ||
import com.bugsnag.android.BugsnagTestUtils.generateEvent | ||
import com.bugsnag.android.FileStore.Delegate | ||
import com.bugsnag.android.internal.BackgroundTaskService | ||
import com.bugsnag.android.internal.ImmutableConfig | ||
import com.bugsnag.android.internal.convertToImmutableConfig | ||
import org.junit.After | ||
import org.junit.Assert.assertEquals | ||
import org.junit.Assert.assertFalse | ||
import org.junit.Assert.assertTrue | ||
import org.junit.Before | ||
import org.junit.Test | ||
import org.mockito.ArgumentMatchers.any | ||
import org.mockito.Mockito.mock | ||
import org.mockito.Mockito.`when` | ||
import java.io.File | ||
import java.nio.file.Files | ||
import java.util.concurrent.CountDownLatch | ||
|
||
class EmptyEventCallbackTest { | ||
|
||
private lateinit var storageDir: File | ||
private lateinit var errorDir: File | ||
private lateinit var backgroundTaskService: BackgroundTaskService | ||
|
||
@Before | ||
fun setUp() { | ||
storageDir = Files.createTempDirectory("tmp").toFile() | ||
storageDir.deleteRecursively() | ||
errorDir = File(storageDir, "bugsnag/errors") | ||
backgroundTaskService = BackgroundTaskService() | ||
} | ||
|
||
@After | ||
fun tearDown() { | ||
storageDir.deleteRecursively() | ||
backgroundTaskService.shutdown() | ||
} | ||
|
||
@Test | ||
fun emptyQueuedEventTriggerEventStoreEmptyCallback() { | ||
val config = generateConfiguration().apply { | ||
maxPersistedEvents = 0 | ||
persistenceDirectory = storageDir | ||
} | ||
val eventStore = createEventStore(convertToImmutableConfig(config)) | ||
eventStore.write(generateEvent()) | ||
|
||
val callbackLatch = CountDownLatch(1) | ||
eventStore.onEventStoreEmptyCallback = { callbackLatch.countDown() } | ||
eventStore.flushAsync() | ||
callbackLatch.await() | ||
|
||
assertTrue(eventStore.isEmpty()) | ||
} | ||
|
||
@Test | ||
fun testFailedDeliveryEvents() { | ||
val mockDelivery = mock(Delivery::class.java) | ||
`when`(mockDelivery.deliver(any<EventPayload>(), any<DeliveryParams>())) | ||
.thenReturn( | ||
DeliveryStatus.DELIVERED, | ||
DeliveryStatus.FAILURE | ||
) | ||
|
||
val config = generateConfiguration().apply { | ||
maxPersistedEvents = 3 | ||
persistenceDirectory = storageDir | ||
delivery = mockDelivery | ||
} | ||
val eventStore = createEventStore(convertToImmutableConfig(config)) | ||
repeat(3) { | ||
eventStore.write(generateEvent()) | ||
} | ||
|
||
// the EventStore should not be considered empty with 3 events in it | ||
assertFalse(eventStore.isEmpty()) | ||
|
||
var eventStoreEmptyCount = 0 | ||
eventStore.onEventStoreEmptyCallback = { eventStoreEmptyCount++ } | ||
eventStore.flushAsync() | ||
backgroundTaskService.shutdown() | ||
|
||
assertTrue( | ||
"there should be no undelivered payloads in the EventStore", | ||
eventStore.isEmpty() | ||
) | ||
|
||
assertEquals( | ||
"onEventStoreEmptyCallback have been called even with a failed (deleted) payload", | ||
1, | ||
eventStoreEmptyCount | ||
) | ||
} | ||
|
||
@Test | ||
fun testUndeliveredEvents() { | ||
val mockDelivery = mock(Delivery::class.java) | ||
`when`(mockDelivery.deliver(any<EventPayload>(), any<DeliveryParams>())) | ||
.thenReturn( | ||
DeliveryStatus.DELIVERED, | ||
DeliveryStatus.FAILURE, | ||
DeliveryStatus.UNDELIVERED | ||
) | ||
|
||
val config = generateConfiguration().apply { | ||
maxPersistedEvents = 3 | ||
persistenceDirectory = storageDir | ||
delivery = mockDelivery | ||
} | ||
val eventStore = createEventStore(convertToImmutableConfig(config)) | ||
repeat(3) { | ||
eventStore.write(generateEvent()) | ||
} | ||
|
||
// the EventStore should not be considered empty with 3 events in it | ||
assertFalse(eventStore.isEmpty()) | ||
|
||
var eventStoreEmptyCount = 0 | ||
eventStore.onEventStoreEmptyCallback = { eventStoreEmptyCount++ } | ||
eventStore.flushAsync() | ||
backgroundTaskService.shutdown() | ||
|
||
// the last payload should not have been delivered | ||
assertFalse( | ||
"there should be one undelivered payload in the EventStore", | ||
eventStore.isEmpty() | ||
) | ||
|
||
assertEquals( | ||
"onEventStoreEmptyCallback should not be called when there are undelivered payloads", | ||
0, | ||
eventStoreEmptyCount | ||
) | ||
} | ||
|
||
private fun createEventStore(config: ImmutableConfig): EventStore { | ||
return EventStore( | ||
config, | ||
NoopLogger, | ||
Notifier(), | ||
backgroundTaskService, | ||
object : Delegate { | ||
override fun onErrorIOFailure( | ||
exception: Exception?, | ||
errorFile: File?, | ||
context: String? | ||
) { | ||
} | ||
}, | ||
CallbackState() | ||
) | ||
} | ||
} |
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
13 changes: 13 additions & 0 deletions
13
bugsnag-plugin-android-exitinfo/src/main/java/com/bugsnag/android/InternalHooks.java
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,13 @@ | ||
package com.bugsnag.android; | ||
|
||
import kotlin.Unit; | ||
import kotlin.jvm.functions.Function0; | ||
|
||
class InternalHooks { | ||
|
||
private InternalHooks() {} | ||
|
||
public static void setEventStoreEmptyCallback(Client client, Function0<Unit> callback) { | ||
client.eventStore.setOnEventStoreEmptyCallback(callback); | ||
} | ||
} |
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