Skip to content

Commit 1b41f0c

Browse files
committed
Ensure we wait for process to exit.
1 parent 49e592f commit 1b41f0c

File tree

1 file changed

+16
-9
lines changed

1 file changed

+16
-9
lines changed

spec/daemonizing_spec.rb

+16-9
Original file line numberDiff line numberDiff line change
@@ -38,14 +38,15 @@ def name
3838
end
3939

4040
it 'should create a pid file' do
41-
fork do
41+
pid = fork do
4242
subject.daemonize
4343
sleep
4444
end
4545

4646
wait_for_server_to_start
4747

4848
subject.kill
49+
Process.wait(pid)
4950
end
5051

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

6768
server.kill
69+
Process.wait(pid)
6870
end
6971

7072
it 'should change privilege' do
@@ -74,14 +76,13 @@ def name
7476
end
7577

7678
_, status = Process.wait2(pid)
77-
7879
expect(status).to be_a_success
7980
end
8081

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

84-
fork do
85+
pid = fork do
8586
subject.daemonize
8687
sleep
8788
end
@@ -94,12 +95,12 @@ def name
9495
subject.kill(1)
9596
end
9697

97-
sleep(1)
98+
Process.wait(pid)
9899
expect(File.exist?(subject.pid_file)).to be_falsey
99100
end
100101

101102
it 'should force kill process in pid file' do
102-
fork do
103+
pid = fork do
103104
subject.daemonize
104105
sleep
105106
end
@@ -108,11 +109,12 @@ def name
108109

109110
subject.kill(0)
110111

112+
Process.wait(pid)
111113
expect(File.exist?(subject.pid_file)).to be_falsey
112114
end
113115

114116
it 'should send kill signal if timeout' do
115-
fork do
117+
pid = fork do
116118
subject.daemonize
117119
sleep
118120
end
@@ -122,13 +124,14 @@ def name
122124
pid = subject.pid
123125

124126
subject.kill(10)
127+
Process.wait(pid)
125128

126129
expect(File.exist?(subject.pid_file)).to be_falsey
127130
expect(Process.running?(pid)).to be_falsey
128131
end
129132

130133
it "should restart" do
131-
fork do
134+
pid = fork do
132135
subject.on_restart {}
133136
subject.daemonize
134137
sleep 5
@@ -140,7 +143,8 @@ def name
140143
TestServer.restart(subject.pid_file)
141144
end
142145

143-
expect { sleep 0.1 while File.exist?(subject.pid_file) }.to take_less_then(20)
146+
Process.wait(pid)
147+
expect(File.exist?(subject.pid_file)).to be_falsey
144148
end
145149

146150
it "should ignore if no restart block specified" do
@@ -154,7 +158,7 @@ def name
154158
end
155159

156160
it "should exit and raise if pid file already exist" do
157-
fork do
161+
pid = fork do
158162
subject.daemonize
159163
sleep 5
160164
end
@@ -164,6 +168,9 @@ def name
164168
expect { subject.daemonize }.to raise_error(PidFileExist)
165169

166170
expect(File.exist?(subject.pid_file)).to be_truthy
171+
172+
subject.kill
173+
Process.wait(pid)
167174
end
168175

169176
it "should raise if no pid file" do

0 commit comments

Comments
 (0)