From 2b6d2017ed4f199caa7e032100ac048ebc3978e2 Mon Sep 17 00:00:00 2001 From: Daniele Varrazzo Date: Sun, 28 Nov 2010 13:42:06 +0000 Subject: [PATCH] Added paranoia test to check we haven't broken gil release. Got scared testing cancel with a signal as it doesn't work. But probably signals are not deliveded to Python in the middle of an opcode. --- tests/test_connection.py | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/tests/test_connection.py b/tests/test_connection.py index 9a28b00e..99d9f4cf 100644 --- a/tests/test_connection.py +++ b/tests/test_connection.py @@ -1,5 +1,7 @@ #!/usr/bin/env python +import time +import threading from testutils import unittest, decorate_all_tests from operator import attrgetter @@ -90,6 +92,24 @@ class ConnectionTests(unittest.TestCase): self.assertRaises(psycopg2.NotSupportedError, cnn.xid, 42, "foo", "bar") + def test_concurrent_execution(self): + def slave(cnn): + cur = cnn.cursor() + cur.execute("select pg_sleep(2)") + cur.close() + + cnn1 = self.connect() + cnn2 = self.connect() + + t1 = threading.Thread(target=slave, args=(cnn1,)) + t2 = threading.Thread(target=slave, args=(cnn2,)) + t0 = time.time() + t1.start() + t2.start() + t1.join() + t2.join() + self.assert_(time.time() - t0 < 3, + "something broken in concurrency") class IsolationLevelsTestCase(unittest.TestCase):