Skip to content
Closed
Show file tree
Hide file tree
Changes from 7 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 .github/workflows/e2e-subtensor-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ jobs:
- name: Install uv
uses: astral-sh/setup-uv@v4
with:
python-version: 3.13
python-version: ${{ matrix.python-version }}

- name: install dependencies
run: |
Expand Down
12 changes: 10 additions & 2 deletions tests/e2e_tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,7 @@ def try_start_docker():
start_new_session=True,
) as process:
try:
loop = None
substrate = None
try:
pattern = re.compile(r"Imported #1")
Expand All @@ -187,22 +188,29 @@ def try_start_docker():
)
if not result.stdout.strip():
raise RuntimeError("Docker container failed to start.")

loop = asyncio.new_event_loop()
asyncio.set_event_loop(loop)
substrate = AsyncSubstrateInterface(url="ws://127.0.0.1:9944")
yield substrate

finally:
try:
if substrate:
asyncio.run(substrate.close())
if substrate and loop:
loop.run_until_complete(substrate.close())
except Exception:
logging.warning("Failed to close substrate connection.")

try:
subprocess.run(["docker", "kill", container_name])
subprocess.run(["docker", "wait", container_name], check=False)
process.wait(timeout=10)
except subprocess.TimeoutExpired:
os.killpg(os.getpgid(process.pid), signal.SIGKILL)

if loop:
loop.close()


@pytest.fixture(scope="function")
def wallet_setup():
Expand Down
4 changes: 2 additions & 2 deletions tests/e2e_tests/test_senate.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"""

import asyncio
from .utils import call_add_proposal
from .utils import call_add_proposal, run_async


def test_senate(local_chain, wallet_setup):
Expand Down Expand Up @@ -90,7 +90,7 @@ def test_senate(local_chain, wallet_setup):
assert wallet_bob.hotkey.ss58_address in root_senate_after_reg.stdout

# Manually add a proposal on the chain & assert
success = asyncio.run(call_add_proposal(local_chain, wallet_bob))
success = run_async(call_add_proposal(local_chain, wallet_bob))
assert success is True

# Fetch proposals after adding one
Expand Down
10 changes: 10 additions & 0 deletions tests/e2e_tests/utils.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import asyncio
import os
import re
import shutil
Expand Down Expand Up @@ -299,3 +300,12 @@ async def call_add_proposal(

await response.process_events()
return await response.is_success

def run_async(coro):
"""Simple helper to run async code in tests (for 3.9)."""
try:
loop = asyncio.get_event_loop()
except RuntimeError:
loop = asyncio.new_event_loop()
asyncio.set_event_loop(loop)
return loop.run_until_complete(coro)
Loading