Advertisement
Guest User

Untitled

a guest
Aug 29th, 2016
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.32 KB | None | 0 0
  1. #code
  2. def check_status
  3. if File.exist?(PID_FILE)
  4. pid = File.read(PID_FILE).to_i
  5. check_pid_status(pid) if pid > 0
  6. File.delete(PID_FILE)
  7. end
  8. end
  9.  
  10. def check_pid_status(pid)
  11. Process.kill(0, pid)
  12. puts "Process(#{pid}) is already running."
  13. exit(1)
  14. rescue Errno::ESERCH #do nothing, and continue with the script
  15. rescue Errno::EPERM
  16. puts "Process with pid=#{pid} is already running but is owned by a different user"
  17. exit(1)
  18. end
  19.  
  20. #test
  21. require 'spec_helper'
  22. require 'mirrorsyncdaemon'
  23.  
  24.  
  25. RSpec.describe MirrorSyncDaemon do
  26. it 'deletes the PID_FILE if it exists but contains invalid PID' do
  27. stub_const("MirrorSyncDaemon::PID_FILE", File.open('test_file', ::File::CREAT|::File::TRUNC|::File::RDWR, 0644) { |f| f.write('123') } )
  28. @mirrorsyncdaemon = MirrorSyncDaemon.new
  29. @mirrorsyncdaemon.stub(:check_pid_status).with(Integer) { raise Errno::ESERCH }
  30. @mirrorsyncdaemon.check_status
  31. expect(MirrorSyncDaemon::PID_FILE).to_not exist
  32. end
  33. end
  34.  
  35. #error
  36. Failures:
  37.  
  38. 1) MirrorSyncDaemon deletes the PID_FILE if it exists but contains invalid PID
  39. Failure/Error: if File.exist?(PID_FILE)
  40.  
  41. TypeError:
  42. no implicit conversion of Fixnum into String
  43. # ./lib/mirrorsyncdaemon.rb:124:in `exist?'
  44. # ./lib/mirrorsyncdaemon.rb:124:in `check_status'
  45. # ./spec/test_mirrorsyncdaemon.rb:10:in `block (2 levels) in <top (required)>'
  46.  
  47. Deprecation Warnings:
  48.  
  49. Using `stub` from rspec-mocks' old `:should` syntax without explicitly enabling the syntax is deprecated. Use the new `:expect` syntax or explicitly enable `:should` instead. Called from /home/mihaelkeehl/rise-chef-repo/cookbooks/mirror/files/default/scripts/spec/test_mirrorsyncdaemon.rb:9:in `block (2 levels) in <top (required)>'.
  50.  
  51.  
  52. If you need more of the backtrace for any of these deprecations to
  53. identify where to make the necessary changes, you can configure
  54. `config.raise_errors_for_deprecations!`, and it will turn the
  55. deprecation warnings into errors, giving you the full backtrace.
  56.  
  57. 1 deprecation warning total
  58.  
  59. Finished in 0.00102 seconds (files took 0.12823 seconds to load)
  60. 1 example, 1 failure
  61.  
  62. Failed examples:
  63.  
  64. rspec ./spec/test_mirrorsyncdaemon.rb:6 # MirrorSyncDaemon deletes the PID_FILE if it exists but contains invalid PID
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement