Skip to content

Catch up with TestKit's temporary feature flags + async fix #638

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

Merged
merged 2 commits into from
Jan 5, 2022
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 neo4j/_async/io/_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ async def on_failure(self, metadata):
""" Called when a FAILURE message has been received.
"""
try:
self.connection.reset()
await self.connection.reset()
except (SessionExpired, ServiceUnavailable):
pass
handler = self.handlers.get("on_failure")
Expand Down
7 changes: 1 addition & 6 deletions neo4j/_async/io/_pool.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,12 +152,7 @@ def time_remaining():
# failed to obtain a connection from pool because the
# pool is full and no free connection in the pool
if time_remaining():
await self.cond.wait(time_remaining())
# if timed out, then we throw error. This time
# computation is needed, as with python 2.7, we
# cannot tell if the condition is notified or
# timed out when we come to this line
if not time_remaining():
if not await self.cond.wait(time_remaining()):
raise ClientError("Failed to obtain a connection from pool "
"within {!r}s".format(timeout))
else:
Expand Down
6 changes: 5 additions & 1 deletion neo4j/_async_compat/concurrency.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,11 @@ async def wait(self, timeout=None):
if not timeout:
return await self._wait()
me = asyncio.current_task()
return await asyncio.wait_for(self._wait(me), timeout)
try:
await asyncio.wait_for(self._wait(me), timeout)
return True
except asyncio.TimeoutError:
return False

def notify(self, n=1):
"""By default, wake up one coroutine waiting on this condition, if any.
Expand Down
7 changes: 1 addition & 6 deletions neo4j/_sync/io/_pool.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,12 +152,7 @@ def time_remaining():
# failed to obtain a connection from pool because the
# pool is full and no free connection in the pool
if time_remaining():
self.cond.wait(time_remaining())
# if timed out, then we throw error. This time
# computation is needed, as with python 2.7, we
# cannot tell if the condition is notified or
# timed out when we come to this line
if not time_remaining():
if not self.cond.wait(time_remaining()):
raise ClientError("Failed to obtain a connection from pool "
"within {!r}s".format(timeout))
else:
Expand Down
31 changes: 18 additions & 13 deletions testkitbackend/_async/requests.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,22 +82,27 @@ async def NewDriver(backend, data):
**auth_token.get("parameters", {})
)
auth_token.mark_item_as_read("parameters", recursive=True)
resolver = None
kwargs = {}
if data["resolverRegistered"] or data["domainNameResolverRegistered"]:
resolver = resolution_func(backend, data["resolverRegistered"],
data["domainNameResolverRegistered"])
connection_timeout = data.get("connectionTimeoutMs")
if connection_timeout is not None:
connection_timeout /= 1000
max_transaction_retry_time = data.get("maxTxRetryTimeMs")
if max_transaction_retry_time is not None:
max_transaction_retry_time /= 1000
kwargs["resolver"] = resolution_func(
backend, data["resolverRegistered"],
data["domainNameResolverRegistered"]
)
if data.get("connectionTimeoutMs"):
kwargs["connection_timeout"] = data["connectionTimeoutMs"] / 1000
if data.get("maxTxRetryTimeMs"):
kwargs["max_transaction_retry_time"] = data["maxTxRetryTimeMs"] / 1000
if data.get("connectionAcquisitionTimeoutMs"):
kwargs["connection_acquisition_timeout"] = \
data["connectionAcquisitionTimeoutMs"] / 1000
if data.get("maxConnectionPoolSize"):
kwargs["max_connection_pool_size"] = data["maxConnectionPoolSize"]
if data.get("fetchSize"):
kwargs["fetch_size"] = data["fetchSize"]

data.mark_item_as_read("domainNameResolverRegistered")
driver = neo4j.AsyncGraphDatabase.driver(
data["uri"], auth=auth, user_agent=data["userAgent"],
resolver=resolver, connection_timeout=connection_timeout,
fetch_size=data.get("fetchSize"),
max_transaction_retry_time=max_transaction_retry_time,
data["uri"], auth=auth, user_agent=data["userAgent"], **kwargs
)
key = backend.next_key()
backend.drivers[key] = driver
Expand Down
31 changes: 18 additions & 13 deletions testkitbackend/_sync/requests.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,22 +82,27 @@ def NewDriver(backend, data):
**auth_token.get("parameters", {})
)
auth_token.mark_item_as_read("parameters", recursive=True)
resolver = None
kwargs = {}
if data["resolverRegistered"] or data["domainNameResolverRegistered"]:
resolver = resolution_func(backend, data["resolverRegistered"],
data["domainNameResolverRegistered"])
connection_timeout = data.get("connectionTimeoutMs")
if connection_timeout is not None:
connection_timeout /= 1000
max_transaction_retry_time = data.get("maxTxRetryTimeMs")
if max_transaction_retry_time is not None:
max_transaction_retry_time /= 1000
kwargs["resolver"] = resolution_func(
backend, data["resolverRegistered"],
data["domainNameResolverRegistered"]
)
if data.get("connectionTimeoutMs"):
kwargs["connection_timeout"] = data["connectionTimeoutMs"] / 1000
if data.get("maxTxRetryTimeMs"):
kwargs["max_transaction_retry_time"] = data["maxTxRetryTimeMs"] / 1000
if data.get("connectionAcquisitionTimeoutMs"):
kwargs["connection_acquisition_timeout"] = \
data["connectionAcquisitionTimeoutMs"] / 1000
if data.get("maxConnectionPoolSize"):
kwargs["max_connection_pool_size"] = data["maxConnectionPoolSize"]
if data.get("fetchSize"):
kwargs["fetch_size"] = data["fetchSize"]

data.mark_item_as_read("domainNameResolverRegistered")
driver = neo4j.GraphDatabase.driver(
data["uri"], auth=auth, user_agent=data["userAgent"],
resolver=resolver, connection_timeout=connection_timeout,
fetch_size=data.get("fetchSize"),
max_transaction_retry_time=max_transaction_retry_time,
data["uri"], auth=auth, user_agent=data["userAgent"], **kwargs
)
key = backend.next_key()
backend.drivers[key] = driver
Expand Down
Loading