Commit 2ce12f3f authored by Profpatsch's avatar Profpatsch

nixos/tests: set timeout for retry & port check

All functions are currently fixed to time out after 899 seconds, which is a bit
long in most cases.
parent 15c8a96b
......@@ -227,6 +227,18 @@ sub retry {
die "action timed out after $n seconds";
}
# Call the given code reference repeatedly, with 1 second intervals,
# until it returns 1 or a timeout is reached.
sub retryTimeout {
my ($timeout, $coderef) = @_;
my $n;
for ($n = $timeout; $n >0; $n--) {
return if &$coderef($n);
sleep 1;
}
die "action timed out after $timeout seconds";
}
sub connect {
my ($self) = @_;
......@@ -462,6 +474,16 @@ sub waitForOpenPort {
});
}
sub waitForOpenPortTimeout {
my ($self, $port, $timeout) = @_;
$self->nest("waiting for TCP port $port", sub {
retryTimeout($timeout, sub {
my ($status, $out) = $self->execute("nc -z localhost $port");
return 1 if $status == 0;
})
});
}
# Wait until the machine is not listening on the given TCP port.
sub waitForClosedPort {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment