summaryrefslogtreecommitdiff
path: root/spec/models
diff options
context:
space:
mode:
authorMatija Čupić <matteeyah@gmail.com>2018-01-29 20:56:28 +0100
committerMatija Čupić <matteeyah@gmail.com>2018-01-29 20:56:28 +0100
commitbdd3e39b0bd4e8fcec5d6e2d97297840211dd921 (patch)
tree80b344923c69a2096383d8f39e33ddaf9657421b /spec/models
parent92ac2b9ee68cad8c01a199e6475bbef272818da5 (diff)
downloadgitlab-ce-bdd3e39b0bd4e8fcec5d6e2d97297840211dd921.tar.gz
Move info update implementation to Ci::Runner model
Diffstat (limited to 'spec/models')
-rw-r--r--spec/models/ci/runner_spec.rb52
1 files changed, 47 insertions, 5 deletions
diff --git a/spec/models/ci/runner_spec.rb b/spec/models/ci/runner_spec.rb
index fe9e5ec9436..830f7cd68c5 100644
--- a/spec/models/ci/runner_spec.rb
+++ b/spec/models/ci/runner_spec.rb
@@ -97,7 +97,7 @@ describe Ci::Runner do
context 'no cache value' do
before do
- stub_redis("#{runner.runner_info_key}:contacted_at", nil)
+ stub_redis_runner_contacted_at(nil)
end
context 'never contacted' do
@@ -128,7 +128,7 @@ describe Ci::Runner do
context 'with cache value' do
context 'contacted long time ago time' do
before do
- stub_redis("#{runner.runner_info_key}:contacted_at", 1.year.ago.to_s)
+ stub_redis_runner_contacted_at(1.year.ago.to_s)
end
it { is_expected.to be_falsey }
@@ -136,17 +136,17 @@ describe Ci::Runner do
context 'contacted 1s ago' do
before do
- stub_redis("#{runner.runner_info_key}:contacted_at", 1.second.ago.to_s)
+ stub_redis_runner_contacted_at(1.second.ago.to_s)
end
it { is_expected.to be_truthy }
end
end
- def stub_redis(key, value)
+ def stub_redis_runner_contacted_at(value)
redis = double
allow(Gitlab::Redis::SharedState).to receive(:with).and_yield(redis)
- allow(redis).to receive(:get).with(key).and_return(value)
+ allow(redis).to receive(:get).with("#{runner.send(:runner_info_redis_cache_key)}:contacted_at").and_return(value)
end
end
@@ -391,6 +391,48 @@ describe Ci::Runner do
end
end
+ describe '#update_runner_info' do
+ let(:runner) { create(:ci_runner) }
+
+ subject { runner.update_runner_info(contacted_at: Time.now) }
+
+ context 'when database was updated recently' do
+ before do
+ runner.update(contacted_at: Time.now)
+ end
+
+ it 'updates cache' do
+ expect_redis_update
+
+ subject
+ end
+ end
+
+ context 'when database was not updated recently' do
+ before do
+ runner.update(contacted_at: 2.hours.ago)
+ end
+
+ it 'updates database' do
+ expect_redis_update
+
+ expect { subject }.to change { runner.reload.contacted_at }
+ end
+
+ it 'updates cache' do
+ expect_redis_update
+
+ subject
+ end
+ end
+
+ def expect_redis_update
+ redis = double
+ expect(Gitlab::Redis::SharedState).to receive(:with).and_yield(redis)
+ expect(redis).to receive(:set).with("#{runner.send(:runner_info_redis_cache_key)}:contacted_at", anything)
+ end
+ end
+
describe '#destroy' do
let(:runner) { create(:ci_runner) }