Skip to content

Commit

Permalink
Merge pull request #2531 from opentensor/fix/tests-buffer-overflow
Browse files Browse the repository at this point in the history
Fixes E2E test chain buffer issues on devnet
  • Loading branch information
ibraheem-opentensor authored Dec 11, 2024
2 parents 6ef0d6c + 924d660 commit 1d708c9
Showing 1 changed file with 23 additions and 3 deletions.
26 changes: 23 additions & 3 deletions tests/e2e_tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import signal
import subprocess
import time
import threading

import pytest
from substrateinterface import SubstrateInterface
Expand Down Expand Up @@ -37,7 +38,11 @@ def local_chain(request):

# Start new node process
process = subprocess.Popen(
cmds, stdout=subprocess.PIPE, text=True, preexec_fn=os.setsid
cmds,
stdout=subprocess.PIPE,
stderr=subprocess.STDOUT,
text=True,
preexec_fn=os.setsid,
)

# Pattern match indicates node is compiled and ready
Expand All @@ -52,16 +57,31 @@ def local_chain(request):
timestamp = int(time.time())

def wait_for_node_start(process, pattern):
for line in process.stdout:
while True:
line = process.stdout.readline()
if not line:
break

print(line.strip())
# 10 min as timeout
if int(time.time()) - timestamp > 10 * 60:
print("Subtensor not started in time")
break
return
if pattern.search(line):
print("Node started!")
break

# Start a background reader after pattern is found
# To prevent the buffer filling up
def read_output():
while True:
line = process.stdout.readline()
if not line:
break

reader_thread = threading.Thread(target=read_output, daemon=True)
reader_thread.start()

wait_for_node_start(process, pattern)

# Run the test, passing in substrate interface
Expand Down

0 comments on commit 1d708c9

Please sign in to comment.