test: add flag to retry.

This should allow better handling flaky tests.
This commit is contained in:
Mike McQuaid 2020-07-29 12:00:45 +01:00
parent 126e4c9df1
commit 92a39bc49e
No known key found for this signature in database
GPG Key ID: 48A898132FD8EE70
3 changed files with 22 additions and 1 deletions

View File

@ -25,6 +25,8 @@ module Homebrew
description: "Test the head version of a formula." description: "Test the head version of a formula."
switch "--keep-tmp", switch "--keep-tmp",
description: "Retain the temporary files created for the test." description: "Retain the temporary files created for the test."
switch "--retry",
description: "Retry if a testing fails."
switch :verbose switch :verbose
switch :debug switch :debug
conflicts "--devel", "--HEAD" conflicts "--devel", "--HEAD"
@ -70,7 +72,7 @@ module Homebrew
next next
end end
puts "Testing #{f.full_name}" oh1 "Testing #{f.full_name}"
env = ENV.to_hash env = ENV.to_hash
@ -108,6 +110,7 @@ module Homebrew
end end
end end
rescue Exception => e # rubocop:disable Lint/RescueException rescue Exception => e # rubocop:disable Lint/RescueException
retry if retry_test?(f)
ofail "#{f.full_name}: failed" ofail "#{f.full_name}: failed"
puts e, e.backtrace puts e, e.backtrace
ensure ensure
@ -115,4 +118,16 @@ module Homebrew
end end
end end
end end
def retry_test?(f)
@test_failed ||= Set.new
if args.retry? && @test_failed.add?(f)
oh1 "Testing #{f.full_name} (again)"
f.clear_cache
true
else
Homebrew.failed = true
false
end
end
end end

View File

@ -1036,6 +1036,8 @@ wrong with the installed formula.
Test the head version of a formula. Test the head version of a formula.
* `--keep-tmp`: * `--keep-tmp`:
Retain the temporary files created for the test. Retain the temporary files created for the test.
* `--retry`:
Retry if a testing fails.
### `tests` [*`options`*] ### `tests` [*`options`*]

View File

@ -1351,6 +1351,10 @@ Test the head version of a formula\.
\fB\-\-keep\-tmp\fR \fB\-\-keep\-tmp\fR
Retain the temporary files created for the test\. Retain the temporary files created for the test\.
. .
.TP
\fB\-\-retry\fR
Retry if a testing fails\.
.
.SS "\fBtests\fR [\fIoptions\fR]" .SS "\fBtests\fR [\fIoptions\fR]"
Run Homebrew\'s unit and integration tests\. Run Homebrew\'s unit and integration tests\.
. .