Skip to content

Commit

Permalink
Fix some test issues.
Browse files Browse the repository at this point in the history
  • Loading branch information
ionelmc committed Dec 18, 2023
1 parent 451d65d commit 602f540
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 19 deletions.
26 changes: 13 additions & 13 deletions tests/test_manhole.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import imp
import importlib.util
import os
import re
import select
Expand Down Expand Up @@ -27,7 +27,7 @@ def is_lib_available(lib):

def is_module_available(mod):
try:
return imp.find_module(mod)
return importlib.util.find_spec(mod)
except ImportError:
return False

Expand Down Expand Up @@ -85,7 +85,7 @@ def test_simple():
uds_path = re.findall(r'(/tmp/manhole-\d+)', proc.read())[0]
wait_for_strings(proc.read, TIMEOUT, 'Waiting for new connection')
for _ in range(20):
proc.reset()
proc.buff.reset()
assert_manhole_running(proc, uds_path)


Expand All @@ -97,7 +97,7 @@ def test_connection_handler_exec(variant):
uds_path = re.findall(r'(/tmp/manhole-\d+)', proc.read())[0]
wait_for_strings(proc.read, TIMEOUT, 'Waiting for new connection')
for _ in range(200):
proc.reset()
proc.buff.reset()
sock = connect_to_manhole(uds_path)
wait_for_strings(
proc.read,
Expand Down Expand Up @@ -183,7 +183,7 @@ def test_locals_after_fork():
with TestProcess(sys.executable, HELPER, 'test_locals_after_fork') as proc:
with dump_on_error(proc.read):
wait_for_strings(proc.read, TIMEOUT, 'Fork detected')
proc.reset()
proc.buff.reset()
wait_for_strings(proc.read, TIMEOUT, '/tmp/manhole-')
child_uds_path = re.findall(r'(/tmp/manhole-\d+)', proc.read())[0]
wait_for_strings(proc.read, TIMEOUT, 'Waiting for new connection')
Expand All @@ -209,7 +209,7 @@ def test_socket_path():
with TestProcess(sys.executable, HELPER, 'test_socket_path') as proc:
with dump_on_error(proc.read):
wait_for_strings(proc.read, TIMEOUT, 'Waiting for new connection')
proc.reset()
proc.buff.reset()
assert_manhole_running(proc, SOCKET_PATH)


Expand Down Expand Up @@ -343,18 +343,18 @@ def test_with_fork():
uds_path = re.findall(r'(/tmp/manhole-\d+)', proc.read())[0]
wait_for_strings(proc.read, TIMEOUT, 'Waiting for new connection')
for _ in range(2):
proc.reset()
proc.buff.reset()
assert_manhole_running(proc, uds_path)

proc.reset()
proc.buff.reset()
wait_for_strings(proc.read, TIMEOUT, 'Fork detected')
wait_for_strings(proc.read, TIMEOUT, '/tmp/manhole-')
new_uds_path = re.findall(r'(/tmp/manhole-\d+)', proc.read())[0]
assert uds_path != new_uds_path

wait_for_strings(proc.read, TIMEOUT, 'Waiting for new connection')
for _ in range(2):
proc.reset()
proc.buff.reset()
assert_manhole_running(proc, new_uds_path)


Expand All @@ -365,18 +365,18 @@ def test_with_forkpty():
uds_path = re.findall(r'(/tmp/manhole-\d+)', proc.read())[0]
wait_for_strings(proc.read, TIMEOUT, 'Waiting for new connection')
for _ in range(2):
proc.reset()
proc.buff.reset()
assert_manhole_running(proc, uds_path)

proc.reset()
proc.buff.reset()
wait_for_strings(proc.read, TIMEOUT, 'Fork detected')
wait_for_strings(proc.read, TIMEOUT, '/tmp/manhole-')
new_uds_path = re.findall(r'(/tmp/manhole-\d+)', proc.read())[0]
assert uds_path != new_uds_path

wait_for_strings(proc.read, TIMEOUT, 'Waiting for new connection')
for _ in range(2):
proc.reset()
proc.buff.reset()
assert_manhole_running(proc, new_uds_path)


Expand Down Expand Up @@ -469,7 +469,7 @@ def test_oneshot_on_usr2_error():
wait_for_strings(proc.read, TIMEOUT, 'Waiting for new connection')
assert_manhole_running(proc, uds_path, oneshot=True, extra=lambda client: client.sock.send(b'raise SystemExit()\n'))

proc.reset()
proc.buff.reset()
proc.signal(signal.SIGUSR2)
wait_for_strings(proc.read, TIMEOUT, '/tmp/manhole-')
uds_path = re.findall(r'(/tmp/manhole-\d+)', proc.read())[0]
Expand Down
3 changes: 1 addition & 2 deletions tests/test_manhole_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,7 @@ def test_help(testdir):
'usage: manhole-cli [-h] [-t TIMEOUT] [-1 | -2 | -s SIGNAL] PID',
'Connect to a manhole.',
'positional arguments:',
' PID A numerical process id, or a path in the form:',
' /tmp/manhole-1234',
' PID A numerical process id, or a path in the form:*',
'optional arguments:',
' -h, --help show this help message and exit',
' -t TIMEOUT, --timeout TIMEOUT',
Expand Down
7 changes: 3 additions & 4 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,9 @@ deps =
cover: pytest-cov
requests
process-tests
py27: subprocess32
eventlet: eventlet==0.30.2
gevent: gevent==21.1.2
{py27,py36,py37,py38,py39,py310}: uwsgi==2.0.20
eventlet: eventlet==0.33.3
gevent: gevent==23.9.1
{py27,py36,py37,py38,py39,py310,py311,py312}: uwsgi==2.0.23
commands =
nocov: {posargs:pytest -vv --ignore=src}
cover: {posargs:pytest --cov --cov-report=term-missing --cov-report=xml -vv}
Expand Down

0 comments on commit 602f540

Please sign in to comment.