-
-
Save marzzz21/56ed5cb9e98217dc87448160af9d2251 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#code | |
def write_pid | |
puts "writing pid" | |
begin | |
File.open(PID_FILE, ::File::CREAT | ::File::EXCL | ::File::WRONLY){|f| f.write("#{Process.pid}") } | |
at_exit { File.delete(PID_FILE) if File.exist?(PID_FILE) } | |
rescue Errno::EEXIST | |
check_status | |
retry | |
end | |
end | |
#test | |
it "should raise Errno::EEXIST if PID_FILE already exists" do | |
stub_const("MirrorSyncDaemon::PID_FILE", './testfile.pid') | |
File.new(MirrorSyncDaemon::PID_FILE, 'w+') | |
allow(mirrorsyncdaemon).to receive(:checkstatus) {} | |
expect(File).to receive(:open).with(MirrorSyncDaemon::PID_FILE, ::File::CREAT | ::Fil e::EXCL | ::File::WRONLY).and_raise(Errno::EEXIST) | |
mirrorsyncdaemon.write_pid | |
FileUtils.rm(MirrorSyncDaemon::PID_FILE) if File.exist?(MirrorSyncDaemon::PID_FILE) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment