Skip to content

Commit

Permalink
test: fix local test
Browse files Browse the repository at this point in the history
  • Loading branch information
darwintree committed Nov 6, 2024
1 parent 8278e58 commit 62569d4
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 14 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/coverage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ jobs:
export USE_TESTNET=1 &&
export ENS_ACCOUNT_NAME=${{secrets.ENS_ACCOUNT_NAME}} &&
export ENS_ACCOUNT_SECRET=${{secrets.ENS_ACCOUNT_SECRET}} &&
pytest --cov tests -n logical --dist loadgroup
pytest --cov tests -n 3 --dist loadgroup
- name: Upload coverage reports to Codecov
run: |
curl -Os https://uploader.codecov.io/latest/linux/codecov
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/local-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,4 @@ jobs:
pip install ".[tester]"
- name: Run test
run: |
pytest tests -n logical --dist loadgroup
pytest tests -n 3 --dist loadgroup
2 changes: 1 addition & 1 deletion .github/workflows/testnet-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,4 @@ jobs:
export ENS_ACCOUNT_NAME=${{secrets.ENS_ACCOUNT_NAME}} &&
export ENS_ACCOUNT_SECRET=${{secrets.ENS_ACCOUNT_SECRET}} &&
export TEST_FINALIZATION=1 &&
pytest tests -n logical --dist loadgroup
pytest tests -n 3 --dist loadgroup
4 changes: 2 additions & 2 deletions tests/_test_helpers/ENV_SETTING.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
LOCAL_NODE_NAME = "python-sdk-env"
TESTNET_NODE_NAME = "python-sdk-env-testnet"
LOCAL_HOST = "127.0.0.1"
PORT = "12537"
TESTNET_HOST_PORT = "12637"
INTERNAL_PORT = 12537
TESTNET_HOST_PORT = 12637

TESTNET_CONFIG_DIR = os.path.join(
os.path.dirname(__file__),
Expand Down
13 changes: 7 additions & 6 deletions tests/_test_helpers/node.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
LOCAL_NODE_NAME,
TESTNET_NODE_NAME,
LOCAL_HOST,
PORT,
INTERNAL_PORT,
VOLUMES,
TESTNET_HOST_PORT
)
Expand Down Expand Up @@ -99,10 +99,11 @@ class LocalNode(BaseNode):
if container with node_name (default as "python-sdk-env") already exists, no extra work needs be done
else pull image and create environment
"""
def __init__(self, image_name=DEV_IMAGE_FULL_NAME, node_name=LOCAL_NODE_NAME):
def __init__(self, image_name=DEV_IMAGE_FULL_NAME, node_name=LOCAL_NODE_NAME, index: int=0):
self._image_name = image_name
self._node_name = node_name
self._url = f"http://{LOCAL_HOST}:{PORT}"
host_port = INTERNAL_PORT + index
self._url = f"http://{LOCAL_HOST}:{host_port}"
self._client = docker.from_env()
container = get_existed_container(self._client, self._node_name)

Expand All @@ -115,9 +116,9 @@ def __init__(self, image_name=DEV_IMAGE_FULL_NAME, node_name=LOCAL_NODE_NAME):
detach=True,
# auto_remove=True,
ports={
f"{PORT}/tcp": f"{PORT}"
f"{INTERNAL_PORT}/tcp": f"{host_port}"
})
self._wait_for_start()
self._wait_for_start()

@cached_property
def secrets(self) -> List[str]:
Expand Down Expand Up @@ -178,7 +179,7 @@ def __init__(self, image_name=TESTNET_IMAGE_FULL_NAME, node_name=TESTNET_NODE_NA
# auto_remove=True,
volumes=volumes,
ports={
f"{PORT}/tcp": f"{TESTNET_HOST_PORT}" # use a different port on host
f"{INTERNAL_PORT}/tcp": f"{TESTNET_HOST_PORT}" # use a different port on host
})
self._wait_for_start()

Expand Down
7 changes: 4 additions & 3 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,19 +22,20 @@ def use_testnet() -> bool:
return bool(os.environ.get("TESTNET_SECRET")) or bool(os.environ.get("USE_TESTNET"))

@pytest.fixture(scope="session")
def node(use_testnet) -> Iterable[BaseNode]:
def node(use_testnet: bool, worker_id: str) -> Iterable[BaseNode]:
if use_testnet:
node = RemoteTestnetNode() # connection error might occur if using public RPC
# node = LocalTestnetNode()
yield node
# node.exit()
else:
node = LocalNode()
num = 0 if worker_id == "master" else int(worker_id[2:])
node = LocalNode(node_name=f"sdk-test-{num}", index=num)
yield node
# node.exit()

@pytest.fixture(scope="session")
def node_url(node):
def node_url(node: Iterable[LocalNode]) -> str:
return node.url

@pytest.fixture(scope="session")
Expand Down

0 comments on commit 62569d4

Please sign in to comment.