Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2023-05-17 19:05:49 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2023-05-17 19:05:49 +0300
commit43a25d93ebdabea52f99b05e15b06250cd8f07d7 (patch)
treedceebdc68925362117480a5d672bcff122fb625b /spec/services/keys/last_used_service_spec.rb
parent20c84b99005abd1c82101dfeff264ac50d2df211 (diff)
Add latest changes from gitlab-org/gitlab@16-0-stable-eev16.0.0-rc42
Diffstat (limited to 'spec/services/keys/last_used_service_spec.rb')
-rw-r--r--spec/services/keys/last_used_service_spec.rb60
1 files changed, 35 insertions, 25 deletions
diff --git a/spec/services/keys/last_used_service_spec.rb b/spec/services/keys/last_used_service_spec.rb
index a2cd5ffdd38..32100d793ff 100644
--- a/spec/services/keys/last_used_service_spec.rb
+++ b/spec/services/keys/last_used_service_spec.rb
@@ -2,33 +2,51 @@
require 'spec_helper'
-RSpec.describe Keys::LastUsedService do
+RSpec.describe Keys::LastUsedService, feature_category: :source_code_management do
describe '#execute', :clean_gitlab_redis_shared_state do
- it 'updates the key when it has not been used recently' do
- key = create(:key, last_used_at: 1.year.ago)
- time = Time.zone.now
+ context 'when it has not been used recently' do
+ let(:key) { create(:key, last_used_at: 1.year.ago) }
+ let(:time) { Time.zone.now }
- travel_to(time) { described_class.new(key).execute }
+ it 'updates the key' do
+ travel_to(time) { described_class.new(key).execute }
- expect(key.reload.last_used_at).to be_like_time(time)
+ expect(key.reload.last_used_at).to be_like_time(time)
+ end
end
- it 'does not update the key when it has been used recently' do
- time = 1.minute.ago
- key = create(:key, last_used_at: time)
+ context 'when it has been used recently' do
+ let(:time) { 1.minute.ago }
+ let(:key) { create(:key, last_used_at: time) }
- described_class.new(key).execute
+ it 'does not update the key' do
+ described_class.new(key).execute
- expect(key.last_used_at).to be_like_time(time)
+ expect(key.reload.last_used_at).to be_like_time(time)
+ end
end
+ end
+
+ describe '#execute_async', :clean_gitlab_redis_shared_state do
+ context 'when it has not been used recently' do
+ let(:key) { create(:key, last_used_at: 1.year.ago) }
+ let(:time) { Time.zone.now }
- it 'does not update the updated_at field' do
- # Since a lot of these updates could happen in parallel for different keys
- # we want these updates to be as lightweight as possible, hence we want to
- # make sure we _only_ update last_used_at and not always updated_at.
- key = create(:key, last_used_at: 1.year.ago)
+ it 'schedules a job to update last_used_at' do
+ expect(::SshKeys::UpdateLastUsedAtWorker).to receive(:perform_async)
- expect { described_class.new(key).execute }.not_to change { key.updated_at }
+ travel_to(time) { described_class.new(key).execute_async }
+ end
+ end
+
+ context 'when it has been used recently' do
+ let(:key) { create(:key, last_used_at: 1.minute.ago) }
+
+ it 'does not schedule a job to update last_used_at' do
+ expect(::SshKeys::UpdateLastUsedAtWorker).not_to receive(:perform_async)
+
+ described_class.new(key).execute_async
+ end
end
end
@@ -47,14 +65,6 @@ RSpec.describe Keys::LastUsedService do
expect(service.update?).to eq(true)
end
- it 'returns false when a lease has already been obtained' do
- key = build(:key, last_used_at: 1.year.ago)
- service = described_class.new(key)
-
- expect(service.update?).to eq(true)
- expect(service.update?).to eq(false)
- end
-
it 'returns false when the key does not yet need to be updated' do
key = build(:key, last_used_at: 1.minute.ago)
service = described_class.new(key)