Skip to content

Commit

Permalink
Add --timeout
Browse files Browse the repository at this point in the history
  • Loading branch information
kou committed Apr 27, 2016
1 parent c12e8b9 commit a4e3f7b
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
10 changes: 9 additions & 1 deletion lib/grntest/test-runner.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
require "pathname"
require "fileutils"
require "tempfile"
require "timeout"

require "json"

Expand Down Expand Up @@ -135,7 +136,14 @@ def execute_groonga_script(result)
@tester.groonga_suggest_create_dataset
context.output_type = @tester.output_type
run_groonga(context) do |executor|
executor.execute(test_script_path)
begin
Timeout.timeout(@tester.timeout) do
executor.execute(test_script_path)
end
rescue Timeout::Error
message = "# error: timeout (#{@tester.timeout}s)"
context.result << [:error, message, {}]
end
end
check_memory_leak(context)
result.omitted = context.omitted?
Expand Down
8 changes: 8 additions & 0 deletions lib/grntest/tester.rb
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,12 @@ def create_option_parser(tester, tag)
tester.use_color = use_color
end

parser.on("--timeout=SECOND", Float,
"Timeout for each test",
"(#{tester.timeout})") do |timeout|
tester.timeout = timeout
end

parser.on("--version",
"Show version and exit") do
puts(VERSION)
Expand Down Expand Up @@ -247,6 +253,7 @@ def parse_name_or_pattern(name)
attr_accessor :output
attr_accessor :gdb, :default_gdb
attr_accessor :valgrind, :default_valgrind
attr_accessor :timeout
attr_writer :valgrind_gen_suppressions
attr_writer :reporter, :keep_database, :use_color
attr_writer :stop_on_failure
Expand Down Expand Up @@ -279,6 +286,7 @@ def initialize
detect_suitable_diff
initialize_debuggers
initialize_memory_checkers
@timeout = 5
end

def run(*targets)
Expand Down

0 comments on commit a4e3f7b

Please sign in to comment.