summaryrefslogtreecommitdiff
path: root/spec/models/ci/resource_spec.rb
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2021-08-19 09:08:42 +0000
committerGitLab Bot <gitlab-bot@gitlab.com>2021-08-19 09:08:42 +0000
commitb76ae638462ab0f673e5915986070518dd3f9ad3 (patch)
treebdab0533383b52873be0ec0eb4d3c66598ff8b91 /spec/models/ci/resource_spec.rb
parent434373eabe7b4be9593d18a585fb763f1e5f1a6f (diff)
downloadgitlab-ce-b76ae638462ab0f673e5915986070518dd3f9ad3.tar.gz
Add latest changes from gitlab-org/gitlab@14-2-stable-eev14.2.0-rc42
Diffstat (limited to 'spec/models/ci/resource_spec.rb')
-rw-r--r--spec/models/ci/resource_spec.rb52
1 files changed, 52 insertions, 0 deletions
diff --git a/spec/models/ci/resource_spec.rb b/spec/models/ci/resource_spec.rb
index 5574f6f82b2..e883d704768 100644
--- a/spec/models/ci/resource_spec.rb
+++ b/spec/models/ci/resource_spec.rb
@@ -15,6 +15,22 @@ RSpec.describe Ci::Resource do
end
end
+ describe '.retained' do
+ subject { described_class.retained }
+
+ it "returns the resource if it's retained" do
+ resource = create(:ci_resource, processable: create(:ci_build))
+
+ is_expected.to eq([resource])
+ end
+
+ it "returns empty if it's not retained" do
+ create(:ci_resource, processable: nil)
+
+ is_expected.to be_empty
+ end
+ end
+
describe '.retained_by' do
subject { described_class.retained_by(build) }
@@ -25,4 +41,40 @@ RSpec.describe Ci::Resource do
is_expected.to eq([resource])
end
end
+
+ describe '.stale_processables' do
+ subject { resource_group.resources.stale_processables }
+
+ let!(:resource_group) { create(:ci_resource_group) }
+ let!(:resource) { create(:ci_resource, processable: build, resource_group: resource_group) }
+
+ context 'when the processable is running' do
+ let!(:build) { create(:ci_build, :running, resource_group: resource_group) }
+
+ before do
+ # Creating unrelated builds to make sure the `retained` scope is working
+ create(:ci_build, :running, resource_group: resource_group)
+ end
+
+ it 'returns empty' do
+ is_expected.to be_empty
+ end
+
+ context 'and doomed' do
+ before do
+ build.doom!
+ end
+
+ it 'returns empty' do
+ is_expected.to be_empty
+ end
+
+ it 'returns the stale prosessable a few minutes later' do
+ travel_to(10.minutes.since) do
+ is_expected.to eq([build])
+ end
+ end
+ end
+ end
+ end
end