summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorDaniele Varrazzo <daniele.varrazzo@gmail.com>2019-03-18 01:53:59 +0000
committerDaniele Varrazzo <daniele.varrazzo@gmail.com>2019-03-18 01:53:59 +0000
commite569e49b8b65b98dcfcbbce5280e5132b582d513 (patch)
tree24218aee49be75a969866f4cd95271094c52dd09 /tests
parent0c581380c72aeead6766449273798d8cc93f90e4 (diff)
parentf8f5a77838d0d356d18552d2fbb295335cad7de3 (diff)
downloadpsycopg2-e569e49b8b65b98dcfcbbce5280e5132b582d513.tar.gz
Merge branch 'fix-829'
Diffstat (limited to 'tests')
-rwxr-xr-xtests/test_connection.py49
1 files changed, 46 insertions, 3 deletions
diff --git a/tests/test_connection.py b/tests/test_connection.py
index f6a08fd..b4422c6 100755
--- a/tests/test_connection.py
+++ b/tests/test_connection.py
@@ -22,14 +22,16 @@
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
# License for more details.
-import ctypes
import gc
import os
import re
-import subprocess as sp
import sys
-import threading
import time
+import ctypes
+import shutil
+import tempfile
+import threading
+import subprocess as sp
from collections import deque
from operator import attrgetter
from weakref import ref
@@ -360,6 +362,47 @@ class ConnectionTests(ConnectingTestCase):
conn.close()
self.assert_(conn.pgconn_ptr is None)
+ @slow
+ def test_multiprocess_close(self):
+ dir = tempfile.mkdtemp()
+ try:
+ with open(os.path.join(dir, "mptest.py"), 'w') as f:
+ f.write("""\
+import time
+import psycopg2
+
+def thread():
+ conn = psycopg2.connect(%(dsn)r)
+ curs = conn.cursor()
+ for i in range(10):
+ curs.execute("select 1")
+ time.sleep(0.1)
+
+def process():
+ time.sleep(0.2)
+""" % {'dsn': dsn})
+
+ script = ("""\
+import sys
+sys.path.insert(0, %(dir)r)
+import time
+import threading
+import multiprocessing
+import mptest
+
+t = threading.Thread(target=mptest.thread, name='mythread')
+t.start()
+time.sleep(0.2)
+multiprocessing.Process(target=mptest.process, name='myprocess').start()
+t.join()
+""" % {'dir': dir})
+
+ out = sp.check_output(
+ [sys.executable, '-c', script], stderr=sp.STDOUT)
+ self.assertEqual(out, b'', out)
+ finally:
+ shutil.rmtree(dir, ignore_errors=True)
+
class ParseDsnTestCase(ConnectingTestCase):
def test_parse_dsn(self):