Navigation Menu

Skip to content

Commit

Permalink
Add --n-retries option
Browse files Browse the repository at this point in the history
  • Loading branch information
kou committed Feb 19, 2018
1 parent 8a5caaf commit 76b2625
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 8 deletions.
10 changes: 9 additions & 1 deletion lib/grntest/tester.rb
@@ -1,4 +1,4 @@
# Copyright (C) 2012-2016 Kouhei Sutou <kou@clear-code.com>
# Copyright (C) 2012-2018 Kouhei Sutou <kou@clear-code.com>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
Expand Down Expand Up @@ -230,6 +230,12 @@ def create_option_parser(tester, tag)
tester.debug = debug
end

parser.on("--n-retries=N", Integer,
"Retry N times on failure",
"(#{tester.n_retries}") do |n|
tester.n_retries = n
end

parser.on("--version",
"Show version and exit") do
puts(VERSION)
Expand Down Expand Up @@ -281,6 +287,7 @@ def parse_name_or_pattern(name)
attr_writer :debug
attr_reader :test_patterns, :test_suite_patterns
attr_reader :exclude_test_patterns, :exclude_test_suite_patterns
attr_accessor :n_retries
def initialize
@groonga = "groonga"
@groonga_httpd = "groonga-httpd"
Expand Down Expand Up @@ -311,6 +318,7 @@ def initialize
initialize_memory_checkers
@timeout = 5
@read_timeout = 3
@n_retries = 0
end

def run(*targets)
Expand Down
39 changes: 32 additions & 7 deletions lib/grntest/worker.rb
@@ -1,4 +1,4 @@
# Copyright (C) 2012-2016 Kouhei Sutou <kou@clear-code.com>
# Copyright (C) 2012-2018 Kouhei Sutou <kou@clear-code.com>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
Expand Down Expand Up @@ -99,12 +99,13 @@ def run(queue)
@suite_name = suite_name
@reporter.on_suite_start(self)
end
@test_script_path = test_script_path
@test_name = test_name
runner = TestRunner.new(@tester, self)
succeeded = false unless runner.run

unless run_test(test_script_path, test_name)
succeeded = false
end

break if interruptted?

if @tester.stop_on_failure? and @test_suites_result.have_failure?
break
end
Expand Down Expand Up @@ -162,8 +163,32 @@ def on_test_no_check(result)
def on_test_finish(result)
@result.on_test_finish
@reporter.on_test_finish(self, result)
@test_script_path = nil
@test_name = nil
end

private
def run_test(test_script_path, test_name)
begin
@test_script_path = test_script_path
@test_name = test_name

n = -1
loop do
n += 1

runner = TestRunner.new(@tester, self)
return true if runner.run

if n < @tester.n_retries and not interruptted?
@test_suites_result.n_total_tests += 1
next
end

return false
end
ensure
@test_script_path = nil
@test_name = nil
end
end
end
end

0 comments on commit 76b2625

Please sign in to comment.