-
-
Notifications
You must be signed in to change notification settings - Fork 441
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'origin/main' into kw/fix-handling-hybri…
…d-unhandled-exceptions
- Loading branch information
Showing
8 changed files
with
83 additions
and
5 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
70 changes: 70 additions & 0 deletions
70
...ry-android-okhttp/src/test/java/io/sentry/android/okhttp/SentryOkHttpEventListenerTest.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,70 @@ | ||
package io.sentry.android.okhttp | ||
|
||
import io.sentry.IHub | ||
import io.sentry.SentryOptions | ||
import io.sentry.SentryTracer | ||
import io.sentry.TransactionContext | ||
import okhttp3.EventListener | ||
import okhttp3.OkHttpClient | ||
import okhttp3.Request | ||
import okhttp3.mockwebserver.MockResponse | ||
import okhttp3.mockwebserver.MockWebServer | ||
import okhttp3.mockwebserver.SocketPolicy | ||
import org.mockito.kotlin.mock | ||
import org.mockito.kotlin.whenever | ||
import kotlin.test.Test | ||
import kotlin.test.assertEquals | ||
|
||
@SuppressWarnings("Deprecated") | ||
class SentryOkHttpEventListenerTest { | ||
|
||
class Fixture { | ||
val hub = mock<IHub>() | ||
val server = MockWebServer() | ||
lateinit var sentryTracer: SentryTracer | ||
|
||
@SuppressWarnings("LongParameterList") | ||
fun getSut( | ||
eventListener: EventListener? = null | ||
): OkHttpClient { | ||
val options = SentryOptions().apply { | ||
dsn = "https://key@sentry.io/proj" | ||
} | ||
whenever(hub.options).thenReturn(options) | ||
|
||
sentryTracer = SentryTracer(TransactionContext("name", "op"), hub) | ||
whenever(hub.span).thenReturn(sentryTracer) | ||
server.enqueue( | ||
MockResponse() | ||
.setBody("responseBody") | ||
.setSocketPolicy(SocketPolicy.KEEP_OPEN) | ||
.setResponseCode(200) | ||
) | ||
|
||
val builder = OkHttpClient.Builder().addInterceptor(SentryOkHttpInterceptor(hub)) | ||
val sentryOkHttpEventListener = when { | ||
eventListener != null -> SentryOkHttpEventListener(hub, eventListener) | ||
else -> SentryOkHttpEventListener(hub) | ||
} | ||
return builder.eventListener(sentryOkHttpEventListener).build() | ||
} | ||
} | ||
|
||
private val fixture = Fixture() | ||
|
||
private fun getRequest(url: String = "/hello"): Request { | ||
return Request.Builder() | ||
.addHeader("myHeader", "myValue") | ||
.get() | ||
.url(fixture.server.url(url)) | ||
.build() | ||
} | ||
|
||
@Test | ||
fun `when there are multiple SentryOkHttpEventListeners, they don't duplicate spans`() { | ||
val sut = fixture.getSut(eventListener = SentryOkHttpEventListener(fixture.hub)) | ||
val call = sut.newCall(getRequest()) | ||
call.execute().close() | ||
assertEquals(8, fixture.sentryTracer.children.size) | ||
} | ||
} |
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