summaryrefslogtreecommitdiff
path: root/spec/lib/gitlab/daemon_spec.rb
diff options
context:
space:
mode:
authorKamil Trzciński <ayufan@ayufan.eu>2019-08-21 11:32:45 +0200
committerKamil Trzciński <ayufan@ayufan.eu>2019-08-21 12:06:10 +0200
commitcb193cd6b54ee9ac0cf87650100585293540abfa (patch)
tree06463ffc03a5877779e4ea3db146538c410ef3fa /spec/lib/gitlab/daemon_spec.rb
parent3683d2d251889865334f861791e5e743dca48898 (diff)
downloadgitlab-ce-cb193cd6b54ee9ac0cf87650100585293540abfa.tar.gz
Improve resillency of monitor
- Retry connection when it fails - Properly shutdown daemon - Stop monitor if the Exception is raised - Properly guard exception handling
Diffstat (limited to 'spec/lib/gitlab/daemon_spec.rb')
-rw-r--r--spec/lib/gitlab/daemon_spec.rb30
1 files changed, 24 insertions, 6 deletions
diff --git a/spec/lib/gitlab/daemon_spec.rb b/spec/lib/gitlab/daemon_spec.rb
index d3e73314b87..0372b770844 100644
--- a/spec/lib/gitlab/daemon_spec.rb
+++ b/spec/lib/gitlab/daemon_spec.rb
@@ -34,12 +34,12 @@ describe Gitlab::Daemon do
end
end
- describe 'when Daemon is enabled' do
+ context 'when Daemon is enabled' do
before do
allow(subject).to receive(:enabled?).and_return(true)
end
- describe 'when Daemon is stopped' do
+ context 'when Daemon is stopped' do
describe '#start' do
it 'starts the Daemon' do
expect { subject.start.join }.to change { subject.thread? }.from(false).to(true)
@@ -57,14 +57,14 @@ describe Gitlab::Daemon do
end
end
- describe 'when Daemon is running' do
+ context 'when Daemon is running' do
before do
- subject.start.join
+ subject.start
end
describe '#start' do
it "doesn't start running Daemon" do
- expect { subject.start.join }.not_to change { subject.thread? }
+ expect { subject.start.join }.not_to change { subject.thread }
expect(subject).to have_received(:start_working).once
end
@@ -76,11 +76,29 @@ describe Gitlab::Daemon do
expect(subject).to have_received(:stop_working)
end
+
+ context 'when stop_working raises exception' do
+ before do
+ allow(subject).to receive(:start_working) do
+ sleep(1000)
+ end
+ end
+
+ it 'shutdowns Daemon' do
+ expect(subject).to receive(:stop_working) do
+ subject.thread.raise(Interrupt)
+ end
+
+ expect(subject.thread).to be_alive
+ expect { subject.stop }.not_to raise_error
+ expect(subject.thread).to be_nil
+ end
+ end
end
end
end
- describe 'when Daemon is disabled' do
+ context 'when Daemon is disabled' do
before do
allow(subject).to receive(:enabled?).and_return(false)
end