Browse Source

refine tests: add time limit for curl; output shadowsocks logs

auth
clowwindy 10 years ago
parent
commit
5892789005
  1. 1
      .travis.yml
  2. 64
      tests/test.py

1
.travis.yml

@ -17,6 +17,7 @@ script:
- pep8 . - pep8 .
- pyflakes . - pyflakes .
- python tests/nose_plugin.py -v - python tests/nose_plugin.py -v
- python setup.py sdist
- python tests/test.py -c tests/aes.json - python tests/test.py -c tests/aes.json
- python tests/test.py -c tests/aes-ctr.json - python tests/test.py -c tests/aes-ctr.json
- python tests/test.py -c tests/aes-cfb1.json - python tests/test.py -c tests/aes-cfb1.json

64
tests/test.py

@ -47,6 +47,16 @@ p1 = Popen(['python', 'shadowsocks/server.py', '-c', server_config],
p2 = Popen(['python', 'shadowsocks/local.py', '-c', client_config], p2 = Popen(['python', 'shadowsocks/local.py', '-c', client_config],
stdin=PIPE, stdout=PIPE, stderr=PIPE, close_fds=True) stdin=PIPE, stdout=PIPE, stderr=PIPE, close_fds=True)
p3 = None p3 = None
p4 = None
p3_fin = False
p4_fin = False
# 1 shadowsocks started
# 2 curl started
# 3 curl finished
# 4 dig started
# 5 dig finished
stage = 1
try: try:
local_ready = False local_ready = False
@ -59,6 +69,11 @@ try:
for fd in r: for fd in r:
line = fd.readline() line = fd.readline()
if not line:
if stage == 2 and fd == p3.stdout:
stage = 3
if stage == 4 and fd == p4.stdout:
stage = 5
if bytes != str: if bytes != str:
line = str(line, 'utf8') line = str(line, 'utf8')
sys.stdout.write(line) sys.stdout.write(line)
@ -70,27 +85,38 @@ try:
if local_ready and server_ready and p3 is None: if local_ready and server_ready and p3 is None:
time.sleep(1) time.sleep(1)
break p3 = Popen(['curl', 'http://www.example.com/', '-v', '-L',
'--socks5-hostname', '127.0.0.1:1081',
p3 = Popen(['curl', 'http://www.example.com/', '-v', '-L', '-m', '15', '--connect-timeout', '10'],
'--socks5-hostname', '127.0.0.1:1081'], close_fds=True) stdin=PIPE, stdout=PIPE, stderr=PIPE, close_fds=True)
if p3 is not None: if p3 is not None:
r = p3.wait() fdset.append(p3.stdout)
if r != 0: fdset.append(p3.stderr)
sys.exit(r) stage = 2
else: else:
sys.exit(1) sys.exit(1)
p4 = Popen(['socksify', 'dig', '@8.8.8.8', 'www.google.com'], if stage == 3 and p3 is not None:
close_fds=True) fdset.remove(p3.stdout)
if p4 is not None: fdset.remove(p3.stderr)
r = p4.wait() r = p3.wait()
if r != 0: if r != 0:
sys.exit(r) sys.exit(1)
else: p4 = Popen(['socksify', 'dig', '@8.8.8.8', 'www.google.com'],
sys.exit(1) stdin=PIPE, stdout=PIPE, stderr=PIPE, close_fds=True)
print('test passed') if p4 is not None:
fdset.append(p4.stdout)
fdset.append(p4.stderr)
stage = 4
else:
sys.exit(1)
if stage == 5:
r = p4.wait()
if r != 0:
sys.exit(1)
print('test passed')
break
finally: finally:
for p in [p1, p2]: for p in [p1, p2]:
try: try:

Loading…
Cancel
Save