Skip to content

Commit 249bcc0

Browse files
author
clowwindy
committed
refine unit test
1 parent 30efc30 commit 249bcc0

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

shadowsocks/manager.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -186,14 +186,14 @@ def run(config):
186186
def test():
187187
import time
188188
import threading
189-
import os
190189
import struct
191190
from shadowsocks import encrypt
192191

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

198198
def run_server():
199199
config = {
@@ -213,8 +213,9 @@ def run_server():
213213
enc.append(manager)
214214
manager.run()
215215

216-
threading.Thread(target=run_server).start()
217-
time.sleep(2)
216+
t = threading.Thread(target=run_server)
217+
t.start()
218+
time.sleep(1)
218219
manager = enc[0]
219220
cli = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
220221
cli.connect(('127.0.0.1', 6001))
@@ -236,9 +237,8 @@ def run_server():
236237
tcp_cli = socket.socket()
237238
tcp_cli.connect(('127.0.0.1', 7001))
238239
tcp_cli.send(data)
239-
rdata = tcp_cli.recv(4096)
240+
tcp_cli.recv(4096)
240241
tcp_cli.close()
241-
rdata = encrypt.encrypt_all(b'1234', 'aes-256-cfb', 0, rdata)
242242

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

267-
os._exit(0)
267+
manager._loop.stop()
268+
t.join()
268269

269270

270271
if __name__ == '__main__':

0 commit comments

Comments
 (0)