mirror of
https://github.com/psycopg/psycopg2.git
synced 2025-08-01 19:00:09 +03:00
handle the green case in test
This commit is contained in:
parent
3bc30f1454
commit
52fc8bbeda
|
@ -45,8 +45,7 @@ from psycopg2 import extensions as ext
|
||||||
from .testutils import (
|
from .testutils import (
|
||||||
PY2, unittest, skip_if_no_superuser, skip_before_postgres,
|
PY2, unittest, skip_if_no_superuser, skip_before_postgres,
|
||||||
skip_after_postgres, skip_before_libpq, skip_after_libpq,
|
skip_after_postgres, skip_before_libpq, skip_after_libpq,
|
||||||
ConnectingTestCase, skip_if_tpc_disabled, skip_if_windows, slow,
|
ConnectingTestCase, skip_if_tpc_disabled, skip_if_windows, slow, green)
|
||||||
skip_if_green)
|
|
||||||
|
|
||||||
from .testconfig import dbhost, dsn, dbname
|
from .testconfig import dbhost, dsn, dbname
|
||||||
|
|
||||||
|
@ -412,26 +411,29 @@ t.join()
|
||||||
shutil.rmtree(dir, ignore_errors=True)
|
shutil.rmtree(dir, ignore_errors=True)
|
||||||
|
|
||||||
@slow
|
@slow
|
||||||
@skip_if_green
|
|
||||||
def test_handles_keyboardinterrupt(self):
|
def test_handles_keyboardinterrupt(self):
|
||||||
def conn(queue):
|
def conn(queue):
|
||||||
host = "10.255.255.1" # will timeout
|
host = "10.255.255.1" # will timeout
|
||||||
queue.put(1)
|
queue.put(1)
|
||||||
try:
|
try:
|
||||||
self.connect(host=host, password="x", connect_timeout=0.5)
|
self.connect(host=host, password="x", connect_timeout=1)
|
||||||
except KeyboardInterrupt:
|
except KeyboardInterrupt:
|
||||||
queue.put("KeyboardInterrupt")
|
queue.put("KeyboardInterrupt")
|
||||||
except psycopg2.OperationalError:
|
except Exception as e:
|
||||||
queue.put("OperationalError")
|
queue.put(str(e))
|
||||||
|
|
||||||
queue = multiprocessing.Queue()
|
queue = multiprocessing.Queue()
|
||||||
process = multiprocessing.Process(target=conn, args=(queue,))
|
process = multiprocessing.Process(target=conn, args=(queue,))
|
||||||
process.start()
|
process.start()
|
||||||
queue.get()
|
queue.get()
|
||||||
time.sleep(0.3)
|
time.sleep(0.5)
|
||||||
os.kill(process.pid, signal.SIGINT)
|
os.kill(process.pid, signal.SIGINT)
|
||||||
|
raised = queue.get()
|
||||||
process.join()
|
process.join()
|
||||||
self.assertEqual(queue.get(), "KeyboardInterrupt")
|
if green:
|
||||||
|
self.assertEqual(raised, "asynchronous connection attempt underway")
|
||||||
|
else:
|
||||||
|
self.assertEqual(raised, "KeyboardInterrupt")
|
||||||
|
|
||||||
|
|
||||||
class ParseDsnTestCase(ConnectingTestCase):
|
class ParseDsnTestCase(ConnectingTestCase):
|
||||||
|
|
Loading…
Reference in New Issue
Block a user