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
#!/usr/bin/env ruby | |
require 'fileutils' | |
require_relative 'workerpool' | |
require_relative 'common' | |
require_relative 'mirrordatabase' | |
require_relative 'watcher' | |
class MirrorSyncDaemon |
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
def check_status | |
~ |+ if File.exists?(PID_FILE) | |
~ |+ pid = File.read(PID_FILE).to_i | |
~ |+ check_pid_status(pid) if pid > 0 | |
~ |+ File.delete(PID_FILE) | |
~ |+ end |
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 check_status | |
if File.exist?(PID_FILE) | |
pid = File.read(PID_FILE).to_i | |
check_pid_status(pid) if pid > 0 | |
File.delete(PID_FILE) | |
end | |
end | |
def check_pid_status(pid) |
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
mihaelkeehl@mihael-k33hl:~/rise-chef-repo/cookbooks/mirror/files/default/scripts$ rspec -b ./spec/test_mirrorsyncdaemon.rb | |
/home/mihaelkeehl/rise-chef-repo/cookbooks/mirror/files/default/scripts/bundle/ruby/2.3.0/gems/beaneater-1.0.0/lib/beaneater/tube/collection.rb:178: warning: assigned but unused variable - last_used | |
/home/mihaelkeehl/rise-chef-repo/cookbooks/mirror/files/default/scripts/lib/beaneater_config.rb:10: warning: assigned but unused variable - e | |
/home/mihaelkeehl/rise-chef-repo/cookbooks/mirror/files/default/scripts/bundle/ruby/2.3.0/gems/rsync-1.0.9/lib/rsync/configure.rb:7: warning: `*' interpreted as argument prefix | |
F | |
Failures: | |
1) MirrorSyncDaemon deletes the PID_FILE if it exists but contains invalid PID | |
Failure/Error: if File.exist?(PID_FILE) |
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
1 require 'spec_helper' | |
2 require 'mirrorsyncdaemon' | |
3 require 'fakefs/spec_helpers' | |
4 | |
5 | |
6 RSpec.describe MirrorSyncDaemon do | |
7 include FakeFS::SpecHelpers | |
8 FakeFS.activate! | |
9 it 'deletes the PID_FILE if it exists but contains invalid PID' do | |
10 stub_const("MirrorSyncDaemon::PID_FILE", FakeFS::File.new("testfile", RealFile::CREA T|RealFile::TRUNC|RealFile::RDWR, 0644).path) |
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
1 require 'spec_helper' | |
2 require 'mirrorsyncdaemon' | |
3 require 'memfs' | |
4 | |
5 RSpec.describe MirrorSyncDaemon do | |
6 it 'deletes the PID_FILE if it exists but contains invalid PID' do | |
7 MemFs.activate do | |
8 FileUtils.mkdir_p(File.dirname(MirrorSyncDaemon::PID_FILE)) | |
9 File.new(MirrorSyncDaemon::PID_FILE, File::CREAT|File::TRUNC|File::RDWR) | |
10 #stub_const("MirrorSyncDaemon::PID_FILE", MemFs.touch('testfile')) |
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
def customMethod | |
puts "This is a test!" | |
end | |
expect { customMethod }.to output("This is a test!").to_stdout } |
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
require 'spec_helper' | |
require 'mirrorsyncdaemon' | |
describe MirrorSyncDaemon do | |
context 'MirrorSyncDaemon.run' do | |
let(:mirrorsyncdaemon) { @mirrorsyncdaemon ||= MirrorSyncDaemon.new } | |
describe 'check_status method' do | |
it 'deletes the PID_FILE if it exists but contains invalid PID' do | |
stub_const("MirrorSyncDaemon::PID_FILE", './testfile.pid') |
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 |
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
it 'creates a WorkerPool with a size based on the defined worker count' do | |
allow(mirrorsyncdaemon).to receive(:get_worker_count) { 5 } | |
worker_pool = double() | |
allow(WorkerPool).to receive(:new) { worker_pool } | |
allow(workerpool).to receive(:shutdown) {} | |
expect(mirrorsyncdaemon).to receive(:get_worker_count) | |
expect(WorkerPool).to receive(:new).with(5) | |
mirrorsyncdaemon.init_workers | |
end |
OlderNewer