2 from tests.patcher_test import ProcessBase
3 from tests import skip_with_pyevent
6 class Socket(ProcessBase):
7 def test_patched_thread(self):
8 new_mod = """from eventlet.green import socket
9 socket.gethostbyname('localhost')
10 socket.getaddrinfo('localhost', 80)
12 os.environ['EVENTLET_TPOOL_DNS'] = 'yes'
14 self.write_to_tempfile("newmod", new_mod)
15 output, lines = self.launch_subprocess('newmod.py')
16 self.assertEqual(len(lines), 1, lines)
18 del os.environ['EVENTLET_TPOOL_DNS']
21 class Tpool(ProcessBase):
23 def test_tpool_size(self):
26 new_mod = """from eventlet import tpool
34 if current[0] > highwater[0]:
35 highwater[0] = current[0]
39 p = eventlet.GreenPool()
40 for i in range(expected*2):
41 p.spawn(tpool.execute, count)
43 assert highwater[0] > 20, "Highwater %%s <= %%s" %% (highwater[0], normal)
45 os.environ['EVENTLET_THREADPOOL_SIZE'] = expected
47 self.write_to_tempfile("newmod", new_mod % (expected, normal))
48 output, lines = self.launch_subprocess('newmod.py')
49 self.assertEqual(len(lines), 1, lines)
51 del os.environ['EVENTLET_THREADPOOL_SIZE']
53 def test_tpool_negative(self):
54 new_mod = """from eventlet import tpool
58 print("should not get here")
61 except AssertionError:
64 os.environ['EVENTLET_THREADPOOL_SIZE'] = "-1"
66 self.write_to_tempfile("newmod", new_mod)
67 output, lines = self.launch_subprocess('newmod.py')
68 self.assertEqual(len(lines), 2, lines)
69 self.assertEqual(lines[0], "success", output)
71 del os.environ['EVENTLET_THREADPOOL_SIZE']
73 def test_tpool_zero(self):
74 new_mod = """from eventlet import tpool
81 os.environ['EVENTLET_THREADPOOL_SIZE'] = "0"
83 self.write_to_tempfile("newmod", new_mod)
84 output, lines = self.launch_subprocess('newmod.py')
85 self.assertEqual(len(lines), 4, lines)
86 self.assertEqual(lines[-2], 'ran it', lines)
87 assert 'Warning' in lines[1] or 'Warning' in lines[0], lines
89 del os.environ['EVENTLET_THREADPOOL_SIZE']
92 class Hub(ProcessBase):
95 super(Hub, self).setUp()
96 self.old_environ = os.environ.get('EVENTLET_HUB')
97 os.environ['EVENTLET_HUB'] = 'selects'
101 os.environ['EVENTLET_HUB'] = self.old_environ
103 del os.environ['EVENTLET_HUB']
104 super(Hub, self).tearDown()
106 def test_eventlet_hub(self):
107 new_mod = """from eventlet import hubs
108 print(hubs.get_hub())
110 self.write_to_tempfile("newmod", new_mod)
111 output, lines = self.launch_subprocess('newmod.py')
112 self.assertEqual(len(lines), 2, "\n".join(lines))
113 assert "selects" in lines[0]