Fix race condition in CI runs of Python SRA client tests (#1751)

* In CI, don't start Launch Kit til Ganache is ready

* Re-enable Python SRA client tests

* For local testing, await service readiness
This commit is contained in:
F. Eugene Aumson 2019-04-03 18:22:26 -04:00 committed by GitHub
parent 2d8acd4711
commit 62e6336a7d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 94 additions and 28 deletions

View File

@ -205,6 +205,7 @@ jobs:
RPC_URL: http://localhost:8545
NETWORK_ID: 50
WHITELIST_ALL_TOKENS: True
command: bash -c "until curl -sfd'{\"method\":\"net_listening\"}' http://localhost:8545 | grep true; do continue; done; forever ts/lib/index.js"
steps:
- checkout
- run: sudo chown -R circleci:circleci /usr/local/bin

View File

@ -294,6 +294,40 @@ except ApiException as e:
print("Exception when calling DefaultApi->get_asset_pairs: %s\n" % e)
```
## Contributing
We welcome improvements and fixes from the wider community! To report bugs within this package, please create an issue in this repository.
Please read our [contribution guidelines](../../CONTRIBUTING.md) before getting started.
### Install Code and Dependencies
Ensure that you have installed Python >=3.6, Docker, and docker-compose. Then:
```bash
pip install -e .[dev]
```
### Test
Tests depend on a running instance of 0x-launch-kit, backed by a Ganache node with the 0x contracts deployed in it. For convenience, a docker-compose file is provided that creates this environment. And a shortcut is provided to interface with that file: `./setup.py start_test_relayer` will start those services. With them running, the tests can be run with `./setup.py test`. When you're done with testing, you can `./setup.py stop_test_relayer`.
### Clean
`./setup.py clean --all`
### Lint
`./setup.py lint`
### Build Documentation
`./setup.py build_sphinx`
### More
See `./setup.py --help-commands` for more info.
## Documentation for API Endpoints
All URIs are relative to _http://localhost_

View File

@ -5,6 +5,8 @@
import subprocess # nosec
import distutils.command.build_py
from urllib.request import urlopen
from urllib.error import URLError
from setuptools import setup, find_packages # noqa: H301
from setuptools.command.test import test as TestCommand
@ -51,28 +53,41 @@ class TestPublishCommand(distutils.command.build_py.build_py):
)
class GanacheCommand(distutils.command.build_py.build_py):
"""Custom command to publish to pypi.org."""
description = "Run ganache daemon to support tests."
def run(self):
"""Run ganache."""
cmd_line = (
"docker run -d -p 8545:8545 0xorg/ganache-cli:2.2.2"
).split()
subprocess.call(cmd_line) # nosec
class LaunchKitCommand(distutils.command.build_py.build_py):
class StartTestRelayerCommand(distutils.command.build_py.build_py):
"""Custom command to boot up a local 0x-launch-kit in docker."""
description = "Run launch-kit daemon to support sra_client demos."
description = "Run launch-kit daemon to support tests."
def run(self):
"""Run 0x-launch-kit."""
cmd_line = ("docker run -d -p 3000:3000 0xorg/launch-kit-ci").split()
subprocess.call(cmd_line) # nosec
"""Run `docker-compose up`."""
subprocess.call( # nosec
("docker-compose -f test/relayer/docker-compose.yml up -d").split()
)
launch_kit_ready = False
print("Waiting for relayer to start accepting connections...", end="")
while not launch_kit_ready:
try:
launch_kit_ready = (
urlopen( # nosec
"http://localhost:3000/v2/asset_pairs"
).getcode()
== 200
)
except URLError:
continue
print("done")
class StopTestRelayerCommand(distutils.command.build_py.build_py):
"""Custom command to tear down the local 0x-launch-kit test relayer."""
description = "Tear down launch-kit daemon."
def run(self):
"""Run `docker-compose down`."""
subprocess.call( # nosec
("docker-compose -f test/relayer/docker-compose.yml down").split()
)
class LintCommand(distutils.command.build_py.build_py):
@ -142,11 +157,11 @@ setup(
cmdclass={
"test_publish": TestPublishCommand,
"publish": PublishCommand,
"launch_kit": LaunchKitCommand,
"start_test_relayer": StartTestRelayerCommand,
"stop_test_relayer": StopTestRelayerCommand,
"lint": LintCommand,
"publish_docs": PublishDocsCommand,
"test": TestCommandExtension,
"ganache": GanacheCommand,
},
extras_require={
"dev": [

View File

@ -93,7 +93,7 @@ Post an order to an SRA-compliant Relayer.
... jsdict_order_to_struct(example_order), exchange_address)
>>> example_order["signature"] = sign_hash(
... provider, Web3.toChecksumAddress(maker_address), order_hash)
>>> relayer_api.post_order_with_http_info( # doctest: +SKIP
>>> relayer_api.post_order_with_http_info(
... network_id=50, signed_order_schema=example_order)[1]
200
@ -101,7 +101,7 @@ Get Orders
-----------
Get orders from an SRA-compliant Relayer.
>>> relayer_api.get_orders() # doctest: +SKIP
>>> relayer_api.get_orders()
{'records': [{'meta_data': {},
'order': {'exchange_address': '0x48bacb9266a570d521063ef5dd96e61686dbe788',
'expiration_time_seconds': '1000000000000000000000',
@ -121,7 +121,7 @@ Get Order
---------
Get an order by hash from an SRA-compliant Relayer.
>>> relayer_api.get_order("0x" + order_hash) # doctest: +SKIP
>>> relayer_api.get_order("0x" + order_hash)
{'meta_data': {},
'order': {'exchange_address': '0x48bacb9266a570d521063ef5dd96e61686dbe788',
'expiration_time_seconds': '1000000000000000000000',
@ -141,7 +141,7 @@ Get Asset Pair
---------------
Get available asset pairs from an SRA-compliant Relayer.
>>> relayer_api.get_asset_pairs() # doctest: +SKIP
>>> relayer_api.get_asset_pairs()
{'records': [{'assetDataA': {'assetData': '0xf47261b00000000000000000000000000b1ba0af832d7c05fd64161e0db78e85978e8082',
'maxAmount': '115792089237316195423570985008687907853269984665640564039457584007913129639936',
'minAmount': '0',
@ -155,7 +155,7 @@ Get Orderbook
-------------
Get the orderbook for the WETH/ZRX asset pair from an SRA-compliant Relayer.
>>> relayer_api.get_orderbook( # doctest: +SKIP
>>> relayer_api.get_orderbook(
... base_asset_data=weth_asset_data,
... quote_asset_data=zrx_asset_data)
{'asks': {'records': [{'meta_data': {},

View File

@ -0,0 +1,19 @@
# Run Launch Kit with Ganache as the backing node
version: '3'
services:
ganache:
image: "0xorg/ganache-cli:2.2.2"
ports:
- "8545:8545"
launchkit:
image: "0xorg/launch-kit-ci"
depends_on:
- ganache
ports:
- "3000:3000"
network_mode: "host" # to connect to ganache
environment:
- NETWORK_ID=50
- RPC_URL=http://localhost:8545
- WHITELIST_ALL_TOKENS=True
command: bash -c "until curl -sfd'{\"method\":\"net_listening\"}' http://localhost:8545 | grep true; do continue; done; forever ts/lib/index.js"

View File

@ -6,13 +6,10 @@ from __future__ import absolute_import
import unittest
import pytest
from sra_client import ApiClient, Configuration
from sra_client.api import DefaultApi
@pytest.mark.skip(reason="Circle CI error launch kit unreachable")
class TestDefaultApi(unittest.TestCase):
"""DefaultApi unit test stubs"""