Skip to content

Commit fc14bdc

Browse files
committed
Enhance PostgreSQLExecutor with wait_for_postgres and timeout handling
- Added wait_for_postgres() call after pg_ctl start to ensure the server is ready for connections. - Implemented timeout handling in the stop() method to raise TimeoutExpired if the stop command exceeds the configured timeout.
1 parent 9ccaabd commit fc14bdc

1 file changed

Lines changed: 11 additions & 3 deletions

File tree

pytest_postgresql/executor.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,10 @@ def start(self: T) -> T:
218218
raise TimeoutExpired(self, self._timeout) from exc
219219
if result.returncode != 0:
220220
raise ProcessFinishedWithError(self, result.returncode)
221+
# pg_ctl start without -w returns before the server accepts connections.
222+
# wait_for_postgres() polls self.running() when -w is absent; when -w is
223+
# present pg_ctl has already waited so it returns immediately.
224+
self.wait_for_postgres()
221225
return self
222226
return super().start()
223227

@@ -349,9 +353,13 @@ def _windows_terminate_process(self, _sig: Optional[int] = None) -> None:
349353

350354
def stop(self: T, sig: Optional[int] = None, exp_sig: Optional[int] = None) -> T:
351355
"""Issue a stop request to executable."""
352-
subprocess.check_output(
353-
[self.executable, "stop", "-D", self.datadir, "-m", "f"],
354-
)
356+
try:
357+
subprocess.check_output(
358+
[self.executable, "stop", "-D", self.datadir, "-m", "f"],
359+
timeout=self._timeout,
360+
)
361+
except subprocess.TimeoutExpired as exc:
362+
raise TimeoutExpired(self, self._timeout) from exc
355363
try:
356364
if platform.system() == "Windows":
357365
self._windows_terminate_process(sig)

0 commit comments

Comments
 (0)