Commit 7861567e authored by Sanad Liaquat's avatar Sanad Liaquat Committed by Dan Davison

Cache namespace name if env var is set

Use existing group for project and existing project for runner
to avoid creating new resources
parent a1c27e95
...@@ -133,7 +133,7 @@ module QA ...@@ -133,7 +133,7 @@ module QA
Capybara::Screenshot.append_timestamp = false Capybara::Screenshot.append_timestamp = false
Capybara::Screenshot.register_filename_prefix_formatter(:rspec) do |example| Capybara::Screenshot.register_filename_prefix_formatter(:rspec) do |example|
::File.join(QA::Runtime::Namespace.name, example.full_description.downcase.parameterize(separator: "_")[0..99]) ::File.join(QA::Runtime::Namespace.name(reset_cache: false), example.full_description.downcase.parameterize(separator: "_")[0..99])
end end
Capybara.configure do |config| Capybara.configure do |config|
......
...@@ -268,6 +268,10 @@ module QA ...@@ -268,6 +268,10 @@ module QA
ENV['JIRA_HOSTNAME'] ENV['JIRA_HOSTNAME']
end end
def cache_namespace_name?
enabled?(ENV['CACHE_NAMESPACE_NAME'], default: true)
end
def knapsack? def knapsack?
!!(ENV['KNAPSACK_GENERATE_REPORT'] || ENV['KNAPSACK_REPORT_PATH'] || ENV['KNAPSACK_TEST_FILE_PATTERN']) !!(ENV['KNAPSACK_GENERATE_REPORT'] || ENV['KNAPSACK_REPORT_PATH'] || ENV['KNAPSACK_TEST_FILE_PATTERN'])
end end
......
...@@ -9,14 +9,19 @@ module QA ...@@ -9,14 +9,19 @@ module QA
@time ||= Time.now @time ||= Time.now
end end
def name def name(reset_cache: !Runtime::Env.cache_namespace_name?)
# If any changes are made to the name tag, following script has to be considered: # If any changes are made to the name tag, following script has to be considered:
# https://ops.gitlab.net/gitlab-com/gl-infra/traffic-generator/blob/master/bin/janitor.bash # https://ops.gitlab.net/gitlab-com/gl-infra/traffic-generator/blob/master/bin/janitor.bash
@name ||= Runtime::Env.namespace_name || "qa-test-#{time.strftime('%Y-%m-%d-%H-%M-%S')}-#{SecureRandom.hex(8)}" reset_name_cache if reset_cache
@name ||= Runtime::Env.namespace_name || "qa-test-#{time.strftime('%Y-%m-%d-%H-%M-%S')}-#{SecureRandom.hex(8)}" # rubocop:disable Gitlab/ModuleWithInstanceVariables
end
def reset_name_cache
@name = nil # rubocop:disable Gitlab/ModuleWithInstanceVariables
end end
def path def path
"#{sandbox_name}/#{name}" "#{sandbox_name}/#{name(reset_cache: false)}"
end end
def sandbox_name def sandbox_name
......
...@@ -17,6 +17,7 @@ module QA ...@@ -17,6 +17,7 @@ module QA
let(:project) do let(:project) do
Resource::Project.fabricate_via_api! do |project| Resource::Project.fabricate_via_api! do |project|
project.name = 'project-to-test-milestones' project.name = 'project-to-test-milestones'
project.group = group
end end
end end
......
...@@ -55,7 +55,7 @@ module QA ...@@ -55,7 +55,7 @@ module QA
end end
create_project_using_template(project_name: 'Project using built-in project template', create_project_using_template(project_name: 'Project using built-in project template',
namespace: Runtime::Namespace.name, namespace: Runtime::Namespace.name(reset_cache: false),
template_name: built_in) template_name: built_in)
Page::Project::Show.perform(&:wait_for_import_success) Page::Project::Show.perform(&:wait_for_import_success)
......
...@@ -9,6 +9,7 @@ module QA ...@@ -9,6 +9,7 @@ module QA
runner.token = group.reload!.runners_token runner.token = group.reload!.runners_token
runner.name = group.name runner.name = group.name
runner.tags = [group.name] runner.tags = [group.name]
runner.project = project_with_success_run
end end
end end
......
...@@ -5,20 +5,21 @@ require 'securerandom' ...@@ -5,20 +5,21 @@ require 'securerandom'
module QA module QA
RSpec.describe 'Release', :docker, :runner do RSpec.describe 'Release', :docker, :runner do
describe 'Pipelines for merged results and merge trains' do describe 'Pipelines for merged results and merge trains' do
before(:context) do let(:group) { Resource::Group.fabricate_via_api! }
@group = Resource::Group.fabricate_via_api!
@runner = Resource::Runner.fabricate_via_api! do |runner| let!(:runner) do
runner.token = @group.reload!.runners_token Resource::Runner.fabricate_via_api! do |runner|
runner.name = @group.name runner.token = group.reload!.runners_token
runner.tags = [@group.name] runner.name = group.name
runner.tags = [group.name]
runner.project = project
end end
end end
let(:project) do let(:project) do
Resource::Project.fabricate_via_api! do |project| Resource::Project.fabricate_via_api! do |project|
project.name = 'pipelines-for-merged-results-and-merge-trains' project.name = 'pipelines-for-merged-results-and-merge-trains'
project.group = @group project.group = group
end end
end end
...@@ -32,7 +33,7 @@ module QA ...@@ -32,7 +33,7 @@ module QA
file_path: '.gitlab-ci.yml', file_path: '.gitlab-ci.yml',
content: <<~EOF content: <<~EOF
test: test:
tags: [#{@group.name}] tags: [#{group.name}]
script: echo 'OK' script: echo 'OK'
only: only:
- merge_requests - merge_requests
...@@ -54,8 +55,8 @@ module QA ...@@ -54,8 +55,8 @@ module QA
end end
end end
after(:context) do after do
@runner.remove_via_api! if @runner runner.remove_via_api! if runner
end end
it 'creates a pipeline with merged results', status_issue: 'https://gitlab.com/gitlab-org/quality/testcases/-/issues/562' do it 'creates a pipeline with merged results', status_issue: 'https://gitlab.com/gitlab-org/quality/testcases/-/issues/562' do
......
# frozen_string_literal: true
describe QA::Runtime::Namespace do
include Helpers::StubENV
describe '.name' do
context 'when CACHE_NAMESPACE_NAME is not defined' do
before do
stub_env('CACHE_NAMESPACE_NAME', nil)
end
it 'caches name by default' do
name = described_class.name
expect(described_class.name).to eq(name)
end
it 'does not cache name when reset_cache is true' do
name = described_class.name
expect(described_class.name(reset_cache: true)).not_to eq(name)
end
end
context 'when CACHE_NAMESPACE_NAME is defined' do
before do
stub_env('CACHE_NAMESPACE_NAME', 'true')
end
it 'caches name by default' do
name = described_class.name
expect(described_class.name).to eq(name)
end
it 'caches name when reset_cache is false' do
name = described_class.name
expect(described_class.name(reset_cache: false)).to eq(name)
end
it 'does not cache name when reset_cache is true' do
name = described_class.name
expect(described_class.name(reset_cache: true)).not_to eq(name)
end
end
end
describe '.path' do
it 'is always cached' do
path = described_class.path
expect(described_class.path).to eq(path)
end
end
end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment