Skip to content
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

Make openqa-cli retry also on connection errors #5359

Merged
merged 1 commit into from
Nov 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/OpenQA/Command.pm
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ sub retry_tx ($self, $client, $tx, $retries = undef, $delay = undef) {
for (;; --$retries) {
$tx = $client->start($tx);
my $res_code = $tx->res->code // 0;
return $self->handle_result($tx) unless $res_code =~ /50[23]/ && $retries > 0;
return $self->handle_result($tx) unless $res_code =~ /^(50[23]|0)$/ && $retries > 0;
print encode('UTF-8',
"Request failed, hit error $res_code, retrying up to $retries more times after waiting …\n");
sleep $delay;
Expand Down
5 changes: 5 additions & 0 deletions t/43-cli-api.t
Original file line number Diff line number Diff line change
Expand Up @@ -451,6 +451,11 @@ EOF

($stdout, $stderr, @result) = capture sub { $api->run('--retries', '1', @params) };
like $stdout, qr/failed.*retrying/, 'requests are retried on error if requested';

@params = ('--host', 'http://localhost:123456', '--retries', 1, 'api', 'test');
($stdout, $stderr, @result) = capture sub { $api->run(@params) };
like $stderr, qr/Connection refused/, 'aborts on connection refused';
like $stdout, qr/failed.*retrying/, 'requests are retried on error if requested';
};

subtest 'Pretty print JSON' => sub {
Expand Down
Loading