Sha256: 0032c9e271a00952b90127218ad79dd1b2447467665cc93ddbfeb081d086915d
Contents?: true
Size: 1.36 KB
Versions: 2
Compression:
Stored size: 1.36 KB
Contents
require 'test_helper' class DaemonTest < ActiveSupport::TestCase setup do @daemon = Sidejobs.daemon @pid_path = Rails.root.join('tmp/pids/sidejobs.pid') end teardown do FileUtils.rm_rf @pid_path end test 'process' do fork do @daemon.start end reconnect sleep 4 assert @daemon.pid assert File.exist?(@pid_path) assert Process.pid != @daemon.pid assert process_exists?(@daemon.pid) pid = @daemon.pid fork do @daemon.restart end reconnect sleep 4 assert @daemon.pid assert File.exist?(@pid_path) assert Process.pid != @daemon.pid assert process_exists?(@daemon.pid) sleep 8 assert_not process_exists?(pid) pid = @daemon.pid @daemon.stop assert_nil @daemon.pid assert_not File.exist?(@pid_path) sleep 8 assert_not process_exists?(pid) end test 'pulling' do @daemon.stubs(:daemonize) @daemon.stubs(:stopping?).returns(false, true) processor = mock processor.expects(:process).once @daemon.stubs(:processor).returns(processor) @daemon.expects(:sleep).with(Sidejobs.configuration.sleep_delay).once @daemon.start end private def process_exists?(pid) begin Process.kill 0, pid true rescue Errno::ESRCH false end end def reconnect ActiveRecord::Base.connection.reconnect! end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
sidejobs-4.0.0.2 | test/daemon_test.rb |
sidejobs-4.0.0.1 | test/daemon_test.rb |