diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-01-13 12:08:03 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-01-13 12:08:03 +0300 |
commit | c3ad57034cc1cbd6d0ad02de7ac57f6004440c83 (patch) | |
tree | b27a4424d2d5d930ffdaf1ef872851ce691d4e7a /spec/lib/gitlab | |
parent | 6ede90f5dd63d4a1f5ba243b4ed5097bb1a0acab (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/lib/gitlab')
-rw-r--r-- | spec/lib/gitlab/ci/trace_spec.rb | 62 |
1 files changed, 62 insertions, 0 deletions
diff --git a/spec/lib/gitlab/ci/trace_spec.rb b/spec/lib/gitlab/ci/trace_spec.rb index f7bc5686b68..574c2b73722 100644 --- a/spec/lib/gitlab/ci/trace_spec.rb +++ b/spec/lib/gitlab/ci/trace_spec.rb @@ -26,4 +26,66 @@ describe Gitlab::Ci::Trace, :clean_gitlab_redis_shared_state do it_behaves_like 'trace with enabled live trace feature' end + + describe '#update_interval' do + context 'it is not being watched' do + it 'returns 30 seconds' do + expect(trace.update_interval).to eq(30.seconds) + end + end + + context 'it is being watched' do + before do + trace.being_watched! + end + + it 'returns 3 seconds' do + expect(trace.update_interval).to eq(3.seconds) + end + end + end + + describe '#being_watched!' do + let(:cache_key) { "gitlab:ci:trace:#{build.id}:watched" } + + it 'sets gitlab:ci:trace:<job.id>:watched in redis' do + trace.being_watched! + + result = Gitlab::Redis::SharedState.with do |redis| + redis.exists(cache_key) + end + + expect(result).to eq(true) + end + + it 'updates the expiry of gitlab:ci:trace:<job.id>:watched in redis', :clean_gitlab_redis_shared_state do + Gitlab::Redis::SharedState.with do |redis| + redis.set(cache_key, true, ex: 4.seconds) + end + + expect do + trace.being_watched! + end.to change { Gitlab::Redis::SharedState.with { |redis| redis.pttl(cache_key) } } + end + end + + describe '#being_watched?' do + context 'gitlab:ci:trace:<job.id>:watched in redis is set', :clean_gitlab_redis_shared_state do + before do + Gitlab::Redis::SharedState.with do |redis| + redis.set("gitlab:ci:trace:#{build.id}:watched", true) + end + end + + it 'returns true' do + expect(trace.being_watched?).to be(true) + end + end + + context 'gitlab:ci:trace:<job.id>:watched in redis is not set' do + it 'returns false' do + expect(trace.being_watched?).to be(false) + end + end + end end |