forked from loggerhead/shadowsocks-rust
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbase_test.py
More file actions
36 lines (30 loc) · 1.12 KB
/
base_test.py
File metadata and controls
36 lines (30 loc) · 1.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
from threading import Thread
import time
from config_tests import *
def BaseTests(object):
def __init__(create_connection, assert_recv_eq):
self.create_connection = create_connection
self.assert_recv_eq = assert_recv_eq
def all_in_one(self):
conn = self.create_connection()
for test in tests:
self.assert_recv_eq(conn, test)
conn.close()
def one_by_one(self):
for test in tests:
conn = self.create_connection()
self.assert_recv_eq(conn, test)
conn.close()
def concurrent_with_different_task(self):
def start_conn(test):
time.sleep(0.1)
conn = self.create_connection()
self.assert_recv_eq(conn, test)
conn.close()
threads = [Thread(target=start_conn, args=(t,)) for t in tests]
[thread.start() for thread in threads]
[thread.join() for thread in threads]
def concurrent_all_in_one(self):
threads = [Thread(target=self.all_in_one) for _ in tests]
[thread.start() for thread in threads]
[thread.join() for thread in threads]