Skip to content

Commit

Permalink
refine unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
clowwindy committed Aug 5, 2015
1 parent 30efc30 commit 249bcc0
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions shadowsocks/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,14 +186,14 @@ def run(config):
def test():
import time
import threading
import os
import struct
from shadowsocks import encrypt

logging.basicConfig(level=logging.DEBUG,
logging.basicConfig(level=5,
format='%(asctime)s %(levelname)-8s %(message)s',
datefmt='%Y-%m-%d %H:%M:%S')
enc = []
eventloop.TIMEOUT_PRECISION = 1

def run_server():
config = {
Expand All @@ -213,8 +213,9 @@ def run_server():
enc.append(manager)
manager.run()

threading.Thread(target=run_server).start()
time.sleep(2)
t = threading.Thread(target=run_server)
t.start()
time.sleep(1)
manager = enc[0]
cli = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
cli.connect(('127.0.0.1', 6001))
Expand All @@ -236,9 +237,8 @@ def run_server():
tcp_cli = socket.socket()
tcp_cli.connect(('127.0.0.1', 7001))
tcp_cli.send(data)
rdata = tcp_cli.recv(4096)
tcp_cli.recv(4096)
tcp_cli.close()
rdata = encrypt.encrypt_all(b'1234', 'aes-256-cfb', 0, rdata)

data, addr = cli.recvfrom(1506)
data = common.to_str(data)
Expand All @@ -264,7 +264,8 @@ def run_server():
assert '8382' in stats
logging.info('UDP statistics test passed')

os._exit(0)
manager._loop.stop()
t.join()


if __name__ == '__main__':
Expand Down

0 comments on commit 249bcc0

Please sign in to comment.