Skip to content

Commit

Permalink
[WIP] Synapse tests
Browse files Browse the repository at this point in the history
  • Loading branch information
smola committed Dec 20, 2024
1 parent a3e9bda commit dacbf48
Showing 1 changed file with 15 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import org.apache.synapse.ServerConfigurationInformation
import org.apache.synapse.ServerContextInformation
import org.apache.synapse.ServerManager
import org.apache.synapse.transport.passthru.PassThroughHttpListener
import spock.lang.Ignore
import spock.lang.Shared

import java.lang.reflect.Field
Expand Down Expand Up @@ -173,6 +174,7 @@ abstract class SynapseTest extends VersionedNamingTestBase {
statusCode == 200
}

@Ignore("Broken")
def "test error status is captured"() {
setup:
def request = new Request.Builder()
Expand All @@ -198,6 +200,7 @@ abstract class SynapseTest extends VersionedNamingTestBase {
statusCode == 500
}

@Ignore("Unexpected operation name, maybe regressed at https://github.com/DataDog/dd-trace-java/pull/4817")
def "test client request is traced"() {
setup:
def request = new Request.Builder()
Expand All @@ -215,25 +218,28 @@ abstract class SynapseTest extends VersionedNamingTestBase {
int statusCode = client.newCall(request).execute().code()

then:
assertTraces(2, SORT_TRACES_BY_NAMES) {
def expectedServerSpanParent = trace(1)[1]
assertTraces(3, SORT_TRACES_BY_ID) {
def clientTrace = trace(0)
def proxyTrace = trace(1)
trace(1) {
serverSpan(it, 0, 'POST', statusCode, null, expectedServerSpanParent, true)
}
trace(2) {
proxySpan(it, 0, 'POST', statusCode)
clientSpan(it, 1, 'POST', statusCode, span(0))
assert span(1).traceId == expectedServerSpanParent.traceId
}
trace(1) {
proxySpan(it, 0, 'POST', statusCode, clientTrace[0])
}
trace(1) {
serverSpan(it, 0, 'POST', statusCode, null, proxyTrace[0], true)
}
}
statusCode == 200
}

def serverSpan(TraceAssert trace, int index, String method, int statusCode, String query = null, Object parentSpan = null, boolean distributedRootSpan = false, boolean legacyOperationName = false) {
final path = '/services/SimpleStockQuoteService'
trace.span {
serviceName expectedServiceName()
operationName legacyOperationName ? "http.request" : expectedServerOperation()
resourceName "${method} /services/SimpleStockQuoteService"
resourceName "${method} ${path}"
spanType DDSpanTypes.HTTP_SERVER
errored statusCode >= 500
if (parentSpan == null) {
Expand All @@ -247,7 +253,7 @@ abstract class SynapseTest extends VersionedNamingTestBase {
"$Tags.SPAN_KIND" Tags.SPAN_KIND_SERVER
"$Tags.PEER_HOST_IPV4" "127.0.0.1"
"$Tags.PEER_PORT" Integer
"$Tags.HTTP_URL" "/services/SimpleStockQuoteService"
"$Tags.HTTP_URL" (query == null? path : "${path}?${query}")
"$DDTags.HTTP_QUERY" query
"$Tags.HTTP_METHOD" method
"$Tags.HTTP_STATUS" statusCode
Expand Down

0 comments on commit dacbf48

Please sign in to comment.