Skip to content

Commit

Permalink
URL Connection test fixes (#774)
Browse files Browse the repository at this point in the history
Removed callID logic and some other minor fixes
  • Loading branch information
priettt committed Apr 19, 2024
1 parent fd62010 commit 7c4f708
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 17 deletions.
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

0 comments on commit 7c4f708

Please sign in to comment.