diff options
author | Daniele Varrazzo <daniele.varrazzo@gmail.com> | 2019-03-17 23:06:55 +0000 |
---|---|---|
committer | Daniele Varrazzo <daniele.varrazzo@gmail.com> | 2019-03-17 23:06:55 +0000 |
commit | 7c5afd6977c2d71a1a3f9550849580b75851a65b (patch) | |
tree | fb5468c33511a8bd3d753c670a3f905f467a0ef7 /tests | |
parent | b4b470c29a635151a65ccedb849aa2ef466df838 (diff) | |
download | psycopg2-7c5afd6977c2d71a1a3f9550849580b75851a65b.tar.gz |
Added test to reproduce ticket #829
Unrelated processes close the FD of the connection. This happens in
Python 3.6 but not 2.7. Let's see if travis shows where else it fails...
Diffstat (limited to 'tests')
-rwxr-xr-x | tests/test_connection.py | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/tests/test_connection.py b/tests/test_connection.py index 77f3b29..75abcc0 100755 --- a/tests/test_connection.py +++ b/tests/test_connection.py @@ -357,6 +357,34 @@ class ConnectionTests(ConnectingTestCase): conn.close() self.assert_(conn.pgconn_ptr is None) + @slow + def test_multiprocess_close(self): + script = ("""\ +import time +import threading +import multiprocessing +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) + +t = threading.Thread(target=thread, name='mythread') +t.start() +time.sleep(0.2) +multiprocessing.Process(target=process, name='myprocess').start() +t.join() +""" % {'dsn': dsn}) + + out = sp.check_output([sys.executable, '-c', script], stderr=sp.STDOUT) + self.assertEqual(out, b'', out.decode('ascii')) + class ParseDsnTestCase(ConnectingTestCase): def test_parse_dsn(self): |