From 404acfbd2df2b88cf3b895558d03e2aa8613a7dd Mon Sep 17 00:00:00 2001 From: Ildus Kurbangaliev Date: Tue, 10 Apr 2018 12:21:33 +0300 Subject: [PATCH 1/3] Add wait option to start and stop functions --- testgres/node.py | 10 ++++++---- tests/test_simple.py | 5 +++++ 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/testgres/node.py b/testgres/node.py index d68f3d34..71d8952f 100644 --- a/testgres/node.py +++ b/testgres/node.py @@ -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`. @@ -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 @@ -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`. @@ -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 diff --git a/tests/test_simple.py b/tests/test_simple.py index f639e92a..bbb1b9bc 100755 --- a/tests/test_simple.py +++ b/tests/test_simple.py @@ -373,6 +373,11 @@ 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) + node.stop(wait=False) + def test_replicate(self): with get_new_node() as node: node.init(allow_streaming=True).start() From 9652bb970c7a456bc4600cf59b9244a2ed0f6665 Mon Sep 17 00:00:00 2001 From: Ildus Kurbangaliev Date: Tue, 10 Apr 2018 12:36:57 +0300 Subject: [PATCH 2/3] Fix test for wait option --- testgres/node.py | 4 ++-- tests/test_simple.py | 10 +++++++++- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/testgres/node.py b/testgres/node.py index 71d8952f..f93f8787 100644 --- a/testgres/node.py +++ b/testgres/node.py @@ -570,7 +570,7 @@ def start(self, params=[], wait=True): Args: params: additional arguments for pg_ctl. - wait: wait until operation completes + wait: wait until operation completes. Returns: This instance of :class:`.PostgresNode`. @@ -601,7 +601,7 @@ def stop(self, params=[], wait=True): Args: params: additional arguments for pg_ctl. - wait: wait until operation completes + wait: wait until operation completes. Returns: This instance of :class:`.PostgresNode`. diff --git a/tests/test_simple.py b/tests/test_simple.py index bbb1b9bc..b8670aed 100755 --- a/tests/test_simple.py +++ b/tests/test_simple.py @@ -376,7 +376,15 @@ def test_backup_wrong_xlog_method(self): def test_pg_ctl_wait_option(self): with get_new_node() as node: node.init().start(wait=False) - node.stop(wait=False) + while True: + try: + node.stop(wait=False) + except ExecUtilException: + # it's ok to break here since node could be not + # started yet + continue + else: + break def test_replicate(self): with get_new_node() as node: From 2dc0659889ccf714ef4092d0e849be1566f14f60 Mon Sep 17 00:00:00 2001 From: Ildus Kurbangaliev Date: Tue, 10 Apr 2018 13:23:51 +0300 Subject: [PATCH 3/3] Refactor test for test option --- tests/test_simple.py | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/tests/test_simple.py b/tests/test_simple.py index b8670aed..9818e6a3 100755 --- a/tests/test_simple.py +++ b/tests/test_simple.py @@ -379,12 +379,11 @@ def test_pg_ctl_wait_option(self): while True: try: node.stop(wait=False) - except ExecUtilException: - # it's ok to break here since node could be not - # started yet - continue - else: 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: