-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
honour connect_timeout and PGCONNECT_TIMEOUT
The wait_select callback previously installed to enable Ctrl+C during long queries was breaking configurable connection timeout : psycopg/psycopg2#944 This is replaced with a more visible async connection and a manual call to a custom wait_select with support for timeout. The timeout mimics default libpq behavior and reads the connect_timeout connection parameter with a fallback on PGCONNECT_TIMEOUT environment variable (and a default of 0: no timeout). A secondary benefit is to allow importing PGMigrate inside another project without PGMigrate altering the global set_wait_callback.
- Loading branch information
1 parent
8e3a4db
commit de38ef2
Showing
5 changed files
with
120 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
# Copyright (c) 2021 Aiven, Helsinki, Finland. https://aiven.io/ | ||
from aiven_db_migrate.migrate.pgmigrate import PGCluster | ||
from multiprocessing import Process | ||
from test.conftest import PGRunner | ||
from typing import Tuple | ||
|
||
import os | ||
import pytest | ||
import signal | ||
import time | ||
|
||
|
||
def test_interruptible_queries(pg_cluster: PGRunner): | ||
def wait_and_interrupt(): | ||
time.sleep(1) | ||
os.kill(os.getppid(), signal.SIGINT) | ||
|
||
cluster = PGCluster(conn_info=pg_cluster.conn_info()) | ||
interuptor = Process(target=wait_and_interrupt) | ||
interuptor.start() | ||
start_time = time.monotonic() | ||
with pytest.raises(KeyboardInterrupt): | ||
cluster.c("select pg_sleep(100)") | ||
assert time.monotonic() - start_time < 2 | ||
interuptor.join() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters