Skip to content

Fix error 'Is another postmaster already running on port XXX' #120

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 1 commit into from
Apr 5, 2024
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
32 changes: 24 additions & 8 deletions testgres/node.py
Original file line number Diff line number Diff line change
Expand Up @@ -726,14 +726,30 @@ def start(self, params=[], wait=True):
"start"
] + params # yapf: disable

try:
exit_status, out, error = execute_utility(_params, self.utils_log_file, verbose=True)
if error and 'does not exist' in error:
raise Exception
except Exception as e:
msg = 'Cannot start node'
files = self._collect_special_files()
raise_from(StartNodeException(msg, files), e)
startup_retries = 5
while True:
try:
exit_status, out, error = execute_utility(_params, self.utils_log_file, verbose=True)
if error and 'does not exist' in error:
raise Exception
except Exception as e:
files = self._collect_special_files()
if any(len(file) > 1 and 'Is another postmaster already '
'running on port' in file[1].decode() for
file in files):
print("Detected an issue with connecting to port {0}. "
"Trying another port after a 5-second sleep...".format(self.port))
self.port = reserve_port()
options = {}
options['port'] = str(self.port)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

flake8 упал

  • flake8 .
    ./build/lib/testgres/node.py:737:21: F821 undefined name 'options'
    ./build/lib/testgres/node.py:738:40: F821 undefined name 'options'
    ./testgres/node.py:737:21: F821 undefined name 'options'
    ./testgres/node.py:738:40: F821 undefined name 'options'
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Переделала, тесты прошли

self.set_auto_conf(options)
startup_retries -= 1
time.sleep(5)
continue

msg = 'Cannot start node'
raise_from(StartNodeException(msg, files), e)
break
self._maybe_start_logger()
self.is_started = True
return self
Expand Down
8 changes: 8 additions & 0 deletions tests/test_simple.py
Original file line number Diff line number Diff line change
Expand Up @@ -1033,6 +1033,14 @@ def test_parse_pg_version(self):
# Macos
assert parse_pg_version("postgres (PostgreSQL) 14.9 (Homebrew)") == "14.9"

def test_the_same_port(self):
with get_new_node() as node:
node.init().start()

with get_new_node() as node2:
node2.port = node.port
node2.init().start()


if __name__ == '__main__':
if os.environ.get('ALT_CONFIG'):
Expand Down