Navigation Menu

Skip to content

Commit

Permalink
run-regression-test: restart groonga per 100 commands
Browse files Browse the repository at this point in the history
It's caused only when --cache-base-path option is used.
  • Loading branch information
kou committed Apr 24, 2017
1 parent 9fe8da9 commit 88ea45a
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 26 deletions.
36 changes: 18 additions & 18 deletions lib/groonga/query-log/command/run-regression-test.rb
Expand Up @@ -228,7 +228,7 @@ def run
retry
end

yield
yield if block_given?
end

def ensure_database
Expand Down Expand Up @@ -273,14 +273,6 @@ def shutdown
Process.waitpid(@pid)
end

def restart
self.shutdown
run_thread = Thread.new do
self.run{}
end
run_thread.join
end

private
def find_unused_port
server = TCPServer.new(@host, 0)
Expand Down Expand Up @@ -372,16 +364,24 @@ def run_test
puts("Running test against query log...: #{query_log_path}")
end
begin
verify_server(log_path, query_log_path)
if @old.use_persistent_cache? or @new.use_persistent_cache?
callback = lambda do
if @old.use_persistent_cache?
@old.shutdown
@old.run
end
if @new.use_persistent_cache?
@new.shutdown
@new.run
end
end
else
callback = nil
end
verify_server(log_path, query_log_path, &callback)
rescue Interrupt
puts("Interrupt: #{query_log_path}")
end
if @new.use_persistent_cache?
@new.restart
end
if @old.use_persistent_cache?
@old.restart
end
end

old_thread = Thread.new do
Expand All @@ -396,7 +396,7 @@ def run_test
true
end

def verify_server(test_log_path, query_log_path)
def verify_server(test_log_path, query_log_path, &callback)
command_line = [
"--n-clients=#{@n_clients}",
"--groonga1-host=#{@old.host}",
Expand All @@ -413,7 +413,7 @@ def verify_server(test_log_path, query_log_path)
command_line << "--verify-cache"
end
verify_server = VerifyServer.new
verify_server.run(command_line)
verify_server.run(command_line, &callback)
end

def query_log_paths
Expand Down
6 changes: 3 additions & 3 deletions lib/groonga/query-log/command/verify-server.rb
Expand Up @@ -26,15 +26,15 @@ def initialize
@options = ServerVerifier::Options.new
end

def run(command_line)
def run(command_line, &callback)
input_paths = create_parser.parse(command_line)
verifier = ServerVerifier.new(@options)
if input_paths.empty?
verifier.verify($stdin)
verifier.verify($stdin, &callback)
else
input_paths.each do |input_path|
File.open(input_path) do |input|
verifier.verify(input)
verifier.verify(input, &callback)
end
end
end
Expand Down
23 changes: 18 additions & 5 deletions lib/groonga/query-log/server-verifier.rb
Expand Up @@ -31,29 +31,42 @@ def initialize(options)
@different_results = Queue.new
end

def verify(input)
producer = run_producer(input)
consumers = run_consumers
def verify(input, &callback)
producer = run_producer(input, &callback)
reporter = run_reporter
producer.join
consumers.each(&:join)
@different_results.push(nil)
reporter.join
end

private
def run_producer(input)
def run_producer(input, &callback)
Thread.new do
consumers = run_consumers

parser = Parser.new
n_commands = 0
callback_per_n_commands = 100
parser.parse(input) do |statistic|
command = statistic.command
next if command.nil?
next unless target_command?(command)
n_commands += 1
@queue.push(statistic)

if callback and (n_commands % callback_per_n_commands).zero?
@options.n_clients.times do
@queue.push(nil)
end
consumers.each(&:join)
callback.call
consumers = run_consumers
end
end
@options.n_clients.times do
@queue.push(nil)
end
consumers.each(&:join)
end
end

Expand Down

0 comments on commit 88ea45a

Please sign in to comment.