|
1
|
|
|
from __future__ import print_function |
|
2
|
|
|
|
|
3
|
|
|
import logging |
|
4
|
|
|
import os |
|
5
|
|
|
import re |
|
6
|
|
|
import socket |
|
7
|
|
|
import sys |
|
8
|
|
|
import time |
|
9
|
|
|
|
|
10
|
|
|
from process_tests import TestProcess |
|
11
|
|
|
from process_tests import TestSocket |
|
12
|
|
|
from process_tests import dump_on_error |
|
13
|
|
|
from process_tests import wait_for_strings |
|
14
|
|
|
|
|
15
|
|
|
from remote_pdb import set_trace |
|
16
|
|
|
|
|
17
|
|
|
TIMEOUT = int(os.getenv('REMOTE_PDB_TEST_TIMEOUT', 10)) |
|
18
|
|
|
|
|
19
|
|
|
|
|
20
|
|
|
def test_simple(): |
|
21
|
|
|
with TestProcess(sys.executable, __file__, 'daemon', 'test_simple') as proc: |
|
22
|
|
|
with dump_on_error(proc.read): |
|
23
|
|
|
wait_for_strings(proc.read, TIMEOUT, |
|
24
|
|
|
'{a1}', |
|
25
|
|
|
'{b1}', |
|
26
|
|
|
'RemotePdb session open at ') |
|
27
|
|
|
host, port = re.findall("RemotePdb session open at (.+):(.+),", proc.read())[0] |
|
28
|
|
|
with TestSocket(socket.create_connection((host, int(port)), timeout=TIMEOUT)) as client: |
|
29
|
|
|
with dump_on_error(client.read): |
|
30
|
|
|
wait_for_strings(proc.read, TIMEOUT, 'accepted connection from') |
|
31
|
|
|
wait_for_strings(client.read, TIMEOUT, "-> print('{b2}')") |
|
32
|
|
|
client.fh.write(b'quit\r\n') |
|
33
|
|
|
wait_for_strings(proc.read, TIMEOUT, 'DIED.') |
|
34
|
|
|
|
|
35
|
|
|
|
|
36
|
|
View Code Duplication |
def test_redirect(): |
|
|
|
|
|
|
37
|
|
|
with TestProcess(sys.executable, __file__, 'daemon', 'test_redirect') as proc: |
|
38
|
|
|
with dump_on_error(proc.read): |
|
39
|
|
|
wait_for_strings(proc.read, TIMEOUT, |
|
40
|
|
|
'{a1}', |
|
41
|
|
|
'{b1}', |
|
42
|
|
|
'RemotePdb session open at ') |
|
43
|
|
|
host, port = re.findall("RemotePdb session open at (.+):(.+),", proc.read())[0] |
|
44
|
|
|
with TestSocket(socket.create_connection((host, int(port)), timeout=TIMEOUT)) as client: |
|
45
|
|
|
with dump_on_error(client.read): |
|
46
|
|
|
wait_for_strings(proc.read, TIMEOUT, 'accepted connection from') |
|
47
|
|
|
wait_for_strings(client.read, TIMEOUT, "-> print('{b2}')") |
|
48
|
|
|
client.fh.write(b'break func_a\r\n') |
|
49
|
|
|
client.fh.write(b'continue\r\n') |
|
50
|
|
|
wait_for_strings(client.read, TIMEOUT, 'Breakpoint', '{b2}') |
|
51
|
|
|
wait_for_strings(client.read, TIMEOUT, "-> print('{a2}')") |
|
52
|
|
|
client.fh.write(b'continue\r\n') |
|
53
|
|
|
wait_for_strings(client.read, TIMEOUT, "{=>") |
|
54
|
|
|
wait_for_strings(proc.read, TIMEOUT, 'DIED.') |
|
55
|
|
|
assert 'Restoring streams' not in proc.read() |
|
56
|
|
|
|
|
57
|
|
|
|
|
58
|
|
View Code Duplication |
def test_simple_break(): |
|
|
|
|
|
|
59
|
|
|
with TestProcess(sys.executable, __file__, 'daemon', 'test_simple') as proc: |
|
60
|
|
|
with dump_on_error(proc.read): |
|
61
|
|
|
wait_for_strings(proc.read, TIMEOUT, |
|
62
|
|
|
'{a1}', |
|
63
|
|
|
'{b1}', |
|
64
|
|
|
'RemotePdb session open at ') |
|
65
|
|
|
host, port = re.findall("RemotePdb session open at (.+):(.+),", proc.read())[0] |
|
66
|
|
|
with TestSocket(socket.create_connection((host, int(port)), timeout=TIMEOUT)) as client: |
|
67
|
|
|
with dump_on_error(client.read): |
|
68
|
|
|
wait_for_strings(proc.read, TIMEOUT, 'accepted connection from') |
|
69
|
|
|
wait_for_strings(client.read, TIMEOUT, "-> print('{b2}')") |
|
70
|
|
|
client.fh.write(b'break func_a\r\n') |
|
71
|
|
|
client.fh.write(b'continue\r\n') |
|
72
|
|
|
wait_for_strings(client.read, TIMEOUT, "-> print('{a2}')") |
|
73
|
|
|
client.fh.write(b'continue\r\n') |
|
74
|
|
|
wait_for_strings(proc.read, TIMEOUT, 'DIED.') |
|
75
|
|
|
assert 'Restoring streams' not in proc.read() |
|
76
|
|
|
|
|
77
|
|
|
|
|
78
|
|
|
def func_b(patch_stdstreams): |
|
79
|
|
|
print('{b1}') |
|
80
|
|
|
set_trace(patch_stdstreams=patch_stdstreams) |
|
81
|
|
|
print('{b2}') |
|
82
|
|
|
|
|
83
|
|
|
|
|
84
|
|
|
def func_a(block=lambda _: None, patch_stdstreams=False): |
|
85
|
|
|
print('{a1}') |
|
86
|
|
|
func_b(patch_stdstreams) |
|
87
|
|
|
print('{a2}') |
|
88
|
|
|
x = block('{a3} ?') |
|
89
|
|
|
print('{=> %s}' % x) |
|
90
|
|
|
|
|
91
|
|
|
|
|
92
|
|
|
if __name__ == '__main__': |
|
93
|
|
|
logging.basicConfig( |
|
94
|
|
|
level=logging.DEBUG, |
|
95
|
|
|
format='%(process)d %(asctime)s,%(msecs)05d %(name)s %(levelname)s %(message)s', |
|
96
|
|
|
datefmt="%x~%X" |
|
97
|
|
|
) |
|
98
|
|
|
test_name = sys.argv[2] |
|
99
|
|
|
|
|
100
|
|
|
if test_name == 'test_simple': |
|
101
|
|
|
func_a() |
|
102
|
|
|
elif test_name == 'test_redirect': |
|
103
|
|
|
func_a(patch_stdstreams=True) |
|
104
|
|
|
time.sleep(TIMEOUT) |
|
105
|
|
|
else: |
|
106
|
|
|
raise RuntimeError('Invalid test spec %r.' % test_name) |
|
107
|
|
|
logging.info('DIED.') |
|
108
|
|
|
|