fix agent stall when also using web argument

This commit is contained in:
Colin Surprenant 2014-03-27 20:03:32 -04:00
parent 6350d68639
commit 323f42fdfd
2 changed files with 59 additions and 4 deletions

View file

@ -56,6 +56,10 @@ I18n.load_path << File.expand_path(
class LogStash::Runner
include LogStash::Program
def initialize
@runners = []
end
def main(args)
require "logstash/util"
require "stud/trap"
@ -74,7 +78,6 @@ class LogStash::Runner
args = [nil] if args.empty?
@runners = []
while args != nil && !args.empty?
args = run(args)
end
@ -187,15 +190,16 @@ class LogStash::Runner
agent = LogStash::Agent.new($0)
begin
agent.parse(args)
@runners << Stud::Task.new { agent.execute }
rescue Clamp::HelpWanted => e
puts e.command.help
show_help(e.command)
return []
rescue Clamp::UsageError => e
# If 'too many arguments' then give the arguments to
# the next command. Otherwise it's a real error.
raise if e.message != "too many arguments"
remaining = agent.remaining_arguments
end
@runners << Stud::Task.new { agent.execute }
return remaining
end
@ -229,8 +233,17 @@ class LogStash::Runner
return args
end # def run
def self.valid_caller?
caller.none?{|entry| entry =~ /rspec/}
end
private
def show_help(command)
puts command.help
end
end # class LogStash::Runner
if $0 == __FILE__
if $0 == __FILE__ && LogStash::Runner.valid_caller?
LogStash::Runner.new.main(ARGV)
end

42
spec/runner_spec.rb Normal file
View file

@ -0,0 +1,42 @@
require "logstash/runner"
require "logstash/agent"
require "logstash/kibana"
require "stud/task"
class NullRunner
def run(args); end
end
describe LogStash::Runner do
context "argument parsing" do
it "should run agent" do
expect(Stud::Task).to receive(:new).once.and_return(nil)
args = ["agent", "-e", ""]
expect(subject.run(args)).to eq(nil)
end
it "should run agent help" do
expect(subject).to receive(:show_help).once.and_return(nil)
args = ["agent", "-h"]
expect(subject.run(args)).to eq([])
end
it "should run agent help and not run following commands" do
expect(subject).to receive(:show_help).once.and_return(nil)
args = ["agent", "-h", "web"]
expect(subject.run(args)).to eq([])
end
it "should run agent and web" do
expect(Stud::Task).to receive(:new).once
args = ["agent", "-e", "", "web"]
args = subject.run(args)
expect(args).to eq(["web"])
expect(LogStash::Kibana::Runner).to receive(:new).once.and_return(NullRunner.new)
args = subject.run(args)
expect(args).to eq(nil)
end
end
end