mirror of
https://github.com/NixOS/nixpkgs.git
synced 2025-06-16 06:29:17 +03:00
nixos/test-driver: add optional address arg to wait_for_{open,closed}_port
This is useful for testing servers configured to listen on specific addresses.
This commit is contained in:
parent
904f07f595
commit
dba49a43a0
3 changed files with 16 additions and 12 deletions
|
@ -699,20 +699,22 @@ class Machine:
|
|||
with self.nested("waiting for file ‘{}‘".format(filename)):
|
||||
retry(check_file)
|
||||
|
||||
def wait_for_open_port(self, port: int) -> None:
|
||||
def wait_for_open_port(self, port: int, addr: str = "localhost") -> None:
|
||||
def port_is_open(_: Any) -> bool:
|
||||
status, _ = self.execute("nc -z localhost {}".format(port))
|
||||
status, _ = self.execute("nc -z {} {}".format(addr, port))
|
||||
return status == 0
|
||||
|
||||
with self.nested("waiting for TCP port {}".format(port)):
|
||||
with self.nested("waiting for TCP port {} on {}".format(port, addr)):
|
||||
retry(port_is_open)
|
||||
|
||||
def wait_for_closed_port(self, port: int) -> None:
|
||||
def wait_for_closed_port(self, port: int, addr: str = "localhost") -> None:
|
||||
def port_is_closed(_: Any) -> bool:
|
||||
status, _ = self.execute("nc -z localhost {}".format(port))
|
||||
status, _ = self.execute("nc -z {} {}".format(addr, port))
|
||||
return status != 0
|
||||
|
||||
with self.nested("waiting for TCP port {} to be closed".format(port)):
|
||||
with self.nested(
|
||||
"waiting for TCP port {} on {} to be closed".format(port, addr)
|
||||
):
|
||||
retry(port_is_closed)
|
||||
|
||||
def start_job(self, jobname: str, user: Optional[str] = None) -> Tuple[int, str]:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue