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
Capybara::Screenshot.append_timestamp = false
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
Capybara.configure do |config|
......
......@@ -268,6 +268,10 @@ module QA
ENV['JIRA_HOSTNAME']
end
def cache_namespace_name?
enabled?(ENV['CACHE_NAMESPACE_NAME'], default: true)
end
def knapsack?
!!(ENV['KNAPSACK_GENERATE_REPORT'] || ENV['KNAPSACK_REPORT_PATH'] || ENV['KNAPSACK_TEST_FILE_PATTERN'])
end
......
......@@ -9,14 +9,19 @@ module QA
@time ||= Time.now
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:
# 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
def path
"#{sandbox_name}/#{name}"
"#{sandbox_name}/#{name(reset_cache: false)}"
end
def sandbox_name
......
......@@ -17,6 +17,7 @@ module QA
let(:project) do
Resource::Project.fabricate_via_api! do |project|
project.name = 'project-to-test-milestones'
project.group = group
end
end
......
......@@ -55,7 +55,7 @@ module QA
end
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)
Page::Project::Show.perform(&:wait_for_import_success)
......
......@@ -9,6 +9,7 @@ module QA
runner.token = group.reload!.runners_token
runner.name = group.name
runner.tags = [group.name]
runner.project = project_with_success_run
end
end
......@@ -116,34 +117,34 @@ module QA
def ci_file_with_tag
{
file_path: '.gitlab-ci.yml',
content: <<~YAML
test-success:
tags: ["#{group.name}"]
script: echo 'OK'
YAML
file_path: '.gitlab-ci.yml',
content: <<~YAML
test-success:
tags: ["#{group.name}"]
script: echo 'OK'
YAML
}
end
def ci_file_without_existing_tag
{
file_path: '.gitlab-ci.yml',
content: <<~YAML
test-pending:
tags: ['does-not-exist']
script: echo 'OK'
YAML
file_path: '.gitlab-ci.yml',
content: <<~YAML
test-pending:
tags: ['does-not-exist']
script: echo 'OK'
YAML
}
end
def ci_file_failed_run
{
file_path: '.gitlab-ci.yml',
content: <<~YAML
test-fail:
tags: ["#{group.name}"]
script: exit 1
YAML
file_path: '.gitlab-ci.yml',
content: <<~YAML
test-fail:
tags: ["#{group.name}"]
script: exit 1
YAML
}
end
end
......
......@@ -5,20 +5,21 @@ require 'securerandom'
module QA
RSpec.describe 'Release', :docker, :runner do
describe 'Pipelines for merged results and merge trains' do
before(:context) do
@group = Resource::Group.fabricate_via_api!
@runner = Resource::Runner.fabricate_via_api! do |runner|
runner.token = @group.reload!.runners_token
runner.name = @group.name
runner.tags = [@group.name]
let(:group) { Resource::Group.fabricate_via_api! }
let!(:runner) do
Resource::Runner.fabricate_via_api! do |runner|
runner.token = group.reload!.runners_token
runner.name = group.name
runner.tags = [group.name]
runner.project = project
end
end
let(:project) do
Resource::Project.fabricate_via_api! do |project|
project.name = 'pipelines-for-merged-results-and-merge-trains'
project.group = @group
project.group = group
end
end
......@@ -30,9 +31,9 @@ module QA
[
{
file_path: '.gitlab-ci.yml',
content: <<~EOF
content: <<~EOF
test:
tags: [#{@group.name}]
tags: [#{group.name}]
script: echo 'OK'
only:
- merge_requests
......@@ -54,8 +55,8 @@ module QA
end
end
after(:context) do
@runner.remove_via_api! if @runner
after do
runner.remove_via_api! if runner
end
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