SOLR-97: Rakefile now supports functional and unit tests. Also added partially functioning test:coverage task

git-svn-id: https://svn.apache.org/repos/asf/incubator/solr/trunk@494108 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Erik Hatcher 2007-01-08 16:05:02 +00:00
parent fbc98a7eda
commit 092f7375ed
6 changed files with 126 additions and 33 deletions

View File

@ -1,3 +1,34 @@
# The ASF licenses this file to You under the Apache License, Version 2.0
# (the "License"); you may not use this file except in compliance with
# the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# the default task is to run both the unit and functional tests
# functional tests require that a solr test server is running
# but this Rakefil should take care of starting and stopping it
# for you
#
# if you just want to run unit tests:
#
# rake test_units
#
# and if you just want to run functional tests
#
# rake test_functionals
#
# if you would like to see solr startup messages on STDERR
# when starting solr test server during functional tests use:
#
# rake SOLR_CONSOLE=true
SOLRB_VERSION = '0.0.1' SOLRB_VERSION = '0.0.1'
require 'rubygems' require 'rubygems'
@ -6,7 +37,7 @@ require 'rake/testtask'
require 'rake/rdoctask' require 'rake/rdoctask'
require 'rake/packagetask' require 'rake/packagetask'
require 'rake/gempackagetask' require 'rake/gempackagetask'
require 'test/test_helper.rb' require 'test/test_solr_server.rb'
task :default => [:test] task :default => [:test]
@ -35,19 +66,51 @@ Rake::RDocTask.new('doc') do |rd|
rd.rdoc_dir = 'doc' rd.rdoc_dir = 'doc'
end end
# append to the test task so that we can wrap Rake::TestTask.new(:test_units) do |t|
# Rake::TestTask with a call to start/stop a solr server t.pattern = 'test/unit/*_test.rb'
task :test do
start_solr_server
end
Rake::TestTask.new('test') do |t|
t.pattern = 'test/*_test.rb'
t.verbose = true t.verbose = true
t.ruby_opts = ['-r solr', '-r test/unit', '-Itest'] t.ruby_opts = ['-r solr', '-r test/unit', '-Itest/unit']
end
Rake::TestTask.new(:test_functionals) do |t|
t.pattern = 'test/functional/*_test.rb'
t.verbose = true
t.ruby_opts = ['-r solr', '-r test/unit', '-Itest/functional']
end end
task :test do task :test do
stop_solr_server # unit tests don't require a solr server
Rake::Task[:test_units].invoke rescue got_error = true
# functional tests do
solr_server = TestSolrServer.instance
solr_server.quiet = false if ENV['SOLR_CONSOLE']
begin
puts
puts "starting solr server for functional tests"
solr_server.start
sleep 10
Rake::Task[:test_functionals].invoke
rescue
got_error = true
ensure
puts "stopping solr server"
solr_server.stop
end
raise "test failures" if got_error
end end
# TODO: fix this so it works, it is not happy with connection_test.rb for some reason
# borrowed from here: http://clarkware.com/cgi/blosxom/2007/01/05#RcovRakeTask
namespace :test do
desc 'Measures test coverage'
task :coverage do
rm_f "coverage"
rm_f "coverage.data"
system("rcov --text-summary -Ilib test/unit/*_test.rb")
system("open coverage/index.html") if PLATFORM['darwin']
end
end

View File

@ -10,26 +10,8 @@
# See the License for the specific language governing permissions and # See the License for the specific language governing permissions and
# limitations under the License. # limitations under the License.
def start_solr_server class TestServer < Test::Unit::TestCase
Dir.chdir(File.dirname(__FILE__) + '/../solr') do def test_ok
puts "starting solr server" assert_equal true, true
# start solr and capture the process ID in a global
$SOLR_PID = fork do
# don't want to see the messages about solr starting up
# STDERR.close
exec "java -Djetty.port=8888 -Dsolr.solr.home=../test -jar start.jar"
end
end end
# wait for the jvm and solr to start
sleep 10
end end
def stop_solr_server
puts "stopping solr server"
Process.kill('TERM', $SOLR_PID)
end

View File

@ -0,0 +1,48 @@
# The ASF licenses this file to You under the Apache License, Version 2.0
# (the "License"); you may not use this file except in compliance with
# the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# A singleton class for starting/stopping a Solr server for testing purposes
# The behavior of TestSolrServer can be modified prior to start() by changing
# port, solr_home, and quiet properties.
class TestSolrServer
require 'singleton'
include Singleton
attr_accessor :port, :solr_home, :quiet
# configure the singleton with some defaults
def initialize
@port = 8888
@quiet = true
root_dir = File.expand_path(File.dirname(__FILE__) + '/..')
@solr_dir = "#{root_dir}/solr"
@solr_home = "#{root_dir}/test"
@pid = nil
end
# start the solr server
def start
Dir.chdir(@solr_dir) do
@pid = fork do
STDERR.close if @quiet
exec "java -Djetty.port=#{@port} -Dsolr.solr.home=#{@solr_home} " +
"-jar start.jar"
end
end
end
# stop a running solr server
def stop
Process.kill('TERM', @pid)
Process.wait
end
end