Skip to content

Fix error handling and port management for Windows #172

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
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion testgres/node.py
Original file line number Diff line number Diff line change
Expand Up @@ -791,8 +791,9 @@ def start(self, params=[], wait=True):
"start"] + params # yapf: disable

def LOCAL__start_node():
# 'error' will be None on Windows
_, _, error = execute_utility(_params, self.utils_log_file, verbose=True)
assert type(error) == str # noqa: E721
assert error is None or type(error) == str # noqa: E721
if error and 'does not exist' in error:
raise Exception(error)

Expand Down
14 changes: 7 additions & 7 deletions tests/test_simple.py
Original file line number Diff line number Diff line change
Expand Up @@ -1054,7 +1054,7 @@ def test_the_same_port(self):
self.assertTrue(node._should_free_port)
self.assertEqual(type(node.port), int)
node_port_copy = node.port
self.assertEqual(node.safe_psql("SELECT 1;"), b'1\n')
self.assertEqual(rm_carriage_returns(node.safe_psql("SELECT 1;")), b'1\n')

with get_new_node(port=node.port) as node2:
self.assertEqual(type(node2.port), int)
Expand All @@ -1069,7 +1069,7 @@ def test_the_same_port(self):
# node is still working
self.assertEqual(node.port, node_port_copy)
self.assertTrue(node._should_free_port)
self.assertEqual(node.safe_psql("SELECT 3;"), b'3\n')
self.assertEqual(rm_carriage_returns(node.safe_psql("SELECT 3;")), b'3\n')

class tagPortManagerProxy:
sm_prev_testgres_reserve_port = None
Expand Down Expand Up @@ -1175,7 +1175,7 @@ def test_port_rereserve_during_node_start(self):
self.assertTrue(node1._should_free_port)
self.assertEqual(type(node1.port), int) # noqa: E721
node1_port_copy = node1.port
self.assertEqual(node1.safe_psql("SELECT 1;"), b'1\n')
self.assertEqual(rm_carriage_returns(node1.safe_psql("SELECT 1;")), b'1\n')

with __class__.tagPortManagerProxy(node1.port, C_COUNT_OF_BAD_PORT_USAGE):
assert __class__.tagPortManagerProxy.sm_DummyPortNumber == node1.port
Expand All @@ -1191,12 +1191,12 @@ def test_port_rereserve_during_node_start(self):
self.assertEqual(__class__.tagPortManagerProxy.sm_DummyPortTotalUsage, C_COUNT_OF_BAD_PORT_USAGE)
self.assertTrue(node2.is_started)

self.assertEqual(node2.safe_psql("SELECT 2;"), b'2\n')
self.assertEqual(rm_carriage_returns(node2.safe_psql("SELECT 2;")), b'2\n')

# node1 is still working
self.assertEqual(node1.port, node1_port_copy)
self.assertTrue(node1._should_free_port)
self.assertEqual(node1.safe_psql("SELECT 3;"), b'3\n')
self.assertEqual(rm_carriage_returns(node1.safe_psql("SELECT 3;")), b'3\n')

def test_port_conflict(self):
assert testgres.PostgresNode._C_MAX_START_ATEMPTS > 1
Expand All @@ -1208,7 +1208,7 @@ def test_port_conflict(self):
self.assertTrue(node1._should_free_port)
self.assertEqual(type(node1.port), int) # noqa: E721
node1_port_copy = node1.port
self.assertEqual(node1.safe_psql("SELECT 1;"), b'1\n')
self.assertEqual(rm_carriage_returns(node1.safe_psql("SELECT 1;")), b'1\n')

with __class__.tagPortManagerProxy(node1.port, C_COUNT_OF_BAD_PORT_USAGE):
assert __class__.tagPortManagerProxy.sm_DummyPortNumber == node1.port
Expand All @@ -1233,7 +1233,7 @@ def test_port_conflict(self):
# node1 is still working
self.assertEqual(node1.port, node1_port_copy)
self.assertTrue(node1._should_free_port)
self.assertEqual(node1.safe_psql("SELECT 3;"), b'3\n')
self.assertEqual(rm_carriage_returns(node1.safe_psql("SELECT 3;")), b'3\n')

def test_simple_with_bin_dir(self):
with get_new_node() as node:
Expand Down