Skip to content

Commit

Permalink
Test fixes attempt #1
Browse files Browse the repository at this point in the history
  • Loading branch information
DZabavchik committed May 7, 2024
1 parent 137d46a commit 15ee8cd
Show file tree
Hide file tree
Showing 8 changed files with 25 additions and 17 deletions.
2 changes: 1 addition & 1 deletion crossbar/router/dealer.py
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ def detach(self, session):
if invoke.timeout_call:
invoke.timeout_call.cancel()
invoke.timeout_call = None

invokes = self._callee_to_invocations[callee]
invokes.remove(invoke)
if not invokes:
Expand Down
3 changes: 2 additions & 1 deletion crossbar/router/session.py
Original file line number Diff line number Diff line change
Expand Up @@ -736,12 +736,13 @@ def onClose(self, wasClean):
self.onLeave(CloseDetails())
except Exception:
self.log.failure("Exception raised in onLeave callback")
self.log.warn("{tb}".format(tb=Failure().getTraceback()))

try:
self._router.detach(self)
except Exception as e:
self.log.error("Failed to detach session '{}': {}".format(self._session_id, e))
self.log.debug("{tb}".format(tb=Failure().getTraceback()))
self.log.warn("{tb}".format(tb=Failure().getTraceback()))

self._session_id = None

Expand Down
7 changes: 7 additions & 0 deletions crossbar/router/test/test_dealer.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,10 +111,17 @@ def test_outstanding_invoke_but_caller_gone(self):
outstanding = mock.Mock()
outstanding.call.request = 1

# there was a bug where timeout calls were not getting cancelled
# mock has non-null timeout_call, so we need to set it to None
outstanding.timeout_call = None
dealer = self.router._dealer
dealer.attach(session)

# All four maps involved in invocation tracking must be updated atomically
dealer._caller_to_invocations[outstanding.caller] = [outstanding]
dealer._callee_to_invocations[session] = [outstanding]
dealer._invocations[outstanding.id] = outstanding
dealer._invocations_by_call[(outstanding.caller_session_id, outstanding.call.request)] = outstanding
# pretend we've disconnected already
outstanding.caller._transport = None

Expand Down
20 changes: 10 additions & 10 deletions crossbar/worker/proxy.py
Original file line number Diff line number Diff line change
Expand Up @@ -634,7 +634,7 @@ def _process_Hello(self, msg):
authmethod=hlval(authmethod),
hello_result=hello_result)

#check if client disconnected while we were yielding to authenticator
# check if client disconnected while we were yielding to authenticator
if not self.transport:
self.log.debug(
'{func} proxy frontend disconnected while processing hello in authenticator:'
Expand All @@ -661,11 +661,11 @@ def _process_Hello(self, msg):
if not self.transport:
# we have not yet established a backend session, only authenticator session was used
self.log.debug('{func} proxy frontend disconnected while connecting backend session'
': session_id={session_id}, session={session}, details="{details}"',
func=hltype(self._process_Hello),
session_id=hlid(self._session_id),
session=self,
details=details)
': session_id={session_id}, session={session}, details="{details}"',
func=hltype(self._process_Hello),
session_id=hlid(self._session_id),
session=self,
details=details)
self._controller.unmap_backend(self, session)
self._backend_session = None
else:
Expand Down Expand Up @@ -744,9 +744,9 @@ def _process_Authenticate(self, msg):
# we have not yet established a backend session, only authenticator session was used
self.log.info('{func} frontend disconnected while processing pending'
' authentication {pending_auth}: {authresult}',
func=hltype(self._process_Authenticate),
pending_auth=self._pending_auth,
authresult=auth_result)
func=hltype(self._process_Authenticate),
pending_auth=self._pending_auth,
authresult=auth_result)
else:
if isinstance(auth_result, types.Accept):
try:
Expand Down Expand Up @@ -1506,6 +1506,7 @@ def stop(self):
topic = '{}.on_proxy_connection_stopped'.format(self._controller._uri_prefix)
yield self._controller.publish(topic, self.marshal(), options=types.PublishOptions(acknowledge=True))


class ProxyController(TransportController):
"""
Controller for proxy workers. Manages:
Expand Down Expand Up @@ -1575,7 +1576,6 @@ def __init__(self, config=None, reactor=None, personality=None):
# map: (realm_name, role_name) -> ProxyRoute
self._service_sessions = {}


def has_realm(self, realm: str) -> bool:
"""
Check if a route to a realm with the given name is currently running.
Expand Down
2 changes: 1 addition & 1 deletion mypy.ini
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[mypy]
python_version = 3.7
python_version = 3.11
disable_error_code = annotation-unchecked

[mypy-crossbar.worker.test.examples.*]
Expand Down
2 changes: 1 addition & 1 deletion requirements-dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ wheel
twine
hashin

pyinstaller==4.2
pyinstaller>=4.2

# FIXME: the docker shit insists on old deps (yaml, jsonschema)
# https://github.com/docker/compose/blob/30fcb72cf3b136598883752edfa6ea4f3b8643d4/setup.py#L27
Expand Down
2 changes: 1 addition & 1 deletion requirements-latest.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ cookiecutter>=2.1.1
cryptography>=39.0.0
docker>=6.0.1
# required for python 3.11+ https://github.com/ethereum/eth-abi/pull/194
eth-abi @ git+https://github.com/ethereum/[email protected]#egg=eth-abi
eth-abi==4.2.1
# required for python 3.11+ (https://github.com/ethereum/eth-account/pull/212)
eth-account @ git+https://github.com/crossbario/eth-account.git@fix-215#egg=eth-account
eth-typing @ git+https://github.com/ethereum/[email protected]#egg=eth-typing
Expand Down
4 changes: 2 additions & 2 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ exclude = crossbar/worker/test/examples/syntaxerror.py
deps =
bandit
commands =
bandit -r -s B101,B110,B311 \
bandit -r -s B101,B110,B311,B113 \
-x crossbar/common/key.py,crossbar/bridge/mqtt/test/test_wamp.py,crossbar/bridge/rest/test/__init__.py,crossbar/bridge/mqtt/test/test_wamp.py,crossbar/webservice/misc.py \
crossbar

Expand All @@ -176,7 +176,7 @@ deps =
commands =
flake8 \
--exclude crossbar/shell/reflection \
--ignore=E501,E402,E722,E741,W503,W504,E126,E251 \
--ignore=E501,E402,E722,E741,W503,W504,E126,E251,E721 \
crossbar


Expand Down

0 comments on commit 15ee8cd

Please sign in to comment.