Skip to content

Commit

Permalink
tests: Improve functional_tests_rpc startup
Browse files Browse the repository at this point in the history
* Use a global startup timeout, and apply it to each socket's connect
  call, rather than repeating connection attempts with short timeouts.

* Avoid leaking sockets by closing them.
  • Loading branch information
iamamyth committed Feb 1, 2025
1 parent 90359e3 commit 274b574
Showing 1 changed file with 20 additions and 16 deletions.
36 changes: 20 additions & 16 deletions tests/functional_tests/functional_tests_rpc.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import socket
import string
import os
import time

USAGE = 'usage: functional_tests_rpc.py <python> <srcdir> <builddir> [<tests-to-run> | all]'
DEFAULT_TESTS = [
Expand Down Expand Up @@ -120,23 +121,26 @@ def kill():
except: pass

# wait for error/startup
for i in range(10):
time.sleep(1)
all_open = True
for port in ports:
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.settimeout(1)
if s.connect_ex(('127.0.0.1', port)) != 0:
all_open = False
break
startup_timeout = 10
deadline = time.monotonic() + startup_timeout
for port in ports:
addr = ('127.0.0.1', port)
delay = 0
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
try:
while True:
timeout = deadline - time.monotonic() - delay
if timeout <= 0:
print('Failed to start wallet or daemon')
kill()
sys.exit(1)
time.sleep(delay)
s.settimeout(timeout)
if s.connect_ex(addr) == 0:
break
delay = .1
finally:
s.close()
if all_open:
break

if not all_open:
print('Failed to start wallet or daemon')
kill()
sys.exit(1)

# online daemons need some time to connect to peers to be ready
time.sleep(2)
Expand Down

0 comments on commit 274b574

Please sign in to comment.