Class: Grntest::Executors::BaseExecutor

Inherits:
Object
  • Object
show all
Defined in:
lib/grntest/executors/base-executor.rb

Direct Known Subclasses

HTTPExecutor, StandardIOExecutor

Defined Under Namespace

Modules: ReturnCode

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(context) ⇒ BaseExecutor

Returns a new instance of BaseExecutor.



38
39
40
41
42
43
44
45
46
# File 'lib/grntest/executors/base-executor.rb', line 38

def initialize(context)
  @loading = false
  @pending_command = ""
  @pending_load_command = nil
  @output_type = nil
  @long_read_timeout = default_long_read_timeout
  @context = context
  @custom_important_log_levels = []
end

Instance Attribute Details

#contextObject (readonly)

Returns the value of attribute context.



37
38
39
# File 'lib/grntest/executors/base-executor.rb', line 37

def context
  @context
end

Instance Method Details

#execute(script_path) ⇒ Object



48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# File 'lib/grntest/executors/base-executor.rb', line 48

def execute(script_path)
  unless script_path.exist?
    raise NotExist.new(script_path)
  end

  @context.execute do
    script_path.open("r:ascii-8bit") do |script_file|
      parser = create_parser
      script_file.each_line do |line|
        begin
          parser << line
        rescue Error, Groonga::Command::Parser::Error
          line_info = "#{script_path}:#{script_file.lineno}:#{line.chomp}"
          log_error("#{line_info}: #{$!.message.b}")
          if $!.is_a?(Groonga::Command::Parser::Error)
            @context.abort
          else
            log_error("#{line_info}: #{$!.message.b}")
            raise unless @context.top_level?
          end
        end
      end
    end
  end

  @context.result
end

#shutdown(pid) ⇒ Object



76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
# File 'lib/grntest/executors/base-executor.rb', line 76

def shutdown(pid)
  begin
    Timeout.timeout(@context.timeout) do
      send_command(command("shutdown"))
    end
  rescue
    return false
  end

  status = nil
  total_sleep_time = 0
  sleep_time = 0.05
  loop do
    _, status = Process.waitpid2(pid, Process::WNOHANG)
    break if status
    sleep(sleep_time)
    total_sleep_time += sleep_time
    return false if total_sleep_time > context.shutdown_wait_timeout
  end

  log_error(read_all_log) unless status.success?
  true
end