Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

URL Connection test fixes #774

Merged
merged 1 commit into from
Apr 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
URL Connection test fixes
  • Loading branch information
priettt authored and bidetofevil committed Apr 19, 2024
commit bd9797319b2d27296ecf237678f26afb24a747e6
Original file line number Diff line number Diff line change
Expand Up @@ -572,7 +572,7 @@ synchronized void internalLogNetworkCall(long startTime, long endTime) {
long contentLength = Math.max(0, responseSize.get());

if (inputStreamAccessException == null && lastConnectionAccessException == null && responseCode.get() != 0) {
embrace.recordNetworkRequest(
embrace.getInternalInterface().recordNetworkRequest(
EmbraceNetworkRequest.fromCompletedRequest(
url,
HttpMethod.fromString(getRequestMethod()),
Expand Down Expand Up @@ -602,7 +602,7 @@ synchronized void internalLogNetworkCall(long startTime, long endTime) {
String errorType = exceptionClass != null ? exceptionClass : "UnknownState";
String errorMessage = exceptionMessage != null ? exceptionMessage : "HTTP response state unknown";

embrace.recordNetworkRequest(
embrace.getInternalInterface().recordNetworkRequest(
EmbraceNetworkRequest.fromIncompleteRequest(
url,
HttpMethod.fromString(getRequestMethod()),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ internal class EmbraceUrlConnectionDelegateTest {

private lateinit var mockEmbrace: Embrace
private lateinit var mockInternalInterface: EmbraceInternalInterface
private lateinit var capturedCallId: MutableList<String>
private lateinit var capturedEmbraceNetworkRequest: CapturingSlot<EmbraceNetworkRequest>
private var fakeTimeMs = REQUEST_TIME
private var isSDKStarted = false
Expand All @@ -52,7 +51,6 @@ internal class EmbraceUrlConnectionDelegateTest {
shouldCaptureNetworkBody = true
isNetworkSpanForwardingEnabled = false
traceIdHeaderName = CONFIG_TRACE_ID_HEADER_DEFAULT_VALUE
capturedCallId = mutableListOf()
capturedEmbraceNetworkRequest = slot()
mockInternalInterface = mockk(relaxed = true)
every { mockInternalInterface.shouldCaptureNetworkBody(any(), any()) } answers { shouldCaptureNetworkBody }
Expand Down Expand Up @@ -295,12 +293,12 @@ internal class EmbraceUrlConnectionDelegateTest {
}

@Test
fun `completed network call logged twice with same callId with a wrapped output stream`() {
fun `completed network call logged once with a wrapped output stream`() {
executeRequest(
connection = createMockUncompressedConnection(),
wrappedIoStream = true
)
verifyTwoCallsRecordedWithSameCallId()
verify(exactly = 1) { mockInternalInterface.recordNetworkRequest(any()) }
}

@Test
Expand All @@ -310,7 +308,6 @@ internal class EmbraceUrlConnectionDelegateTest {
wrappedIoStream = false
)
verify(exactly = 1) { mockInternalInterface.recordNetworkRequest(any()) }
assertTrue(capturedCallId[0].isNotBlank())
}

@Test
Expand All @@ -329,7 +326,6 @@ internal class EmbraceUrlConnectionDelegateTest {
EmbraceUrlConnectionDelegate(mockConnection, true, mockEmbrace).disconnect()
verifyIncompleteRequestLogged(mockConnection)
verify(exactly = 1) { mockInternalInterface.recordNetworkRequest(any()) }
assertEquals(1, capturedCallId.size)
}

@Test
Expand All @@ -339,7 +335,7 @@ internal class EmbraceUrlConnectionDelegateTest {

executeRequest(connection = mockConnection, wrappedIoStream = true)
verifyIncompleteRequestLogged(mockConnection = mockConnection, errorType = TIMEOUT_ERROR, noResponseAccess = false)
verifyTwoCallsRecordedWithSameCallId()
verify(exactly = 1) { mockInternalInterface.recordNetworkRequest(any()) }
}

@Test
Expand All @@ -349,7 +345,7 @@ internal class EmbraceUrlConnectionDelegateTest {

executeRequest(connection = mockConnection, wrappedIoStream = true)
verifyIncompleteRequestLogged(mockConnection = mockConnection, errorType = TIMEOUT_ERROR, noResponseAccess = false)
verifyTwoCallsRecordedWithSameCallId()
verify(exactly = 1) { mockInternalInterface.recordNetworkRequest(any()) }
}

@Test
Expand All @@ -359,7 +355,7 @@ internal class EmbraceUrlConnectionDelegateTest {

executeRequest(connection = mockConnection, wrappedIoStream = true)
verifyIncompleteRequestLogged(mockConnection = mockConnection, errorType = TIMEOUT_ERROR, noResponseAccess = false)
verifyTwoCallsRecordedWithSameCallId()
verify(exactly = 1) { mockInternalInterface.recordNetworkRequest(any()) }
}

@Test
Expand Down Expand Up @@ -610,12 +606,6 @@ internal class EmbraceUrlConnectionDelegateTest {
assertEquals(errorType, capturedEmbraceNetworkRequest.captured.errorType)
}

private fun verifyTwoCallsRecordedWithSameCallId() {
verify(exactly = 2) { mockInternalInterface.recordNetworkRequest(any()) }
assertEquals(2, capturedCallId.size)
assertEquals(capturedCallId[0], capturedCallId[1])
}

companion object {
private fun String.toGzipByteArray(): ByteArray {
val outputStream = ByteArrayOutputStream()
Expand Down
Loading