Skip to content

Commit

Permalink
Work 0506 (#1562)
Browse files Browse the repository at this point in the history
* add websocket_options to ApplicationRunner; add automatic immediate reconnect feature
* initial federated realms support, various smaller improvements (see changelog)
* bump dev version; update changelog
* fixes #1561
* add more tests
  • Loading branch information
oberstet committed May 9, 2022
1 parent 299a656 commit 5a50788
Show file tree
Hide file tree
Showing 25 changed files with 891 additions and 209 deletions.
21 changes: 20 additions & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,12 @@ on:

jobs:
check:
env:
WEB3_INFURA_PROJECT_ID: "1c91697c211f4fcd8c7361f4c4e1f55f"
# not sure why, but this doesn't work currently:
# WEB3_INFURA_PROJECT_ID: ${{ secrets.WEB3_INFURA_PROJECT_ID }}
# WEB3_INFURA_API_SECRET: ${{ secrets.WEB3_INFURA_API_SECRET }}

runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v2
Expand Down Expand Up @@ -53,6 +59,11 @@ jobs:
env:
CB_FULLTESTS: 1

WEB3_INFURA_PROJECT_ID: "1c91697c211f4fcd8c7361f4c4e1f55f"
# not sure why, but this doesn't work currently:
# WEB3_INFURA_PROJECT_ID: ${{ secrets.WEB3_INFURA_PROJECT_ID }}
# WEB3_INFURA_API_SECRET: ${{ secrets.WEB3_INFURA_API_SECRET }}

# Test on Ubuntu, MacOS, Windows using CPython and PyPy
runs-on: ${{ matrix.os }}
strategy:
Expand Down Expand Up @@ -101,11 +112,19 @@ jobs:
run: |
pip install .[all]
- name: Run unit tests (PyTest)
- name: Prechecks
run: |
python -c "import autobahn; print(autobahn.__version__)"
python -c "from autobahn import xbr; print(xbr.HAS_XBR)"
python -c "from autobahn.testutil import FakeTransport; print(FakeTransport)"
python -c "import os; print('WEB3_INFURA_PROJECT_ID', len(os.environ.get('WEB3_INFURA_PROJECT_ID', '')))"
python -c "import os; print('WEB3_INFURA_API_SECRET', len(os.environ.get('WEB3_INFURA_API_SECRET', '')))"
# does not work on py3.10
# python -c "from web3.auto.infura import w3; print(w3.isConnected())"

- name: Run unit tests (PyTest)
run: |
tox -c tox.ini -e ${{ matrix.framework }}
docs:
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,5 @@ autobahn/xbr/contracts
.wheels
get-pip.py
docs/autoapi/
key.pub
key.priv
17 changes: 17 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,12 @@ upload_exe:
aws cloudfront create-invalidation \
--distribution-id E2QIG9LNGCJSP9 --paths "/xbrnetwork/linux-amd64/*"

# WEB3_INFURA_PROJECT_ID must be defined for this
test_infura:
time -f "%e" python -c "from web3.auto.infura import w3; print(w3.isConnected())"

test_xbr:
USE_TWISTED=1 trial autobahn.xbr

test_xbr_cli:
xbrnetwork
Expand Down Expand Up @@ -178,6 +184,9 @@ test_rng:
test_serializer:
USE_TWISTED=1 trial autobahn.wamp.test.test_wamp_serializer

test_wamp_identifiers:
USE_TWISTED=1 trial autobahn.wamp.test.test_wamp_identifiers

test_tx_cryptobox:
USE_TWISTED=1 trial autobahn.wamp.test.test_cryptobox

Expand All @@ -189,6 +198,14 @@ test_cryptosign:
USE_ASYNCIO=1 pytest -s -v -rfA --ignore=./autobahn/twisted autobahn/wamp/test/test_wamp_cryptosign.py
USE_TWISTED=1 trial autobahn.wamp.test.test_wamp_cryptosign

test_xbr_web3:
# pytest -s -v -rfA autobahn/xbr/test/test_xbr_web3.py
trial autobahn/xbr/test/test_xbr_web3.py

test_xbr_frealm:
# pytest -s -v -rfA autobahn/xbr/test/test_xbr_frealm.py
trial autobahn/xbr/test/test_xbr_frealm.py

test_wamp_scram:
USE_ASYNCIO=1 trial autobahn.wamp.test.test_wamp_scram
USE_TWISTED=1 trial autobahn.wamp.test.test_wamp_scram
Expand Down
2 changes: 1 addition & 1 deletion autobahn/_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,6 @@
#
###############################################################################

__version__ = '22.4.2'
__version__ = '22.5.1.dev1'

__build__ = '00000000-0000000'
25 changes: 14 additions & 11 deletions autobahn/twisted/component.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@


from functools import wraps
from typing import List

from twisted.internet.interfaces import IStreamClientEndpoint
from twisted.internet.endpoints import UNIXClientEndpoint
Expand Down Expand Up @@ -334,7 +335,7 @@ def start(self, reactor=None):
return self._start(loop=reactor)


def run(components, log_level='info'):
def run(components: List[Component], log_level: str = 'info', stop_at_close: bool = True):
"""
High-level API to run a series of components.
Expand All @@ -347,10 +348,8 @@ def run(components, log_level='info'):
each component yourself.
:param components: the Component(s) you wish to run
:type components: instance or list of :class:`autobahn.twisted.component.Component`
:param log_level: a valid log-level (or None to avoid calling start_logging)
:type log_level: string
:param stop_at_close: Flag to control whether to stop the reactor when done.
"""
# only for Twisted > 12
# ...so this isn't in all Twisted versions we test against -- need
Expand All @@ -366,12 +365,16 @@ def run(components, log_level='info'):

log = txaio.make_logger()

def done_callback(reactor, arg):
if isinstance(arg, Failure):
log.error("Something went wrong: {log_failure}", failure=arg)
try:
reactor.stop()
except ReactorNotRunning:
pass
if stop_at_close:
def done_callback(reactor, arg):
if isinstance(arg, Failure):
log.error('Something went wrong: {log_failure}', failure=arg)
try:
log.warn('Stopping reactor ..')
reactor.stop()
except ReactorNotRunning:
pass
else:
done_callback = None

react(component._run, (components, done_callback))
2 changes: 1 addition & 1 deletion autobahn/twisted/test/test_tx_component.py
Original file line number Diff line number Diff line change
Expand Up @@ -394,7 +394,7 @@ def test_invalid_type(self):
"foo"
]
)
self.assertIn("must be a dict", str(ctx.exception))
self.assertIn("invalid WebSocket URL", str(ctx.exception))

def test_no_url(self):
with self.assertRaises(ValueError) as ctx:
Expand Down

0 comments on commit 5a50788

Please sign in to comment.