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

Encode Query timeout header correctly #127

Merged
merged 3 commits into from
Jun 29, 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
2 changes: 1 addition & 1 deletion .github/workflows/yapf.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ jobs:
cache: pip

- name: Install yapf
run: pip install yapf
run: pip install yapf==0.40.1

- name: Check Format
run: |
Expand Down
2 changes: 1 addition & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ If you want to run fauna, then run integration tests separately:

.. code-block:: bash
$ make docker-fauna
$ make run-fauna
$ source venv/bin/activate
$ make install
$ make integration-test
Expand Down
2 changes: 1 addition & 1 deletion fauna/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
__title__ = "Fauna"
__version__ = "0.7.0"
__version__ = "0.7.1"
__api_version__ = "10"
__author__ = "Fauna, Inc"
__license__ = "MPL 2.0"
Expand Down
2 changes: 1 addition & 1 deletion fauna/client/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ def __init__(
self._query_tags.update(query_tags)

if query_timeout is not None:
self._query_timeout_ms = query_timeout.total_seconds() * 1000
self._query_timeout_ms = int(query_timeout.total_seconds() * 1000)
else:
self._query_timeout_ms = None

Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
]

extras_require = {
"lint": ["yapf==0.32.0"],
"lint": ["yapf==0.40.1"],
"test": [
"pytest==7.3.0", "pytest-env==0.8.1", "pytest-cov==4.0.0",
"pytest-httpx==0.21.3", "pytest-subtests==0.10.0"
Expand Down
10 changes: 10 additions & 0 deletions tests/integration/test_client.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
from datetime import timedelta
import pytest
from fauna.client.client import QueryOptions

from fauna.errors import ClientError

Expand Down Expand Up @@ -27,3 +29,11 @@ def test_handle_invalid_json_response():
with pytest.raises(ClientError, match=err_msg):
c = Client(endpoint="https://dashboard.fauna.com/")
c.query(fql("'foolery'"))


def test_fauna_accepts_query_timeout_header():
c1 = Client(query_timeout=timedelta(seconds=5))
c1.query(fql('"hello"'))

c2 = Client()
c2.query(fql('"hello"'), QueryOptions(query_timeout=timedelta(seconds=5)))
11 changes: 8 additions & 3 deletions tests/integration/test_query.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,23 +27,28 @@ def test_query_smoke_test(subtests, client):

def test_query_with_all_stats(client, a_collection):
res = client.query(fql("${col}.create({})", col=a_collection))
doc_id = res.data.id
res = client.query(
fql("${col}.create({})\n${col}.byId(${id})",
col=a_collection,
id=doc_id))
assert res.stats.compute_ops > 0
assert res.stats.read_ops > 0
assert res.stats.write_ops > 0
assert res.stats.storage_bytes_read > 0
assert res.stats.storage_bytes_write > 0
assert res.stats.query_time_ms > 0
assert res.stats.contention_retries >= 0
assert res.stats.contention_retries == 0


def test_query_with_constraint_failure(client):
with pytest.raises(QueryRuntimeError) as e:
client.query(
fql('Function.create({"name": "double", "body": "x => x * 2"})'))
fql('Function.create({"name": "false", "body": "_ => false"})'))

assert e.value.constraint_failures == [
ConstraintFailure(
message="The identifier `double` is reserved.",
message="The identifier `false` is reserved.",
name=None,
paths=[["name"]],
),
Expand Down