Skip to content

Commit

Permalink
Fix flaky ratpack test (open-telemetry#8733)
Browse files Browse the repository at this point in the history
  • Loading branch information
laurit committed Jun 15, 2023
1 parent 4a0d725 commit 6a8cce2
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 50 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,51 +39,57 @@ class RatpackServerApplicationTest extends Specification {

def "add span on handlers"() {
expect:
app.test { httpClient -> "hi-foo" == httpClient.get("foo").body.text }

new PollingConditions().eventually {
def spanData = app.spanExporter.finishedSpanItems.find { it.name == "GET /foo" }
def attributes = spanData.attributes.asMap()

spanData.kind == SpanKind.SERVER
attributes[HTTP_ROUTE] == "/foo"
attributes[HTTP_TARGET] == "/foo"
attributes[HTTP_METHOD] == "GET"
attributes[HTTP_STATUS_CODE] == 200L
app.test { httpClient ->
assert "hi-foo" == httpClient.get("foo").body.text

new PollingConditions().eventually {
def spanData = app.spanExporter.finishedSpanItems.find { it.name == "GET /foo" }
def attributes = spanData.attributes.asMap()

spanData.kind == SpanKind.SERVER
attributes[HTTP_ROUTE] == "/foo"
attributes[HTTP_TARGET] == "/foo"
attributes[HTTP_METHOD] == "GET"
attributes[HTTP_STATUS_CODE] == 200L
}
}
}

def "propagate trace to http calls"() {
expect:
app.test { httpClient -> "hi-bar" == httpClient.get("bar").body.text }

new PollingConditions().eventually {
def spanData = app.spanExporter.finishedSpanItems.find { it.name == "GET /bar" }
def spanDataClient = app.spanExporter.finishedSpanItems.find { it.name == "GET" }
def attributes = spanData.attributes.asMap()

spanData.traceId == spanDataClient.traceId

spanData.kind == SpanKind.SERVER
attributes[HTTP_ROUTE] == "/bar"
attributes[HTTP_TARGET] == "/bar"
attributes[HTTP_METHOD] == "GET"
attributes[HTTP_STATUS_CODE] == 200L

spanDataClient.kind == SpanKind.CLIENT
def attributesClient = spanDataClient.attributes.asMap()
attributesClient[HTTP_ROUTE] == "/other"
attributesClient[HTTP_METHOD] == "GET"
attributesClient[HTTP_STATUS_CODE] == 200L
app.test { httpClient ->
assert "hi-bar" == httpClient.get("bar").body.text

new PollingConditions().eventually {
def spanData = app.spanExporter.finishedSpanItems.find { it.name == "GET /bar" }
def spanDataClient = app.spanExporter.finishedSpanItems.find { it.name == "GET" }
def attributes = spanData.attributes.asMap()

spanData.traceId == spanDataClient.traceId

spanData.kind == SpanKind.SERVER
attributes[HTTP_ROUTE] == "/bar"
attributes[HTTP_TARGET] == "/bar"
attributes[HTTP_METHOD] == "GET"
attributes[HTTP_STATUS_CODE] == 200L

spanDataClient.kind == SpanKind.CLIENT
def attributesClient = spanDataClient.attributes.asMap()
attributesClient[HTTP_ROUTE] == "/other"
attributesClient[HTTP_METHOD] == "GET"
attributesClient[HTTP_STATUS_CODE] == 200L
}
}
}

def "ignore handlers before OpenTelemetryServerHandler"() {
expect:
app.test { httpClient -> "ignored" == httpClient.get("ignore").body.text }
app.test { httpClient ->
assert "ignored" == httpClient.get("ignore").body.text

new PollingConditions(initialDelay: 0.1, timeout: 0.3).eventually {
!app.spanExporter.finishedSpanItems.any { it.name == "GET /ignore" }
new PollingConditions(initialDelay: 0.1, timeout: 0.3).eventually {
!app.spanExporter.finishedSpanItems.any { it.name == "GET /ignore" }
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,19 +46,20 @@ class RatpackServerTest extends Specification {
}
}

when:
app.test { httpClient -> "hi-foo" == httpClient.get("foo").body.text }

then:
new PollingConditions().eventually {
def spanData = spanExporter.finishedSpanItems.find { it.name == "GET /foo" }
def attributes = spanData.attributes.asMap()

spanData.kind == SpanKind.SERVER
attributes[SemanticAttributes.HTTP_ROUTE] == "/foo"
attributes[SemanticAttributes.HTTP_TARGET] == "/foo"
attributes[SemanticAttributes.HTTP_METHOD] == "GET"
attributes[SemanticAttributes.HTTP_STATUS_CODE] == 200L
expect:
app.test { httpClient ->
assert "hi-foo" == httpClient.get("foo").body.text

new PollingConditions().eventually {
def spanData = spanExporter.finishedSpanItems.find { it.name == "GET /foo" }
def attributes = spanData.attributes.asMap()

spanData.kind == SpanKind.SERVER
attributes[SemanticAttributes.HTTP_ROUTE] == "/foo"
attributes[SemanticAttributes.HTTP_TARGET] == "/foo"
attributes[SemanticAttributes.HTTP_METHOD] == "GET"
attributes[SemanticAttributes.HTTP_STATUS_CODE] == 200L
}
}
}

Expand All @@ -81,7 +82,7 @@ class RatpackServerTest extends Specification {
}

app.test { httpClient ->
"hi-foo" == httpClient.get("foo").body.text
assert "hi-foo" == httpClient.get("foo").body.text

new PollingConditions().eventually {
def spanData = spanExporter.finishedSpanItems.find { it.name == "GET /foo" }
Expand Down Expand Up @@ -130,8 +131,9 @@ class RatpackServerTest extends Specification {
}

app.test { httpClient ->
"hi-foo" == httpClient.get("foo").body.text
"hi-bar" == httpClient.get("bar").body.text
assert "hi-foo" == httpClient.get("foo").body.text
assert "hi-bar" == httpClient.get("bar").body.text

new PollingConditions().eventually {
def spanData = spanExporter.finishedSpanItems.find { it.name == "GET /foo" }
def spanDataChild = spanExporter.finishedSpanItems.find { it.name == "a-span" }
Expand Down

0 comments on commit 6a8cce2

Please sign in to comment.