summaryrefslogtreecommitdiff
path: root/tests/patcher_psycopg_test_patched.py
diff options
context:
space:
mode:
authorSergey Shepelev <temotor@gmail.com>2014-04-02 15:48:28 +0400
committerSergey Shepelev <temotor@gmail.com>2015-02-21 16:51:18 +0300
commitc6e5320f6b4b881aa7de77e4814167ccb8c2bf7c (patch)
tree89aaf1c1423200f8da42f1d86a2dbfba344a08ae /tests/patcher_psycopg_test_patched.py
parenta6ce444265d36fb23361809d40da73caf4864487 (diff)
downloadeventlet-run_python.tar.gz
tests: ProcessBase -> run_pythonrun_python
Extracted inline code to permanent files Python3 compatibility of test files tests.run_python: new_tmp flag to create new temporary directory and pass it to child process via environ[TMP]. The directory with any files is removed when child process is finished. tests.rmtree: silent version of shutil.rmtree()
Diffstat (limited to 'tests/patcher_psycopg_test_patched.py')
-rw-r--r--tests/patcher_psycopg_test_patched.py37
1 files changed, 37 insertions, 0 deletions
diff --git a/tests/patcher_psycopg_test_patched.py b/tests/patcher_psycopg_test_patched.py
new file mode 100644
index 0000000..9be75ef
--- /dev/null
+++ b/tests/patcher_psycopg_test_patched.py
@@ -0,0 +1,37 @@
+from __future__ import print_function
+# no standard tests in this file, ignore
+__test__ = False
+
+
+def fetch(dsn, num, secs):
+ conn = psycopg2.connect(dsn)
+ cur = conn.cursor()
+ for i in range(num):
+ cur.execute("select pg_sleep(%s)", [secs])
+
+
+def tick(count, totalseconds, persecond):
+ for i in range(totalseconds * persecond):
+ count[0] += 1
+ eventlet.sleep(1.0 / persecond)
+
+
+if __name__ == '__main__':
+ import os
+ import sys
+ import eventlet
+ eventlet.monkey_patch()
+ from eventlet import patcher
+ if not patcher.is_monkey_patched('psycopg'):
+ print("Psycopg not monkeypatched")
+ sys.exit(0)
+
+ dsn = os.environ['PSYCOPG_TEST_DSN']
+ import psycopg2
+
+ count = [0]
+ f = eventlet.spawn(fetch, dsn, 2, 1)
+ t = eventlet.spawn(tick, count, 2, 100)
+ f.wait()
+ assert count[0] > 100, count[0]
+ print("done")