Skip to content
This repository has been archived by the owner on May 2, 2021. It is now read-only.

Commit

Permalink
- fix runners and test launcher
Browse files Browse the repository at this point in the history
  • Loading branch information
jordansissel committed Jul 1, 2011
1 parent 529e6c7 commit e98f463
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 91 deletions.
88 changes: 3 additions & 85 deletions bin/logstash-test
Original file line number Diff line number Diff line change
@@ -1,90 +1,8 @@
#!/usr/bin/env ruby

require "rubygems"
require "optparse"
$:.unshift "#{File.dirname(__FILE__)}/../lib"
$:.unshift "#{File.dirname(__FILE__)}/../test"

#require "logstash/test_syntax"
#require "logstash/filters/test_date"
#require "logstash/filters/test_multiline"

def check_lib(lib, provider, optional=true, message=nil)
begin
require lib
puts "+ Found #{optional ? "optional" : "required"} library '#{lib}'"
return { :optional => optional, :found => true }
rescue LoadError => e
puts "- Missing #{optional ? "optional" : "required"} library '#{lib}' - try 'gem install #{provider}'#{optional ? " if you want this library" : ""}. #{message}"
return { :optional => optional, :found => false }
end
end

def report_ruby_version
puts "Running #{RUBY_VERSION}p#{RUBY_PATCHLEVEL} on #{RUBY_PLATFORM}"
end

def check_libraries
results = []
results << check_lib("em-http-request", "em-http-request", true,
"needed for ElasticSearch input, output, and logstash-web support.")
results << check_lib("em-mongo", "em-mongo", true,
"needed for the mongodb output.")
results << check_lib("grok", "jls-grok", true,
"needed for the grok filter.")
results << check_lib("em-websocket", "em-websocket", true,
"needed for websocket output")
results << check_lib("rack", "rack", true,
"needed for logstash-web")
results << check_lib("thin", "thin", true,
"needed for logstash-web")
results << check_lib("amqp", "amqp", true,
"needed for AMQP input and output")
results << check_lib("sinatra/async", "async_sinatra", true,
"needed for logstash-web")
results << check_lib("uuidtools", "uuidtools", true,
"needed for AMQP input and output")
results << check_lib("ap", "awesome_print", true,
"improve logstash debug logging output")
results << check_lib("eventmachine", "eventmachine", false,
"required for logstash to function")
results << check_lib("json", "json", false,
"required for logstash to function")

missing_required = results.count { |r| !r[:optional] and !r[:found] }
if missing_required == 0
puts "All required libraries found :)"
else
suffix = (missing_required > 1) ? "ies" : "y"
puts "FATAL: Missing #{missing_required} required librar#{suffix}"
return false
end

return true
end

def run_tests
require "#{File.dirname(__FILE__)}/../test/run"
return Test::Unit::AutoRunner.run
end

def main(args)
report_ruby_version
# TODO(sissel): Add a way to call out specific things to test, like
# logstash-web, elasticsearch, mongodb, syslog, etc.
if !check_libraries
puts "Library check failed."
return 1
end

if !run_tests
puts "Test suite failed."
return 1
end

return 0
end

exit(main(ARGV))

require "logstash/runner"

ARGV.unshift("test")
LogStash::Runner.new.main(ARGV)
3 changes: 2 additions & 1 deletion lib/logstash/agent.rb
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,8 @@ def run(args, &block)
public
def wait
@thread.join
end
return 0
end # def wait

public
def run_with_config(config)
Expand Down
15 changes: 12 additions & 3 deletions lib/logstash/runner.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
require "rubygems"
$: << File.join(File.dirname(__FILE__), "..")
$: << File.join(File.dirname(__FILE__), "..", "..", "test")
require "logstash/namespace"

class LogStash::Runner
Expand All @@ -11,7 +13,11 @@ def main(args)
args = run(args)
end

@runners.each { |r| r.wait }
status = []
@runners.each { |r| status << r.wait }

# Avoid running test/unit's at_exit crap
java.lang.System.exit(status.first)
end # def self.main

def run(args)
Expand All @@ -30,7 +36,10 @@ def run(args)
return web.run(args)
end,
"test" => lambda do
require "logstash_test_runner"
require "logstash/test"
test = LogStash::Test.new
@runners << test
return test.run(args)
end
} # commands

Expand All @@ -48,7 +57,7 @@ def run(args)
end

return args
end # def self.run
end # def run
end # class LogStash::Runner

if $0 == __FILE__
Expand Down
1 change: 1 addition & 0 deletions lib/logstash/web/runner.rb
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ def run(args)
public
def wait
@thread.join
return 0
end # def wait
end # class LogStash::Web::Runner

3 changes: 1 addition & 2 deletions test/logstash_test_runner.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,4 @@ def use(path)
skip "logstash/inputs/test_syslog"
skip "logstash/inputs/test_stomp"

Test::Unit::AutoRunner.run

#Test::Unit::AutoRunner.run

0 comments on commit e98f463

Please sign in to comment.