Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Menu
Open sidebar
Open Subsurface Data Universe Software
Platform
Domain Data Mgmt Services
Wellbore
Wellbore Domain Services
Commits
540228b7
Commit
540228b7
authored
Jul 09, 2021
by
Alexandre Vincent
Browse files
add test for correlation id trace on client middleware
parent
de736158
Changes
1
Hide whitespace changes
Inline
Side-by-side
tests/unit/middleware/client_test.py
View file @
540228b7
...
...
@@ -3,10 +3,10 @@ from pytest_httpx import HTTPXMock
from
app.clients
import
make_storage_record_client
,
make_search_client
from
app.utils
import
Context
,
get_or_create_ctx
from
tests.unit.test_utils
import
ctx_fixture
,
nope_logger_fixture
from
tests.unit.test_utils
import
ctx_fixture
@
pytest
.
mark
.
asyncio
async
def
test_fwd_correlation_id_to_outgoing_request_to_storage
(
ctx_fixture
,
httpx_mock
:
HTTPXMock
):
async
def
test_fwd_correlation_id_to_outgoing_request_to_storage
(
ctx_fixture
:
Context
,
httpx_mock
:
HTTPXMock
):
storage_url
=
"http://example.com"
# well formed url required
expected_correlation_id
=
'some-correlation-id'
...
...
@@ -16,22 +16,39 @@ async def test_fwd_correlation_id_to_outgoing_request_to_storage(ctx_fixture, ht
ctx
=
ctx_fixture
.
with_correlation_id
(
expected_correlation_id
).
with_auth
(
"foobar"
)
Context
.
set_current
(
ctx
)
# safety: make sure no methods on tracer have been called yet
assert
ctx
.
tracer
.
method_calls
==
[]
# force to use endpoint which does not return a response to skip model validation
response
=
await
storage_client
.
delete_record
(
id
=
"123"
,
data_partition_id
=
"test"
)
assert
response
is
not
None
# make sure correlation-id is traced when doing a request to storage
ctx
.
tracer
.
add_attribute_to_current_span
.
assert_any_call
(
attribute_key
=
'correlation-id'
,
attribute_value
=
expected_correlation_id
)
@
pytest
.
mark
.
asyncio
async
def
test_fwd_correlation_id_to_outgoing_request_to_search
(
httpx_mock
:
HTTPXMock
):
async
def
test_fwd_correlation_id_to_outgoing_request_to_search
(
ctx_fixture
:
Context
,
httpx_mock
:
HTTPXMock
):
storage_url
=
"http://example.com"
# well formed url required
expected_correlation_id
=
'some-correlation-id'
search_client
=
make_search_client
(
storage_url
)
httpx_mock
.
add_response
(
match_headers
=
{
'correlation-id'
:
expected_correlation_id
})
ctx
=
get_or_create_ctx
()
.
with_correlation_id
(
expected_correlation_id
).
with_auth
(
"foobar"
)
ctx
=
ctx_fixture
.
with_correlation_id
(
expected_correlation_id
).
with_auth
(
"foobar"
)
Context
.
set_current
(
ctx
)
# safety: make sure no methods on tracer have been called yet
assert
ctx
.
tracer
.
method_calls
==
[]
# force to use endpoint which does not return a response to skip model validation
response
=
await
search_client
.
delete_index
(
kind
=
"kind"
,
data_partition_id
=
"test"
)
assert
response
is
not
None
# make sure correlation-id is traced when doing a request to search
ctx
.
tracer
.
add_attribute_to_current_span
.
assert_any_call
(
attribute_key
=
'correlation-id'
,
attribute_value
=
expected_correlation_id
)
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment