Skip to content

Commit 4554d9d

Browse files
committed
add unit test
1 parent 6042164 commit 4554d9d

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

tests/test_ros.py

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,3 +58,38 @@ def handle_closing():
5858
assert ctx["closing_event_called"]
5959
assert ctx["was_still_connected"]
6060
assert closing_was_handled_synchronously_before_close
61+
62+
63+
def test_multithreaded_connect_disconnect():
64+
CONNECTIONS = 30
65+
clients = []
66+
67+
def connect(clients):
68+
ros = Ros(url)
69+
ros.run()
70+
clients.append(ros)
71+
72+
# First connect all
73+
threads = []
74+
for _ in range(CONNECTIONS):
75+
thread = threading.Thread(target=connect, args=(clients,))
76+
thread.daemon = False
77+
thread.start()
78+
threads.append(thread)
79+
80+
for thread in threads:
81+
thread.join()
82+
83+
# Assert connection status
84+
for ros in clients:
85+
assert ros.is_connected
86+
87+
# Now disconnect all
88+
for ros in clients:
89+
ros.close()
90+
91+
time.sleep(0.5)
92+
93+
# Assert connection status
94+
for ros in clients:
95+
assert ros.is_connected == False

0 commit comments

Comments
 (0)