Skip to content

Commit ca00a9e

Browse files
StopNodeException is added
Also: - New class NodeException is a base class for Start/Stop node exceptions
1 parent 9f87334 commit ca00a9e

6 files changed

Lines changed: 78 additions & 3 deletions

File tree

‎src/__init__.py‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
TimeoutException, \
2525
CatchUpException, \
2626
StartNodeException, \
27+
StopNodeException, \
2728
InitNodeException, \
2829
BackupException, \
2930
InvalidOperationException
@@ -73,6 +74,7 @@
7374
"QueryTimeoutException",
7475
"TimeoutException", "CatchUpException", "StartNodeException", "InitNodeException", "BackupException", "InvalidOperationException",
7576
"XLogMethod", "IsolationLevel", "NodeStatus", "ProcessType", "DumpFormat",
77+
"StopNodeException",
7678
"NodeApp",
7779
"PostgresNode",
7880
"PortManager",

‎src/exceptions.py‎

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ def __repr__(self) -> str:
160160
return result
161161

162162

163-
class StartNodeException(TestgresException):
163+
class NodeException(TestgresException):
164164
_description: typing.Optional[str]
165165
_files: typing.Optional[typing.Iterable]
166166

@@ -224,6 +224,14 @@ def __repr__(self) -> str:
224224
return result
225225

226226

227+
class StartNodeException(NodeException):
228+
pass
229+
230+
231+
class StopNodeException(NodeException):
232+
pass
233+
234+
227235
class InitNodeException(TestgresException):
228236
_message: typing.Optional[str]
229237

‎src/node.py‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
QueryException, \
4747
QueryTimeoutException, \
4848
StartNodeException, \
49+
StopNodeException, \
4950
TimeoutException, \
5051
InitNodeException, \
5152
TestgresException, \
@@ -1410,6 +1411,10 @@ def stop(
14101411
logfile=self.utils_log_file,
14111412
)
14121413
self._manually_started_pm_pid = None
1414+
except ExecUtilException as e:
1415+
msg = 'Cannot stop node'
1416+
files = self._collect_special_files()
1417+
raise StopNodeException(msg, files) from e
14131418
finally:
14141419
# always stop the reader thread, even if pg_ctl stop failed,
14151420
# so it can't leak into interpreter shutdown.

‎tests/test_testgres_common.py‎

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838

3939
from src import InitNodeException
4040
from src import StartNodeException
41+
from src import StopNodeException
4142
from src import QueryException
4243
from src import ExecUtilException
4344
from src import QueryTimeoutException
@@ -539,6 +540,9 @@ def helper_step_of_failure_during_slow_start(
539540
assert "Connection reset by peer" in str(x.value)
540541
return False
541542

543+
if type(x.value) is StopNodeException:
544+
return True
545+
542546
assert not node.is_started
543547
assert node.status() == NodeStatus.Stopped
544548

@@ -642,7 +646,11 @@ def test_double_stop(self, node_svc: PostgresNodeService):
642646
node.stop()
643647

644648
assert x is not None
645-
assert "Is server running?" in str(x.value)
649+
e1 = x.value
650+
assert type(e1) is StopNodeException
651+
e2 = e1.__cause__
652+
assert type(e2) is ExecUtilException
653+
assert "Is server running?" in str(e2)
646654

647655
assert not node.is_started
648656

@@ -2038,7 +2046,7 @@ def impl__test_pg_ctl_wait_option(
20382046
try:
20392047
node.stop(wait=False)
20402048
break
2041-
except ExecUtilException as e:
2049+
except StopNodeException as e:
20422050
# it's ok to get this exception here since node
20432051
# could be not started yet
20442052
logging.info("Node is not stopped. Exception ({0}): {1}".format(type(e).__name__, e))

‎tests/units/exceptions/StopNodeException/__init__.py‎

Whitespace-only changes.
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
from src.exceptions import StopNodeException
2+
from src.exceptions import TestgresException as testgres__TestgresException
3+
4+
5+
class TestSet001_Constructor:
6+
def test_001__default(self):
7+
e = StopNodeException()
8+
assert type(e) is StopNodeException
9+
assert isinstance(e, testgres__TestgresException)
10+
assert e.source is None
11+
assert e.message == ""
12+
assert e.description is None
13+
assert e.files is None
14+
assert str(e) == ""
15+
assert repr(e) == "StopNodeException()"
16+
return
17+
18+
def test_002__message(self):
19+
e = StopNodeException(message="abc\n123")
20+
assert type(e) is StopNodeException
21+
assert isinstance(e, testgres__TestgresException)
22+
assert e.source is None
23+
assert e.message == "abc\n123"
24+
assert e.description == "abc\n123"
25+
assert e.files is None
26+
assert str(e) == "abc\n123"
27+
assert repr(e) == "StopNodeException(message='abc\\n123')"
28+
return
29+
30+
def test_003__files(self):
31+
e = StopNodeException(files=[("f\n1", b'line1\nline2')])
32+
assert type(e) is StopNodeException
33+
assert isinstance(e, testgres__TestgresException)
34+
assert e.source is None
35+
assert e.message == "f\n1\n----\nb'line1\\nline2'\n"
36+
assert e.description is None
37+
assert e.files == [("f\n1", b'line1\nline2')]
38+
assert str(e) == "f\n1\n----\nb'line1\\nline2'\n"
39+
assert repr(e) == "StopNodeException(files=[('f\\n1', b'line1\\nline2')])"
40+
return
41+
42+
def test_004__all(self):
43+
e = StopNodeException(message="mmm", files=[("f\n1", b'line1\nline2')])
44+
assert type(e) is StopNodeException
45+
assert isinstance(e, testgres__TestgresException)
46+
assert e.source is None
47+
assert e.message == "mmm\nf\n1\n----\nb'line1\\nline2'\n"
48+
assert e.description == "mmm"
49+
assert e.files == [("f\n1", b'line1\nline2')]
50+
assert str(e) == "mmm\nf\n1\n----\nb'line1\\nline2'\n"
51+
assert repr(e) == "StopNodeException(message='mmm', files=[('f\\n1', b'line1\\nline2')])"
52+
return

0 commit comments

Comments
 (0)