- Notifications
You must be signed in to change notification settings - Fork35
Fix initdb error on Windows#99
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Merged
Uh oh!
There was an error while loading.Please reload this page.
Merged
Changes fromall commits
Commits
Show all changes
5 commits Select commitHold shift + click to select a range
edb5708
Fix initdb error on Windows
036b924
Fix initdb error on Windows - fix pgbench
05cd996
Fix initdb error on Windows - fix pgbench
de1ce5c
Merge branch 'fix-initdb-error' of github.com:postgrespro/testgres in…
demonolock901a639
Refactoring local_ops.py
demonolockFile filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
There are no files selected for viewing
8 changes: 4 additions & 4 deletionssetup.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
4 changes: 3 additions & 1 deletiontestgres/__init__.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
Empty file addedtestgres/helpers/__init__.py
Empty file.
40 changes: 40 additions & 0 deletionstestgres/helpers/port_manager.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import socket | ||
import random | ||
from typing import Set, Iterable, Optional | ||
class PortForException(Exception): | ||
pass | ||
class PortManager: | ||
def __init__(self, ports_range=(1024, 65535)): | ||
self.ports_range = ports_range | ||
@staticmethod | ||
def is_port_free(port: int) -> bool: | ||
"""Check if a port is free to use.""" | ||
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s: | ||
try: | ||
s.bind(("", port)) | ||
return True | ||
except OSError: | ||
return False | ||
def find_free_port(self, ports: Optional[Set[int]] = None, exclude_ports: Optional[Iterable[int]] = None) -> int: | ||
"""Return a random unused port number.""" | ||
if ports is None: | ||
ports = set(range(1024, 65535)) | ||
if exclude_ports is None: | ||
exclude_ports = set() | ||
ports.difference_update(set(exclude_ports)) | ||
sampled_ports = random.sample(tuple(ports), min(len(ports), 100)) | ||
for port in sampled_ports: | ||
if self.is_port_free(port): | ||
return port | ||
raise PortForException("Can't select a port") |
8 changes: 4 additions & 4 deletionstestgres/node.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
133 changes: 74 additions & 59 deletionstestgres/operations/local_ops.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
8 changes: 7 additions & 1 deletiontestgres/operations/os_ops.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
Oops, something went wrong.
Uh oh!
There was an error while loading.Please reload this page.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.