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

Fix query timeout #124

Merged
merged 3 commits into from
Jun 3, 2023
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
6 changes: 3 additions & 3 deletions fauna/client/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ def _query(
headers[_Header.Authorization] = self._auth.bearer()

if self._query_timeout_ms is not None:
headers[Header.TimeoutMs] = str(self._query_timeout_ms)
headers[Header.QueryTimeoutMs] = str(self._query_timeout_ms)

headers.update(self._last_txn_ts.request_header)

Expand All @@ -274,8 +274,8 @@ def _query(
if opts.traceparent is not None:
headers[Header.Traceparent] = opts.traceparent
if opts.query_timeout is not None:
timeout_ms = f"{opts.query_timeout.total_seconds() * 1000}"
headers[Header.TimeoutMs] = timeout_ms
timeout_ms = f"{int(opts.query_timeout.total_seconds() * 1000)}"
headers[Header.QueryTimeoutMs] = timeout_ms
if opts.query_tags is not None:
query_tags.update(opts.query_tags)
if opts.typecheck is not None:
Expand Down
2 changes: 1 addition & 1 deletion fauna/client/headers.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class Header:
LastTxnTs = "X-Last-Txn-Ts"
Linearized = "X-Linearized"
MaxContentionRetries = "X-Max-Contention-Retries"
TimeoutMs = "X-Timeout-Ms"
QueryTimeoutMs = "X-Query-Timeout-Ms"
Typecheck = "X-Typecheck"
Tags = "X-Query-Tags"
Traceparent = "Traceparent"
Expand Down
7 changes: 1 addition & 6 deletions tests/integration/test_paginate.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,17 +101,12 @@ def test_can_get_pages_using_a_loop_with_next(client, pagination_collections):
assert page_count == 2


@pytest.mark.skip(reason="query_timeout not properly handled yet")
def test_respects_query_options(client, pagination_collections):
_, big_coll = pagination_collections

query_iterator = client.paginate(
fql("${mod}.create({ name: 'Wah' })", mod=big_coll),
QueryOptions(query_timeout=timedelta(milliseconds=1)))

try:
with pytest.raises(QueryTimeoutError):
next(query_iterator.iter())
except QueryTimeoutError:
assert True

assert False
7 changes: 1 addition & 6 deletions tests/integration/test_query.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,12 +128,7 @@ def test_null_doc(client, a_collection):
assert r.data.cause == "not found"


@pytest.mark.skip(reason="query_timeout not properly handled yet")
def test_query_timeout(client, a_collection):
try:
with pytest.raises(QueryTimeoutError):
client.query(fql("${coll}.byId('123')", coll=a_collection),
QueryOptions(query_timeout=timedelta(milliseconds=1)))
except QueryTimeoutError:
assert True

assert False
4 changes: 2 additions & 2 deletions tests/unit/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ def test_query_options_set(httpx_mock: HTTPXMock):

typecheck = True
linearized = True
query_timeout_ms = 5000.0
query_timeout_ms = 5000
traceparent = "happy-little-fox"
max_contention_retries = 5
tags = {
Expand All @@ -135,7 +135,7 @@ def validate_headers(request: httpx.Request):
Validate each of the associated Headers are set on the request
"""
assert request.headers[Header.Linearized] == str(linearized).lower()
assert request.headers[Header.TimeoutMs] == f"{query_timeout_ms}"
assert request.headers[Header.QueryTimeoutMs] == f"{query_timeout_ms}"
assert request.headers[Header.Traceparent] == traceparent
assert request.headers[Header.Typecheck] == str(typecheck).lower()
assert request.headers[Header.MaxContentionRetries] == f"{max_contention_retries}" # yapf: disable
Expand Down