diff options
| author | Sergey Shepelev <temotor@gmail.com> | 2015-03-05 16:32:40 +0300 |
|---|---|---|
| committer | Sergey Shepelev <temotor@gmail.com> | 2015-03-05 16:32:40 +0300 |
| commit | 8ca2b0d5ff27bf963db78c01bab77e679baa0abc (patch) | |
| tree | 9ff77b27986f9ac31a07bef14caa44ed6b1804af /tests/isolated | |
| parent | 84b535becafcdc932ab905061f5fa2fbea35dc74 (diff) | |
| download | eventlet-tm4.tar.gz | |
tests: move some into isolatedtm4
Diffstat (limited to 'tests/isolated')
| -rw-r--r-- | tests/isolated/env_tpool_dns.py | 12 | ||||
| -rw-r--r-- | tests/isolated/hub_kqueue_unsupported.py | 38 | ||||
| -rw-r--r-- | tests/isolated/os_waitpid.py | 13 | ||||
| -rw-r--r-- | tests/isolated/patcher_monkey_patch_ok.py | 9 | ||||
| -rw-r--r-- | tests/isolated/patcher_monkey_patch_unknown_module.py | 14 | ||||
| -rw-r--r-- | tests/isolated/patcher_psycopg.py | 51 | ||||
| -rw-r--r-- | tests/isolated/patcher_subprocess.py | 18 | ||||
| -rw-r--r-- | tests/isolated/patcher_threading_greenlet.py | 28 | ||||
| -rw-r--r-- | tests/isolated/patcher_threading_greenthread.py | 23 | ||||
| -rw-r--r-- | tests/isolated/patcher_threading_original_thread.py | 29 | ||||
| -rw-r--r-- | tests/isolated/patcher_threading_patched_thread.py | 26 | ||||
| -rw-r--r-- | tests/isolated/patcher_threading_tpool.py | 25 | ||||
| -rw-r--r-- | tests/isolated/patcher_tpool_original_thread.py | 32 | ||||
| -rw-r--r-- | tests/isolated/patcher_tpool_patched_thread.py | 32 | ||||
| -rw-r--r-- | tests/isolated/patcher_tpool_simple.py | 19 |
15 files changed, 369 insertions, 0 deletions
diff --git a/tests/isolated/env_tpool_dns.py b/tests/isolated/env_tpool_dns.py new file mode 100644 index 0000000..cbdbb1d --- /dev/null +++ b/tests/isolated/env_tpool_dns.py @@ -0,0 +1,12 @@ +from __future__ import print_function + +# no standard tests in this file, ignore +__test__ = False + +if __name__ == '__main__': + import os + os.environ['EVENTLET_TPOOL_DNS'] = 'yes' + from eventlet.green import socket + socket.gethostbyname('localhost') + socket.getaddrinfo('localhost', 80) + print('pass') diff --git a/tests/isolated/hub_kqueue_unsupported.py b/tests/isolated/hub_kqueue_unsupported.py new file mode 100644 index 0000000..481b3e5 --- /dev/null +++ b/tests/isolated/hub_kqueue_unsupported.py @@ -0,0 +1,38 @@ +# https://github.com/eventlet/eventlet/issues/38 +# get_hub on windows broken by kqueue +from __future__ import print_function + +# no standard tests in this file, ignore +__test__ = False + + +def main(): + # Simulate absence of kqueue even on platforms that support it. + import select + try: + del select.kqueue + except AttributeError: + pass + + from eventlet.support.six.moves import builtins + + original_import = builtins.__import__ + state = [False] + + def fail_import(name, *args, **kwargs): + if 'epoll' in name: + raise ImportError('disabled for test') + if 'kqueue' in name: + state[0] = True + return original_import(name, *args, **kwargs) + + builtins.__import__ = fail_import + + import eventlet.hubs + eventlet.hubs.get_default_hub() + assert state[0], 'did not try to import kqueue' + print('pass') + + +if __name__ == '__main__': + main() diff --git a/tests/isolated/os_waitpid.py b/tests/isolated/os_waitpid.py new file mode 100644 index 0000000..677b3cc --- /dev/null +++ b/tests/isolated/os_waitpid.py @@ -0,0 +1,13 @@ +from __future__ import print_function + +# no standard tests in this file, ignore +__test__ = False + +if __name__ == '__main__': + import subprocess + import eventlet + eventlet.monkey_patch(all=False, os=True) + process = subprocess.Popen("sleep 0.1 && false", shell=True) + rc = process.wait() + assert rc == 1, rc + print('pass') diff --git a/tests/isolated/patcher_monkey_patch_ok.py b/tests/isolated/patcher_monkey_patch_ok.py new file mode 100644 index 0000000..718cae4 --- /dev/null +++ b/tests/isolated/patcher_monkey_patch_ok.py @@ -0,0 +1,9 @@ +from __future__ import print_function + +# no standard tests in this file, ignore +__test__ = False + +if __name__ == '__main__': + import eventlet + eventlet.monkey_patch() + print('pass') diff --git a/tests/isolated/patcher_monkey_patch_unknown_module.py b/tests/isolated/patcher_monkey_patch_unknown_module.py new file mode 100644 index 0000000..8b83200 --- /dev/null +++ b/tests/isolated/patcher_monkey_patch_unknown_module.py @@ -0,0 +1,14 @@ +from __future__ import print_function + +# no standard tests in this file, ignore +__test__ = False + +if __name__ == '__main__': + import eventlet + err = '' + try: + eventlet.monkey_patch(finagle=True) + except TypeError as e: + err = str(e) + assert 'finagle' in err, err + print('pass') diff --git a/tests/isolated/patcher_psycopg.py b/tests/isolated/patcher_psycopg.py new file mode 100644 index 0000000..491a63e --- /dev/null +++ b/tests/isolated/patcher_psycopg.py @@ -0,0 +1,51 @@ +from __future__ import print_function + +# no standard tests in this file, ignore +__test__ = False + + +def main(): + from tests.db_pool_test import postgres_requirement + if not postgres_requirement(None, debug=False): + print('skip:postgres_requirement') + return + + import sys + import eventlet + eventlet.monkey_patch() + if not eventlet.patcher.is_monkey_patched('psycopg'): + print('psycopg not monkeypatched') + sys.exit(1) + + from eventlet.support import six + import tests + # construct a non-json dsn for the subprocess + psycopg_auth = tests.get_database_auth()['psycopg2'] + if isinstance(psycopg_auth, six.string_types): + dsn = psycopg_auth + else: + dsn = " ".join(["%s=%s" % (k, v) for k, v in six.iteritems(psycopg_auth)]) + + count = [0] + + def tick(totalseconds, persecond): + for i in range(totalseconds * persecond): + count[0] += 1 + eventlet.sleep(1.0 / persecond) + + import psycopg2 + + def fetch(num, secs): + conn = psycopg2.connect(dsn) + cur = conn.cursor() + for i in range(num): + cur.execute("select pg_sleep(%s)", [secs]) + + f = eventlet.spawn(fetch, 2, 1) + eventlet.spawn(tick, 2, 100) + f.wait() + assert count[0] > 100, count[0] + print('pass') + +if __name__ == '__main__': + main() diff --git a/tests/isolated/patcher_subprocess.py b/tests/isolated/patcher_subprocess.py new file mode 100644 index 0000000..2b359a8 --- /dev/null +++ b/tests/isolated/patcher_subprocess.py @@ -0,0 +1,18 @@ +from __future__ import print_function + +# no standard tests in this file, ignore +__test__ = False + + +def main(): + import sys + import eventlet + eventlet.monkey_patch() + from eventlet.green import subprocess + + subprocess.Popen([sys.executable, '-c', ''], stdin=subprocess.PIPE) + + print('pass') + +if __name__ == '__main__': + main() diff --git a/tests/isolated/patcher_threading_greenlet.py b/tests/isolated/patcher_threading_greenlet.py new file mode 100644 index 0000000..d192268 --- /dev/null +++ b/tests/isolated/patcher_threading_greenlet.py @@ -0,0 +1,28 @@ +from __future__ import print_function + +# no standard tests in this file, ignore +__test__ = False + + +def main(): + import eventlet + eventlet.monkey_patch() + from eventlet import event + import threading + evt = event.Event() + state = [''] + + def fun(): + state[0] = repr(threading.currentThread()) + evt.send() + + eventlet.spawn_n(fun) + evt.wait() + + assert state[0].startswith('<_MainThread'), state[0] + active_count = len(threading._active) + assert active_count == 1, active_count + print('pass') + +if __name__ == '__main__': + main() diff --git a/tests/isolated/patcher_threading_greenthread.py b/tests/isolated/patcher_threading_greenthread.py new file mode 100644 index 0000000..b5fc363 --- /dev/null +++ b/tests/isolated/patcher_threading_greenthread.py @@ -0,0 +1,23 @@ +from __future__ import print_function + +# no standard tests in this file, ignore +__test__ = False + + +def main(): + import eventlet + eventlet.monkey_patch() + import threading + state = [''] + + def fun(): + state[0] = repr(threading.currentThread()) + + eventlet.spawn(fun).wait() + assert state[0].startswith('<_GreenThread'), state[0] + active_count = len(threading._active) + assert active_count == 1, active_count + print('pass') + +if __name__ == '__main__': + main() diff --git a/tests/isolated/patcher_threading_original_thread.py b/tests/isolated/patcher_threading_original_thread.py new file mode 100644 index 0000000..5009d69 --- /dev/null +++ b/tests/isolated/patcher_threading_original_thread.py @@ -0,0 +1,29 @@ +from __future__ import print_function + +# no standard tests in this file, ignore +__test__ = False + + +def main(): + import eventlet + eventlet.monkey_patch() + import threading + threading_original = eventlet.patcher.original('threading') + state = [''] + + def fun(): + state[0] = repr(threading.currentThread()) + + t = threading_original.Thread(target=fun) + t.start() + t.join() + + assert state[0].startswith('<Thread'), state[0] + active_patched = len(threading._active) + active_original = len(threading_original._active) + assert active_patched == 1, active_patched + assert active_original == 1, active_original + print('pass') + +if __name__ == '__main__': + main() diff --git a/tests/isolated/patcher_threading_patched_thread.py b/tests/isolated/patcher_threading_patched_thread.py new file mode 100644 index 0000000..f9b7681 --- /dev/null +++ b/tests/isolated/patcher_threading_patched_thread.py @@ -0,0 +1,26 @@ +from __future__ import print_function + +# no standard tests in this file, ignore +__test__ = False + + +def main(): + import eventlet + eventlet.monkey_patch() + import threading + state = [''] + + def fun(): + state[0] = repr(threading.currentThread()) + + t = threading.Thread(target=fun) + t.start() + t.join() + + assert state[0].startswith('<_MainThread'), state[0] + active_count = len(threading._active) + assert active_count == 1, active_count + print('pass') + +if __name__ == '__main__': + main() diff --git a/tests/isolated/patcher_threading_tpool.py b/tests/isolated/patcher_threading_tpool.py new file mode 100644 index 0000000..a74ec0b --- /dev/null +++ b/tests/isolated/patcher_threading_tpool.py @@ -0,0 +1,25 @@ +from __future__ import print_function + +# no standard tests in this file, ignore +__test__ = False + + +def main(): + import eventlet + eventlet.monkey_patch() + from eventlet import tpool + import threading + state = [''] + + def fun(): + state[0] = repr(threading.currentThread()) + + tpool.execute(fun) + + assert state[0].startswith('<Thread'), state[0] + active_count = len(threading._active) + assert active_count == 1, active_count + print('pass') + +if __name__ == '__main__': + main() diff --git a/tests/isolated/patcher_tpool_original_thread.py b/tests/isolated/patcher_tpool_original_thread.py new file mode 100644 index 0000000..aa2b32d --- /dev/null +++ b/tests/isolated/patcher_tpool_original_thread.py @@ -0,0 +1,32 @@ +from __future__ import print_function + +# no standard tests in this file, ignore +__test__ = False + + +def main(): + import eventlet + eventlet.monkey_patch(time=False, thread=False) + from eventlet import tpool + import time + + tickcount = [0] + + def tick(): + from eventlet.support import six + for i in six.moves.range(1000): + tickcount[0] += 1 + eventlet.sleep() + + def do_sleep(): + tpool.execute(time.sleep, 0.5) + + eventlet.spawn(tick) + w1 = eventlet.spawn(do_sleep) + w1.wait() + assert tickcount[0] > 900 + tpool.killall() + print('pass') + +if __name__ == '__main__': + main() diff --git a/tests/isolated/patcher_tpool_patched_thread.py b/tests/isolated/patcher_tpool_patched_thread.py new file mode 100644 index 0000000..5bb8f8b --- /dev/null +++ b/tests/isolated/patcher_tpool_patched_thread.py @@ -0,0 +1,32 @@ +from __future__ import print_function + +# no standard tests in this file, ignore +__test__ = False + + +def main(): + import eventlet + eventlet.monkey_patch(time=False, thread=True) + from eventlet import tpool + import time + + tickcount = [0] + + def tick(): + from eventlet.support import six + for i in six.moves.range(1000): + tickcount[0] += 1 + eventlet.sleep() + + def do_sleep(): + tpool.execute(time.sleep, 0.5) + + eventlet.spawn(tick) + w1 = eventlet.spawn(do_sleep) + w1.wait() + assert tickcount[0] > 900 + tpool.killall() + print('pass') + +if __name__ == '__main__': + main() diff --git a/tests/isolated/patcher_tpool_simple.py b/tests/isolated/patcher_tpool_simple.py new file mode 100644 index 0000000..871b690 --- /dev/null +++ b/tests/isolated/patcher_tpool_simple.py @@ -0,0 +1,19 @@ +from __future__ import print_function + +# no standard tests in this file, ignore +__test__ = False + + +def main(): + from eventlet import patcher + patcher.monkey_patch() + from eventlet import tpool + state = [] + tpool.execute(state.append, 1) + tpool.execute(state.append, 2) + tpool.killall() + assert set(state) == set([1, 2]) + print('pass') + +if __name__ == '__main__': + main() |
