Skip to content

Commit

Permalink
Add --read-timeout
Browse files Browse the repository at this point in the history
  • Loading branch information
kou committed Jan 18, 2018
1 parent 12618d8 commit 47a709d
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 15 deletions.
8 changes: 6 additions & 2 deletions lib/grntest/execution-context.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 All @@ -23,7 +23,9 @@ class ExecutionContext
attr_accessor :on_error
attr_accessor :abort_tag
attr_accessor :timeout
attr_accessor :read_timeout
attr_accessor :default_timeout
attr_accessor :default_read_timeout
attr_writer :suppress_backtrace
attr_writer :collect_query_log
attr_writer :debug
Expand All @@ -41,7 +43,9 @@ def initialize
@on_error = :default
@abort_tag = nil
@timeout = 0
@default_timeout = 0
@read_timeout = 3
@default_timeout = @timeout
@default_read_timeout = @read_timeout
@omitted = false
@suppress_backtrace = true
@collect_query_log = false
Expand Down
14 changes: 4 additions & 10 deletions lib/grntest/executors/base-executor.rb
@@ -1,4 +1,4 @@
# Copyright (C) 2012-2017 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 @@ -39,9 +39,7 @@ def initialize(context)
@loading = false
@pending_command = ""
@pending_load_command = nil
@current_command_name = nil
@output_type = nil
@read_timeout = default_read_timeout
@long_read_timeout = default_long_read_timeout
@context = context
@custom_important_log_levels = []
Expand Down Expand Up @@ -223,8 +221,8 @@ def execute_directive_read_timeout(line, content, options)
new_value = timeout_value("read-timeout",
line,
timeout,
default_read_timeout)
@read_timeout = new_value unless new_value.nil?
@context.default_read_timeout)
@context.read_timeout = new_value unless new_value.nil?
end

def execute_directive_long_read_timeout(line, content, options)
Expand Down Expand Up @@ -441,7 +439,7 @@ def extract_important_messages(log)

def read_all_readable_content(output, options={})
content = ""
first_timeout = options[:first_timeout] || @read_timeout
first_timeout = options[:first_timeout] || @context.read_timeout
timeout = first_timeout
while IO.select([output], [], [], timeout)
break if output.eof?
Expand Down Expand Up @@ -552,10 +550,6 @@ def debug_output(output)
output
end

def default_read_timeout
3
end

def default_long_read_timeout
180
end
Expand Down
4 changes: 1 addition & 3 deletions lib/grntest/executors/standard-io-executor.rb
@@ -1,6 +1,4 @@
# -*- coding: utf-8 -*-
#
# Copyright (C) 2012-2013 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
2 changes: 2 additions & 0 deletions lib/grntest/test-runner.rb
Expand Up @@ -140,7 +140,9 @@ def execute_groonga_script(result)
context.output_type = @tester.output_type
context.timeout = @tester.timeout
context.timeout = 0 if @tester.gdb
context.read_timeout = @tester.read_timeout
context.default_timeout = context.timeout
context.default_read_timeout = context.read_timeout
context.suppress_backtrace = @tester.suppress_backtrace?
context.debug = @tester.debug?
run_groonga(context) do |executor|
Expand Down
8 changes: 8 additions & 0 deletions lib/grntest/tester.rb
Expand Up @@ -218,6 +218,12 @@ def create_option_parser(tester, tag)
tester.timeout = timeout
end

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

parser.on("--[no-]debug",
"Enable debug information",
"(#{tester.debug?})") do |debug|
Expand Down Expand Up @@ -266,6 +272,7 @@ def parse_name_or_pattern(name)
attr_accessor :gdb, :default_gdb
attr_accessor :valgrind, :default_valgrind
attr_accessor :timeout
attr_accessor :read_timeout
attr_writer :valgrind_gen_suppressions
attr_writer :reporter, :keep_database, :use_color
attr_writer :stop_on_failure
Expand Down Expand Up @@ -303,6 +310,7 @@ def initialize
initialize_debuggers
initialize_memory_checkers
@timeout = 5
@read_timeout = 3
end

def run(*targets)
Expand Down

0 comments on commit 47a709d

Please sign in to comment.