Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ensure we wait for process to exit. #433

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 20 additions & 11 deletions spec/daemonizing_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,15 @@ def name
end

it 'should create a pid file' do
fork do
pid = fork do
subject.daemonize
sleep
end

wait_for_server_to_start

subject.kill
Process.wait(pid)
end

it 'should redirect stdio to a log file' do
Expand All @@ -65,6 +66,7 @@ def name
expect(log).to include('simple puts', 'STDERR.puts', 'STDOUT.puts')

server.kill
Process.wait(pid)
end

it 'should change privilege' do
Expand All @@ -74,14 +76,13 @@ def name
end

_, status = Process.wait2(pid)

expect(status).to be_a_success
end

it 'should kill process in pid file' do
expect(File.exist?(subject.pid_file)).to be_falsey

fork do
pid = fork do
subject.daemonize
sleep
end
Expand All @@ -94,12 +95,14 @@ def name
subject.kill(1)
end

sleep(1)
Process.kill(:INT, pid)
Process.wait(pid)

expect(File.exist?(subject.pid_file)).to be_falsey
end

it 'should force kill process in pid file' do
fork do
pid = fork do
subject.daemonize
sleep
end
Expand All @@ -108,27 +111,29 @@ def name

subject.kill(0)

Process.wait(pid)
expect(File.exist?(subject.pid_file)).to be_falsey
end

it 'should send kill signal if timeout' do
fork do
pid = fork do
subject.daemonize
sleep
end

wait_for_server_to_start

pid = subject.pid
server_pid = subject.pid

subject.kill(10)
Process.wait(pid)

expect(File.exist?(subject.pid_file)).to be_falsey
expect(Process.running?(pid)).to be_falsey
expect(Process.running?(server_pid)).to be_falsey
end

it "should restart" do
fork do
pid = fork do
subject.on_restart {}
subject.daemonize
sleep 5
Expand All @@ -140,7 +145,8 @@ def name
TestServer.restart(subject.pid_file)
end

expect { sleep 0.1 while File.exist?(subject.pid_file) }.to take_less_then(20)
Process.wait(pid)
expect(File.exist?(subject.pid_file)).to be_falsey
end

it "should ignore if no restart block specified" do
Expand All @@ -154,7 +160,7 @@ def name
end

it "should exit and raise if pid file already exist" do
fork do
pid = fork do
subject.daemonize
sleep 5
end
Expand All @@ -164,6 +170,9 @@ def name
expect { subject.daemonize }.to raise_error(PidFileExist)

expect(File.exist?(subject.pid_file)).to be_truthy

subject.kill
Process.wait(pid)
end

it "should raise if no pid file" do
Expand Down
Loading