Skip to content

Commit

Permalink
[tests] try to use shorter socket filenames
Browse files Browse the repository at this point in the history
Change-Id: I7f59268078f2178910de3425a0b68a8e5113b071
  • Loading branch information
stbuehler committed Jan 13, 2024
1 parent 643514a commit d9e4b2e
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 9 deletions.
13 changes: 10 additions & 3 deletions tests/pylt/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,15 @@ def __init__(self, *, tests: base.Tests) -> None:
self.proc: typing.Optional[subprocess.Popen] = None
self.failed = False

def bind_unix_socket(self, *, sockfile: str, backlog: int = 8) -> socket.socket:
sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
rel_sockfile = os.path.relpath(sockfile)
if len(rel_sockfile) < len(sockfile):
sockfile = rel_sockfile
sock.bind(sockfile)
sock.listen(8)
return sock

def fork(self, *args: str, inp: typing.Union[tuple[()], FileWithFd, None] = ()) -> None:
arguments = list(args) # convert tuple to list
stdin: typing.Optional[FileWithFd]
Expand Down Expand Up @@ -245,9 +254,7 @@ def __init__(self, *, tests: base.Tests) -> None:
def prepare_service(self) -> None:
assert self.tests
self.tests.install_dir(os.path.join("tmp", "sockets"))
sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
sock.bind(os.path.relpath(self.sockfile))
sock.listen(8)
sock = self.bind_unix_socket(sockfile=self.sockfile)
self.fork(*self.binary, inp=sock)

def cleanup_service(self) -> None:
Expand Down
4 changes: 1 addition & 3 deletions tests/pylt/tests/t-memcached.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,7 @@ def __init__(self, *, tests: base.Tests) -> None:
def prepare_service(self) -> None:
assert self.tests
self.tests.install_dir(os.path.join("tmp", "sockets"))
sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
sock.bind(os.path.relpath(self.sockfile))
sock.listen(8)
sock = self.bind_unix_socket(sockfile=self.sockfile)
self.fork(*self.binary, inp=sock)

def cleanup_service(self) -> None:
Expand Down
4 changes: 1 addition & 3 deletions tests/pylt/tests/t-scgi.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,7 @@ def __init__(self, *, tests: base.Tests) -> None:
def prepare_service(self) -> None:
assert self.tests
self.tests.install_dir(os.path.join("tmp", "sockets"))
sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
sock.bind(os.path.relpath(self.sockfile))
sock.listen(8)
sock = self.bind_unix_socket(sockfile=self.sockfile)
self.fork(*self.binary, inp=sock)

def cleanup_service(self) -> None:
Expand Down

0 comments on commit d9e4b2e

Please sign in to comment.