summaryrefslogtreecommitdiff
path: root/spec/lib/gitlab/loop_helpers_spec.rb
diff options
context:
space:
mode:
authorShinya Maeda <shinya@gitlab.com>2019-01-17 15:06:37 +0900
committerShinya Maeda <shinya@gitlab.com>2019-01-24 20:50:42 +0900
commit3cc3650dfee5132c120b2b418918f12b3eebcde2 (patch)
tree0497feec4829ed16e0b0d37954b0998a4d8fac15 /spec/lib/gitlab/loop_helpers_spec.rb
parent490eeb5159945107576c756b22c08f99b45a8463 (diff)
downloadgitlab-ce-3cc3650dfee5132c120b2b418918f12b3eebcde2.tar.gz
Remove expired artifacts periodically
Rename Introduce Destroy expired job artifacts service Revert a bit Add changelog Use expired Improve Fix spec Fix spec Use bang for destroy Introduce iteration limit Update comment Simplify more Refacor Remove unnecessary thing Fix comments Fix coding offence Make loop helper exception free
Diffstat (limited to 'spec/lib/gitlab/loop_helpers_spec.rb')
-rw-r--r--spec/lib/gitlab/loop_helpers_spec.rb45
1 files changed, 45 insertions, 0 deletions
diff --git a/spec/lib/gitlab/loop_helpers_spec.rb b/spec/lib/gitlab/loop_helpers_spec.rb
new file mode 100644
index 00000000000..e17a0342d64
--- /dev/null
+++ b/spec/lib/gitlab/loop_helpers_spec.rb
@@ -0,0 +1,45 @@
+require 'spec_helper'
+
+describe Gitlab::LoopHelpers do
+ let(:class_instance) { (Class.new { include ::Gitlab::LoopHelpers }).new }
+
+ describe '#loop_until' do
+ subject do
+ class_instance.loop_until(**params) { true }
+ end
+
+ context 'when limit is not given' do
+ let(:params) { { limit: nil } }
+
+ it 'raises an error' do
+ expect { subject }.to raise_error(ArgumentError)
+ end
+ end
+
+ context 'when timeout is specified' do
+ let(:params) { { timeout: 1.second } }
+
+ it "returns false after it's expired" do
+ is_expected.to be_falsy
+ end
+
+ it 'executes the block at least once' do
+ expect { |b| class_instance.loop_until(**params, &b) }
+ .to yield_control.at_least(1)
+ end
+ end
+
+ context 'when iteration limit is specified' do
+ let(:params) { { limit: 1 } }
+
+ it "returns false after it's expired" do
+ is_expected.to be_falsy
+ end
+
+ it 'executes the block once' do
+ expect { |b| class_instance.loop_until(**params, &b) }
+ .to yield_control.once
+ end
+ end
+ end
+end