-
Notifications
You must be signed in to change notification settings - Fork 333
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feature/mvds00/test axon subprocess error checking #2226
base: staging
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
import asyncio | ||
import sys | ||
import textwrap | ||
|
||
import pytest | ||
|
||
|
@@ -29,6 +30,8 @@ | |
|
||
""" | ||
|
||
INDENT = " " | ||
|
||
|
||
@pytest.mark.asyncio | ||
async def test_axon(local_chain): | ||
|
@@ -68,35 +71,52 @@ async def test_axon(local_chain): | |
|
||
# register miner | ||
# "python neurons/miner.py --netuid 1 --subtensor.chain_endpoint ws://localhost:9945 --wallet.name wallet.name --wallet.hotkey wallet.hotkey.ss58_address" | ||
cmd = " ".join( | ||
[ | ||
f"{sys.executable}", | ||
f'"{template_path}{templates_repo}/neurons/miner.py"', | ||
"--no_prompt", | ||
"--netuid", | ||
str(netuid), | ||
"--subtensor.network", | ||
"local", | ||
"--subtensor.chain_endpoint", | ||
"ws://localhost:9945", | ||
"--wallet.path", | ||
wallet.path, | ||
"--wallet.name", | ||
wallet.name, | ||
"--wallet.hotkey", | ||
"default", | ||
] | ||
) | ||
|
||
axon_process = await asyncio.create_subprocess_shell( | ||
cmd, | ||
args = [ | ||
f"{template_path}{templates_repo}/neurons/miner.py", | ||
"--no_prompt", | ||
"--netuid", | ||
str(netuid), | ||
"--subtensor.network", | ||
"local", | ||
"--subtensor.chain_endpoint", | ||
"ws://localhost:9945", | ||
"--wallet.path", | ||
wallet.path, | ||
"--wallet.name", | ||
wallet.name, | ||
"--wallet.hotkey", | ||
"default", | ||
] | ||
|
||
cmd = sys.executable + " " + " ".join(args) | ||
|
||
axon_process = await asyncio.create_subprocess_exec( | ||
sys.executable, | ||
*args, | ||
stdout=asyncio.subprocess.PIPE, | ||
stderr=asyncio.subprocess.PIPE, | ||
env={"NEST_ASYNCIO": "0"}, | ||
) | ||
logging.info("Neuron Alice is now mining") | ||
await asyncio.sleep(1) # wait for the miner to start up or fail | ||
if axon_process.returncode != None: | ||
stdout, stderr = await axon_process.communicate() | ||
stdout = textwrap.indent(stdout.decode("UTF8"), INDENT) | ||
stderr = textwrap.indent(stderr.decode("UTF8"), INDENT) | ||
assert ( | ||
axon_process.returncode == None | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
), f"miner process stopped immediately or did not start:\n{cmd}\nstdout:\n{stdout}\nstderr:\n{stderr}" | ||
|
||
logging.info(f"Neuron Alice is now mining: {axon_process}") | ||
await asyncio.sleep( | ||
5 | ||
) # wait for 5 seconds for the metagraph to refresh with latest data | ||
if axon_process.returncode != None: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
stdout, stderr = await axon_process.communicate() | ||
stdout = textwrap.indent(stdout.decode("UTF8"), INDENT) | ||
stderr = textwrap.indent(stderr.decode("UTF8"), INDENT) | ||
assert ( | ||
axon_process.returncode == None | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
), f"miner process stopped unexpectedly:\n{cmd}\nstdout:\n{stdout}\nstderr:\n{stderr}" | ||
|
||
# refresh metagraph | ||
metagraph = bittensor.metagraph(netuid=netuid, network="ws://localhost:9945") | ||
|
@@ -109,4 +129,29 @@ async def test_axon(local_chain): | |
assert updated_axon.port == 8091 | ||
assert updated_axon.hotkey == alice_keypair.ss58_address | ||
assert updated_axon.coldkey == alice_keypair.ss58_address | ||
|
||
# Terminate miner and make sure nothing bad happened. | ||
if axon_process.returncode == None: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
logging.info("terminating miner") | ||
try: | ||
# try/except to prevent exception in case the process just ends now | ||
axon_process.terminate() | ||
except: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let's not do bare |
||
pass | ||
await asyncio.sleep(1) | ||
|
||
if axon_process.returncode == None: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
logging.info("killing miner") | ||
try: | ||
# try/except to prevent exception in case the process just ends now | ||
axon_process.kill() | ||
except: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. bare |
||
pass | ||
|
||
stdout, stderr = await axon_process.communicate() | ||
stdout = textwrap.indent(stdout.decode("UTF8"), INDENT) | ||
stderr = textwrap.indent(stderr.decode("UTF8"), INDENT) | ||
assert ( | ||
"Exception" not in stderr | ||
), f"miner output indicates issue:\nstdout:\n{stdout}\nstderr:\n{stderr}" | ||
logging.info("Passed test_axon") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is not
instead of!=