aboutsummaryrefslogtreecommitdiffstats
path: root/activejob/test/support/integration/adapters
diff options
context:
space:
mode:
authorMatthew Draper <matthew@trebex.net>2015-04-20 08:50:24 +0930
committerMatthew Draper <matthew@trebex.net>2015-04-20 08:50:24 +0930
commit41ae432f492bfedadc6977012c8d38665bda3ae2 (patch)
tree430efa3789af60129afbd7b2f9811ea37d831836 /activejob/test/support/integration/adapters
parent2ca8545e514d2b8ad9c1925ef5d54fe65305799c (diff)
downloadrails-41ae432f492bfedadc6977012c8d38665bda3ae2.tar.gz
rails-41ae432f492bfedadc6977012c8d38665bda3ae2.tar.bz2
rails-41ae432f492bfedadc6977012c8d38665bda3ae2.zip
Shuffle a few things in aid of easier debugging
* Don't swallow output -- if there is any, it's probably useful * Wait for the process to finish * Use IPC instead of a sleep * No need for a pidfile
Diffstat (limited to 'activejob/test/support/integration/adapters')
-rw-r--r--activejob/test/support/integration/adapters/sidekiq.rb56
1 files changed, 36 insertions, 20 deletions
diff --git a/activejob/test/support/integration/adapters/sidekiq.rb b/activejob/test/support/integration/adapters/sidekiq.rb
index 7378591cbc..4988cdb33f 100644
--- a/activejob/test/support/integration/adapters/sidekiq.rb
+++ b/activejob/test/support/integration/adapters/sidekiq.rb
@@ -19,28 +19,38 @@ module SidekiqJobsManager
end
def start_workers
- fork do
- logfile = Rails.root.join("log/sidekiq.log").to_s
- pidfile = Rails.root.join("tmp/sidekiq.pid").to_s
- ::Process.daemon(true, true)
- [$stdout, $stderr].each do |io|
- File.open(logfile, 'ab') do |f|
- io.reopen(f)
- end
- io.sync = true
- end
+ continue_read, continue_write = IO.pipe
+ death_read, death_write = IO.pipe
+
+ @pid = fork do
+ continue_read.close
+ death_write.close
+
+ # Celluloid & Sidekiq are not warning-clean :(
+ $VERBOSE = false
+
$stdin.reopen('/dev/null')
+ $stdout.sync = true
+ $stderr.sync = true
+
+ logfile = Rails.root.join("log/sidekiq.log").to_s
Sidekiq::Logging.initialize_logger(logfile)
- File.open(File.expand_path(pidfile), 'w') do |f|
- f.puts ::Process.pid
- end
self_read, self_write = IO.pipe
trap "TERM" do
self_write.puts("TERM")
end
+ Thread.new do
+ begin
+ death_read.read
+ rescue Exception
+ end
+ self_write.puts("TERM")
+ end
+
require 'celluloid'
+ Celluloid.logger = nil
require 'sidekiq/launcher'
sidekiq = Sidekiq::Launcher.new({queues: ["integration_tests"],
environment: "test",
@@ -51,23 +61,29 @@ module SidekiqJobsManager
Sidekiq::Scheduled.const_set :INITIAL_WAIT, 1
begin
sidekiq.run
+ continue_write.puts "started"
while readable_io = IO.select([self_read])
signal = readable_io.first[0].gets.strip
raise Interrupt if signal == "TERM"
end
rescue Interrupt
- sidekiq.stop
- exit(0)
end
+
+ sidekiq.stop
+ exit!
end
- sleep 1
+ continue_write.close
+ death_read.close
+ @worker_lifeline = death_write
+
+ raise "Failed to start worker" unless continue_read.gets == "started\n"
end
def stop_workers
- pidfile = Rails.root.join("tmp/sidekiq.pid").to_s
- Process.kill 'TERM', File.open(pidfile).read.to_i
- FileUtils.rm_f pidfile
- rescue
+ if @pid
+ Process.kill 'TERM', @pid
+ Process.wait @pid
+ end
end
def can_run?