Commit 46afe60085fb3b0a89cf524bc0e0867aa33047b9
1 parent
9109bcc4
Exists in
master
and in
28 other branches
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
Showing
2 changed files
with
29 additions
and
20 deletions
Show diff stats
lib/tasks/test.rake
... | ... | @@ -18,19 +18,28 @@ AllTasks = TestTasks + CucumberTasks + NoosferoTasks |
18 | 18 | |
19 | 19 | namespace :test do |
20 | 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 | 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 | 30 | end |
25 | 31 | end |
26 | 32 | (CucumberTasks + NoosferoTasks).each do |test_task| |
27 | 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 | 39 | end |
30 | 40 | |
31 | 41 | task :test do |
32 | 42 | ENV['RAILS_ENV'] = 'test' |
33 | - Rake::Task['solr:start'].invoke | |
34 | 43 | errors = AllTasks.collect do |task| |
35 | 44 | begin |
36 | 45 | Rake::Task[task].invoke |
... | ... | @@ -39,7 +48,6 @@ task :test do |
39 | 48 | task |
40 | 49 | end |
41 | 50 | end.compact |
42 | - Rake::Task['solr:stop'].invoke | |
43 | 51 | abort "Errors running #{errors.to_sentence}!" if errors.any? |
44 | 52 | end |
45 | 53 | ... | ... |
vendor/plugins/acts_as_solr_reloaded/lib/tasks/solr.rake
... | ... | @@ -41,6 +41,8 @@ namespace :solr do |
41 | 41 | FileUtils.mkdir_p(SOLR_LOGS_PATH) |
42 | 42 | FileUtils.mkdir_p(SOLR_DATA_PATH) |
43 | 43 | FileUtils.mkdir_p(SOLR_PIDS_PATH) |
44 | + | |
45 | + # test if there is a solr already running | |
44 | 46 | begin |
45 | 47 | n = Net::HTTP.new('127.0.0.1', SOLR_PORT) |
46 | 48 | n.request_head('/').value |
... | ... | @@ -73,23 +75,22 @@ namespace :solr do |
73 | 75 | desc 'Stops Solr. Specify the environment by using: RAILS_ENV=your_env. Defaults to development if none.' |
74 | 76 | task :stop => :environment do |
75 | 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 | 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 | 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 | 94 | end |
94 | 95 | end |
95 | 96 | ... | ... |