Skip to content

Add wait option to start and stop functions #45

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Apr 10, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions testgres/node.py
Original file line number Diff line number Diff line change
Expand Up @@ -564,12 +564,13 @@ def get_control_data(self):

return out_dict

def start(self, params=[]):
def start(self, params=[], wait=True):
"""
Start this node using pg_ctl.

Args:
params: additional arguments for pg_ctl.
wait: wait until operation completes.

Returns:
This instance of :class:`.PostgresNode`.
Expand All @@ -579,7 +580,7 @@ def start(self, params=[]):
get_bin_path("pg_ctl"),
"-D", self.data_dir,
"-l", self.pg_log_file,
"-w", # wait
"-w" if wait else '-W', # --wait or --no-wait
"start"
] + params # yapf: disable

Expand All @@ -594,12 +595,13 @@ def start(self, params=[]):

return self

def stop(self, params=[]):
def stop(self, params=[], wait=True):
"""
Stop this node using pg_ctl.

Args:
params: additional arguments for pg_ctl.
wait: wait until operation completes.

Returns:
This instance of :class:`.PostgresNode`.
Expand All @@ -608,7 +610,7 @@ def stop(self, params=[]):
_params = [
get_bin_path("pg_ctl"),
"-D", self.data_dir,
"-w", # wait
"-w" if wait else '-W', # --wait or --no-wait
"stop"
] + params # yapf: disable

Expand Down
12 changes: 12 additions & 0 deletions tests/test_simple.py
Original file line number Diff line number Diff line change
Expand Up @@ -373,6 +373,18 @@ def test_backup_wrong_xlog_method(self):
BackupException, msg='Invalid xlog_method "wrong"'):
node.backup(xlog_method='wrong')

def test_pg_ctl_wait_option(self):
with get_new_node() as node:
node.init().start(wait=False)
while True:
try:
node.stop(wait=False)
break
except ExecUtilException:
# it's ok to get this exception here since node
# could be not started yet
pass

def test_replicate(self):
with get_new_node() as node:
node.init(allow_streaming=True).start()
Expand Down