Commit 46afe60085fb3b0a89cf524bc0e0867aa33047b9

Authored by Rafael Martins
1 parent 9109bcc4

Fixes for solr tasks on rake test

* call solr tasks directly, with execute, instead of as dependencies
* removed fork on solr:stop to sinchronize sequential tasks
lib/tasks/test.rake
@@ -18,19 +18,28 @@ AllTasks = TestTasks + CucumberTasks + NoosferoTasks @@ -18,19 +18,28 @@ AllTasks = TestTasks + CucumberTasks + NoosferoTasks
18 18
19 namespace :test do 19 namespace :test do
20 TestTasks.each do |test_task| 20 TestTasks.each do |test_task|
21 - test_task = test_task.to_s.gsub(/^test:/, '').to_sym #remove namespace :test 21 + orig_name = test_task.to_s
  22 + test_task = test_task.to_s.gsub(/^test:/, '').to_sym #remove namespace :test
22 ENV['RAILS_ENV'] = 'test' 23 ENV['RAILS_ENV'] = 'test'
23 - override_task test_task => ['solr:start', "#{test_task}:original", "solr:stop"] 24 + # force the solr tasks to run with each individual test task
  25 + override_task test_task do
  26 + Rake::Task['solr:start'].execute
  27 + Rake::Task["#{orig_name}:original"].execute
  28 + Rake::Task['solr:stop'].execute
  29 + end
24 end 30 end
25 end 31 end
26 (CucumberTasks + NoosferoTasks).each do |test_task| 32 (CucumberTasks + NoosferoTasks).each do |test_task|
27 ENV['RAILS_ENV'] = 'test' 33 ENV['RAILS_ENV'] = 'test'
28 - override_task test_task => ['solr:start', "#{test_task}:original", "solr:stop"] 34 + override_task test_task do
  35 + Rake::Task['solr:start'].execute
  36 + Rake::Task["#{test_task}:original"].execute
  37 + Rake::Task['solr:stop'].execute
  38 + end
29 end 39 end
30 40
31 task :test do 41 task :test do
32 ENV['RAILS_ENV'] = 'test' 42 ENV['RAILS_ENV'] = 'test'
33 - Rake::Task['solr:start'].invoke  
34 errors = AllTasks.collect do |task| 43 errors = AllTasks.collect do |task|
35 begin 44 begin
36 Rake::Task[task].invoke 45 Rake::Task[task].invoke
@@ -39,7 +48,6 @@ task :test do @@ -39,7 +48,6 @@ task :test do
39 task 48 task
40 end 49 end
41 end.compact 50 end.compact
42 - Rake::Task['solr:stop'].invoke  
43 abort "Errors running #{errors.to_sentence}!" if errors.any? 51 abort "Errors running #{errors.to_sentence}!" if errors.any?
44 end 52 end
45 53
vendor/plugins/acts_as_solr_reloaded/lib/tasks/solr.rake
@@ -41,6 +41,8 @@ namespace :solr do @@ -41,6 +41,8 @@ namespace :solr do
41 FileUtils.mkdir_p(SOLR_LOGS_PATH) 41 FileUtils.mkdir_p(SOLR_LOGS_PATH)
42 FileUtils.mkdir_p(SOLR_DATA_PATH) 42 FileUtils.mkdir_p(SOLR_DATA_PATH)
43 FileUtils.mkdir_p(SOLR_PIDS_PATH) 43 FileUtils.mkdir_p(SOLR_PIDS_PATH)
  44 +
  45 + # test if there is a solr already running
44 begin 46 begin
45 n = Net::HTTP.new('127.0.0.1', SOLR_PORT) 47 n = Net::HTTP.new('127.0.0.1', SOLR_PORT)
46 n.request_head('/').value 48 n.request_head('/').value
@@ -73,23 +75,22 @@ namespace :solr do @@ -73,23 +75,22 @@ namespace :solr do
73 desc 'Stops Solr. Specify the environment by using: RAILS_ENV=your_env. Defaults to development if none.' 75 desc 'Stops Solr. Specify the environment by using: RAILS_ENV=your_env. Defaults to development if none.'
74 task :stop => :environment do 76 task :stop => :environment do
75 require File.expand_path("#{File.dirname(__FILE__)}/../../config/solr_environment") 77 require File.expand_path("#{File.dirname(__FILE__)}/../../config/solr_environment")
76 - fork do  
77 - if File.exists?(SOLR_PID_FILE)  
78 - killed = false  
79 - File.open(SOLR_PID_FILE, "r") do |f|  
80 - pid = f.readline  
81 - begin  
82 - Process.kill('TERM', -pid.to_i)  
83 - killed = true  
84 - rescue  
85 - puts "Solr could not be found at pid #{pid.to_i}. Removing pid file."  
86 - end 78 + if File.exists?(SOLR_PID_FILE)
  79 + killed = false
  80 + File.open(SOLR_PID_FILE, "r") do |f|
  81 + pid = f.readline
  82 + begin
  83 + Process.kill('TERM', -pid.to_i)
  84 + sleep 3
  85 + killed = true
  86 + rescue
  87 + puts "Solr could not be found at pid #{pid.to_i}. Removing pid file."
87 end 88 end
88 - File.unlink(SOLR_PID_FILE)  
89 - puts "Solr shutdown successfully." if killed  
90 - else  
91 - puts "PID file not found at #{SOLR_PID_FILE}. Either Solr is not running or no PID file was written."  
92 end 89 end
  90 + File.unlink(SOLR_PID_FILE)
  91 + puts "Solr shutdown successfully." if killed
  92 + else
  93 + puts "PID file not found at #{SOLR_PID_FILE}. Either Solr is not running or no PID file was written."
93 end 94 end
94 end 95 end
95 96