diff --git a/qa/qa/runtime/namespace.rb b/qa/qa/runtime/namespace.rb index 575d22438a7e4083fb3a19ff4eb737d23a046fd5..393074956705a2f9528b08123781b5ac5bbaec7d 100644 --- a/qa/qa/runtime/namespace.rb +++ b/qa/qa/runtime/namespace.rb @@ -18,16 +18,26 @@ def group_name Env.namespace_name || "qa-test-#{time.strftime('%Y-%m-%d-%H-%M-%S')}-#{SecureRandom.hex(8)}" end - # Predefined top level group name + # Top level group name # # @return [String] def sandbox_name - @sandbox_name ||= Runtime::Env.sandbox_name || - if !QA::Runtime::Env.running_on_dot_com? && QA::Runtime::Env.run_in_parallel? - "gitlab-qa-sandbox-group-#{SecureRandom.hex(4)}-#{Time.now.wday + 1}" - else - "gitlab-qa-sandbox-group-#{Time.now.wday + 1}" - end + return "gitlab-qa-sandbox-group-#{Time.now.wday + 1}" if live_env? + + "qa-sandbox-#{SecureRandom.hex(6)}" + end + + private + + # Test is running on live environment with limitations for top level group creation + # + # @return [Boolean] + def live_env? + return @live_env unless @live_env.nil? + + # Memoize the result of this check so every call doesn't parse gitlab address and check hostname + # There is no case to change gitlab address in the middle of test process so it should be safe to do + @live_env = Runtime::Env.running_on_dot_com? || Runtime::Env.running_on_release? end end end diff --git a/qa/spec/runtime/namespace_spec.rb b/qa/spec/runtime/namespace_spec.rb index f9ef679390850aca48f620a3e7e47e2fc01d13a6..6f8be32429bf7d92dceaf2a08fd7d4f905d76d18 100644 --- a/qa/spec/runtime/namespace_spec.rb +++ b/qa/spec/runtime/namespace_spec.rb @@ -7,7 +7,6 @@ before(:context) do described_class.instance_variable_set(:@time, nil) - described_class.instance_variable_set(:@sandbox_name, nil) end describe '.group_name' do @@ -17,12 +16,37 @@ end describe '.sandbox_name' do + let(:dot_com) { false } + let(:release) { false } + before do - allow(QA::Runtime::Scenario).to receive(:gitlab_address).and_return("http://gitlab.test") + described_class.instance_variable_set(:@live_env, nil) + allow(QA::Runtime::Env).to receive_messages( + running_on_dot_com?: dot_com, + running_on_release?: release + ) + end + + context "when running on .com environment" do + let(:dot_com) { true } + + it "returns day specific sandbox name" do + expect(described_class.sandbox_name).to match(%r{gitlab-qa-sandbox-group-#{time.wday + 1}}) + end + end + + context "when running on release environment" do + let(:release) { true } + + it "returns day specific sandbox name" do + expect(described_class.sandbox_name).to match(%r{gitlab-qa-sandbox-group-#{time.wday + 1}}) + end end - it "returns day specific sandbox name" do - expect(described_class.sandbox_name).to match(%r{gitlab-qa-sandbox-group-#{time.wday + 1}}) + context "when running on ephemeral environment" do + it "returns random sandbox name" do + expect(described_class.sandbox_name).to match(/qa-sandbox-[a-f0-9]{12}/) + end end end end