Commit e6184680 authored by Dan Davison's avatar Dan Davison

Merge branch 'qa-shl-option-to-reset-namespace-cache' into 'master'

Reset namespace name if CACHE_NAMESPACE_NAME is false

See merge request gitlab-org/gitlab!40085
parents 7a30f8fe 7861567e
...@@ -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
...@@ -116,34 +117,34 @@ module QA ...@@ -116,34 +117,34 @@ module QA
def ci_file_with_tag def ci_file_with_tag
{ {
file_path: '.gitlab-ci.yml', file_path: '.gitlab-ci.yml',
content: <<~YAML content: <<~YAML
test-success: test-success:
tags: ["#{group.name}"] tags: ["#{group.name}"]
script: echo 'OK' script: echo 'OK'
YAML YAML
} }
end end
def ci_file_without_existing_tag def ci_file_without_existing_tag
{ {
file_path: '.gitlab-ci.yml', file_path: '.gitlab-ci.yml',
content: <<~YAML content: <<~YAML
test-pending: test-pending:
tags: ['does-not-exist'] tags: ['does-not-exist']
script: echo 'OK' script: echo 'OK'
YAML YAML
} }
end end
def ci_file_failed_run def ci_file_failed_run
{ {
file_path: '.gitlab-ci.yml', file_path: '.gitlab-ci.yml',
content: <<~YAML content: <<~YAML
test-fail: test-fail:
tags: ["#{group.name}"] tags: ["#{group.name}"]
script: exit 1 script: exit 1
YAML YAML
} }
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!
let!(:runner) do
@runner = Resource::Runner.fabricate_via_api! do |runner| Resource::Runner.fabricate_via_api! do |runner|
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
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
...@@ -30,9 +31,9 @@ module QA ...@@ -30,9 +31,9 @@ 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