From 46afe60085fb3b0a89cf524bc0e0867aa33047b9 Mon Sep 17 00:00:00 2001 From: Rafael Martins Date: Fri, 9 Mar 2012 17:30:58 -0300 Subject: [PATCH] Fixes for solr tasks on rake test --- lib/tasks/test.rake | 18 +++++++++++++----- vendor/plugins/acts_as_solr_reloaded/lib/tasks/solr.rake | 31 ++++++++++++++++--------------- 2 files changed, 29 insertions(+), 20 deletions(-) diff --git a/lib/tasks/test.rake b/lib/tasks/test.rake index 37f70b1..9debe56 100644 --- a/lib/tasks/test.rake +++ b/lib/tasks/test.rake @@ -18,19 +18,28 @@ AllTasks = TestTasks + CucumberTasks + NoosferoTasks namespace :test do TestTasks.each do |test_task| - test_task = test_task.to_s.gsub(/^test:/, '').to_sym #remove namespace :test + orig_name = test_task.to_s + test_task = test_task.to_s.gsub(/^test:/, '').to_sym #remove namespace :test ENV['RAILS_ENV'] = 'test' - override_task test_task => ['solr:start', "#{test_task}:original", "solr:stop"] + # force the solr tasks to run with each individual test task + override_task test_task do + Rake::Task['solr:start'].execute + Rake::Task["#{orig_name}:original"].execute + Rake::Task['solr:stop'].execute + end end end (CucumberTasks + NoosferoTasks).each do |test_task| ENV['RAILS_ENV'] = 'test' - override_task test_task => ['solr:start', "#{test_task}:original", "solr:stop"] + override_task test_task do + Rake::Task['solr:start'].execute + Rake::Task["#{test_task}:original"].execute + Rake::Task['solr:stop'].execute + end end task :test do ENV['RAILS_ENV'] = 'test' - Rake::Task['solr:start'].invoke errors = AllTasks.collect do |task| begin Rake::Task[task].invoke @@ -39,7 +48,6 @@ task :test do task end end.compact - Rake::Task['solr:stop'].invoke abort "Errors running #{errors.to_sentence}!" if errors.any? end diff --git a/vendor/plugins/acts_as_solr_reloaded/lib/tasks/solr.rake b/vendor/plugins/acts_as_solr_reloaded/lib/tasks/solr.rake index f09a223..c942d21 100644 --- a/vendor/plugins/acts_as_solr_reloaded/lib/tasks/solr.rake +++ b/vendor/plugins/acts_as_solr_reloaded/lib/tasks/solr.rake @@ -41,6 +41,8 @@ namespace :solr do FileUtils.mkdir_p(SOLR_LOGS_PATH) FileUtils.mkdir_p(SOLR_DATA_PATH) FileUtils.mkdir_p(SOLR_PIDS_PATH) + + # test if there is a solr already running begin n = Net::HTTP.new('127.0.0.1', SOLR_PORT) n.request_head('/').value @@ -73,23 +75,22 @@ namespace :solr do desc 'Stops Solr. Specify the environment by using: RAILS_ENV=your_env. Defaults to development if none.' task :stop => :environment do require File.expand_path("#{File.dirname(__FILE__)}/../../config/solr_environment") - fork do - if File.exists?(SOLR_PID_FILE) - killed = false - File.open(SOLR_PID_FILE, "r") do |f| - pid = f.readline - begin - Process.kill('TERM', -pid.to_i) - killed = true - rescue - puts "Solr could not be found at pid #{pid.to_i}. Removing pid file." - end + if File.exists?(SOLR_PID_FILE) + killed = false + File.open(SOLR_PID_FILE, "r") do |f| + pid = f.readline + begin + Process.kill('TERM', -pid.to_i) + sleep 3 + killed = true + rescue + puts "Solr could not be found at pid #{pid.to_i}. Removing pid file." end - File.unlink(SOLR_PID_FILE) - puts "Solr shutdown successfully." if killed - else - puts "PID file not found at #{SOLR_PID_FILE}. Either Solr is not running or no PID file was written." end + File.unlink(SOLR_PID_FILE) + puts "Solr shutdown successfully." if killed + else + puts "PID file not found at #{SOLR_PID_FILE}. Either Solr is not running or no PID file was written." end end -- libgit2 0.21.2