Skip to content

Apache Lucene open-source search software

Added TestSolrServer.wrap. Adjusted Rakefile to use .wrap method in test target, and added functional tests to code coverage run.

Erik Hatcher6d0d02f41b01
diff --git a/client/ruby/solrb/Rakefile b/client/ruby/solrb/Rakefile
index 5fe8175c88d..285b5c7b1b4 100644
--- a/client/ruby/solrb/Rakefile
+++ b/client/ruby/solrb/Rakefile
@@ -82,21 +82,9 @@ task :test do
# 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
+ # wrap functional tests with a test-specific Solr server
+ got_error = TestSolrServer.wrap(:quiet => ENV['SOLR_CONSOLE'] ? false : true) do
Rake::Task[:test_functionals].invoke
- rescue
- got_error = true
- ensure
- puts "stopping solr server"
- solr_server.stop
end
raise "test failures" if got_error
@@ -107,7 +95,11 @@ namespace :test do
# borrowed from here: http://clarkware.com/cgi/blosxom/2007/01/05#RcovRakeTask
task :coverage do
rm_f "coverage"
- system("rcov --text-summary -Ilib:test/unit test/unit/*_test.rb")
+ rm_f "coverage.data"
+ system("rcov --aggregate coverage.data --text-summary -Ilib:test/unit test/unit/*_test.rb")
+ TestSolrServer.wrap do
+ system("rcov --aggregate coverage.data --text-summary -Ilib:test/functional test/functional/*_test.rb")
+ end
system("open coverage/index.html") if PLATFORM['darwin']
end
diff --git a/client/ruby/solrb/test/functional/server_test.rb b/client/ruby/solrb/test/functional/server_test.rb
index e387d5ae892..6983c83f8eb 100644
--- a/client/ruby/solrb/test/functional/server_test.rb
+++ b/client/ruby/solrb/test/functional/server_test.rb
@@ -10,8 +10,15 @@
# See the License for the specific language governing permissions and
# limitations under the License.
+require 'test/unit'
+require 'solr'
+
class TestServer < Test::Unit::TestCase
- def test_ok
- assert_equal true, true
+ include Solr
+
+ def test_commit
+ connection = Connection.new("http://localhost:8888")
+ response = connection.send(UpdateRequest.new("<commit/>"))
+ assert_equal "<result status=\"0\"></result>", response.raw_response
end
end
diff --git a/client/ruby/solrb/test/functional/test_solr_server.rb b/client/ruby/solrb/test/functional/test_solr_server.rb
index 81256fd85cb..b5f4b80f578 100644
--- a/client/ruby/solrb/test/functional/test_solr_server.rb
+++ b/client/ruby/solrb/test/functional/test_solr_server.rb
@@ -45,4 +45,24 @@ class TestSolrServer
Process.kill('TERM', @pid)
Process.wait
end
- end
+
+ def self.wrap(params = {})
+ error = false
+ solr_server = self.instance
+ solr_server.quiet = params[:quiet]
+ begin
+ puts "starting solr server"
+ solr_server.start
+ sleep 10
+ yield
+ rescue
+ error = true
+ ensure
+ puts "stopping solr server"
+ solr_server.stop
+ end
+
+ return error
+ end
+
+end