diff options
author | Grzegorz Bizon <grzegorz@gitlab.com> | 2018-06-05 14:50:07 +0000 |
---|---|---|
committer | Grzegorz Bizon <grzegorz@gitlab.com> | 2018-06-05 14:50:07 +0000 |
commit | cb77087246929cc92f6bd7ce2cb306855b6e6219 (patch) | |
tree | 2ab7ed30f560f398761fc16185f7223d89c673bc /spec/models/ci | |
parent | 064218b543d0581acf390dde438cd56fb1b8383f (diff) | |
parent | 36fbe1422666cb5553ccde9e534bb2a504f0f2c1 (diff) | |
download | gitlab-ce-cb77087246929cc92f6bd7ce2cb306855b6e6219.tar.gz |
Merge branch 'optimise-runner-update-cached-info' into 'master'
Optimise runner update cached info
See merge request gitlab-org/gitlab-ce!19187
Diffstat (limited to 'spec/models/ci')
-rw-r--r-- | spec/models/ci/runner_spec.rb | 26 |
1 files changed, 18 insertions, 8 deletions
diff --git a/spec/models/ci/runner_spec.rb b/spec/models/ci/runner_spec.rb index 0f072aa1719..f6433234573 100644 --- a/spec/models/ci/runner_spec.rb +++ b/spec/models/ci/runner_spec.rb @@ -549,7 +549,7 @@ describe Ci::Runner do end describe '#update_cached_info' do - let(:runner) { create(:ci_runner) } + let(:runner) { create(:ci_runner, :project) } subject { runner.update_cached_info(architecture: '18-bit') } @@ -570,17 +570,22 @@ describe Ci::Runner do runner.contacted_at = 2.hours.ago end - it 'updates database' do - expect_redis_update + context 'with invalid runner' do + before do + runner.projects = [] + end + + it 'still updates redis cache and database' do + expect(runner).to be_invalid - expect { subject }.to change { runner.reload.read_attribute(:contacted_at) } - .and change { runner.reload.read_attribute(:architecture) } + expect_redis_update + does_db_update + end end - it 'updates cache' do + it 'updates redis cache and database' do expect_redis_update - - subject + does_db_update end end @@ -590,6 +595,11 @@ describe Ci::Runner do expect(redis).to receive(:set).with(redis_key, anything, any_args) end end + + def does_db_update + expect { subject }.to change { runner.reload.read_attribute(:contacted_at) } + .and change { runner.reload.read_attribute(:architecture) } + end end describe '#destroy' do |