-
Notifications
You must be signed in to change notification settings - Fork 835
/
test_asyncio_event_loops.py
55 lines (45 loc) · 1.75 KB
/
test_asyncio_event_loops.py
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
import logging
import unittest
import asyncio
import pytest
from slack import WebClient, RTMClient
class TestAsyncioEventLoops(unittest.TestCase):
"""This test was added to verify the behavior of asyncio.new_event_loop().
Also, the tests here ensure WebClient and RTMClient don't generate a large number of event loops
even when a lot of those instances are created.
"""
def setUp(self):
self.logger = logging.getLogger(__name__)
def tearDown(self):
pass
@pytest.mark.skip("The result of this test depends on the environment")
def test_the_cost_of_event_loop_creation(self):
# create 100 event loops
loops = []
try:
upper_limit = 0
for i in range(1000):
try:
loops.append(asyncio.new_event_loop())
except OSError as e:
self.logger.info(f"Got an OSError when creating {i} event loops")
self.assertEqual(e.errno, 24)
self.assertEqual(e.strerror, "Too many open files")
upper_limit = i
break
self.assertTrue(upper_limit > 0)
finally:
for loop in loops:
loop.close()
def test_web_client_never_generate_huge_number_of_event_loops(self):
num = 1000
clients = []
for i in range(num):
clients.append(WebClient(token="xoxb-test", run_async=False))
self.assertEqual(len(clients), num)
def test_rtm_client_never_generate_huge_number_of_event_loops(self):
num = 1000
clients = []
for i in range(num):
clients.append(RTMClient(token="xoxb-test", run_async=False))
self.assertEqual(len(clients), num)