Commit b0bd3a48 authored by Mark Lapierre's avatar Mark Lapierre Committed by Dan Davison

Make merge trains in tests independent

If multiple tests use the same project they'll use the same merge
train. That can cause tests to fail if one tries to use the merge
train while it's in an unexpected state, e.g., trying to start a new
train when one is already running.

This creates a separate project for each test that uses a merge
train.

Uses the Commit API to add a file because it's faster than
pushing.

Adds a runners_token attribute to the Group resource, and lets
resources be reloaded so updated data can be fetched. It's not
clear why the runners token isn't available immediately upon
creating a group, but reloading the API data fixes it.
parent 496ffa03
...@@ -284,12 +284,16 @@ module QA ...@@ -284,12 +284,16 @@ module QA
wait_for_animated_element :merge_immediately_button wait_for_animated_element :merge_immediately_button
click_element :merge_immediately_button click_element :merge_immediately_button
finished_loading?
end end
def merge_via_merge_train def merge_via_merge_train
raise ElementNotFound, "Not ready to merge" unless ready_to_merge? raise ElementNotFound, "Not ready to merge" unless ready_to_merge?
click_element(:merge_button, text: "Start merge train") click_element(:merge_button, text: "Start merge train")
finished_loading?
end end
private private
......
...@@ -177,7 +177,7 @@ module QA ...@@ -177,7 +177,7 @@ module QA
# The number of selectors should be able to be reduced after # The number of selectors should be able to be reduced after
# migration to the new spinner is complete. # migration to the new spinner is complete.
# https://gitlab.com/groups/gitlab-org/-/epics/956 # https://gitlab.com/groups/gitlab-org/-/epics/956
has_no_css?('.gl-spinner, .fa-spinner, .spinner', wait: Capybara.default_max_wait_time) has_no_css?('.gl-spinner, .fa-spinner, .spinner', wait: QA::Support::Repeater::DEFAULT_MAX_WAIT_TIME)
end end
def finished_loading_block? def finished_loading_block?
......
...@@ -155,6 +155,8 @@ module QA ...@@ -155,6 +155,8 @@ module QA
def merge! def merge!
click_element :merge_button if ready_to_merge? click_element :merge_button if ready_to_merge?
finished_loading?
raise "Merge did not appear to be successful" unless merged? raise "Merge did not appear to be successful" unless merged?
end end
......
...@@ -31,6 +31,12 @@ module QA ...@@ -31,6 +31,12 @@ module QA
resource_web_url(api_post) resource_web_url(api_post)
end end
def reload!
api_get
self
end
def remove_via_api! def remove_via_api!
api_delete api_delete
end end
......
...@@ -16,6 +16,7 @@ module QA ...@@ -16,6 +16,7 @@ module QA
attribute :id attribute :id
attribute :name attribute :name
attribute :runners_token
def initialize def initialize
@path = Runtime::Namespace.name @path = Runtime::Namespace.name
......
...@@ -6,35 +6,44 @@ module QA ...@@ -6,35 +6,44 @@ module QA
context 'Release', :docker do context 'Release', :docker do
describe 'Pipelines for merged results and merge trains' do describe 'Pipelines for merged results and merge trains' do
before(:context) do before(:context) do
@project = Resource::Project.fabricate_via_api! do |project| @group = Resource::Group.fabricate_via_api!
project.name = 'pipelines-for-merged-results-and-merge-trains'
end
@executor = "qa-runner-#{Time.now.to_i}"
Resource::Runner.fabricate_via_api! do |runner| Resource::Runner.fabricate_via_api! do |runner|
runner.project = @project runner.token = @group.reload!.runners_token
runner.name = @executor runner.name = @group.name
runner.tags = %w[qa test] runner.tags = [@group.name]
end end
end
Resource::Repository::ProjectPush.fabricate! do |project_push| let(:project) do
project_push.project = @project Resource::Project.fabricate_via_api! do |project|
project_push.file_name = '.gitlab-ci.yml' project.name = 'pipelines-for-merged-results-and-merge-trains'
project_push.commit_message = 'Add .gitlab-ci.yml' project.group = @group
project_push.file_content = <<~EOF
test:
tags: ["qa"]
script: echo 'OK'
only:
- merge_requests
EOF
end end
end end
before do before do
Flow::Login.sign_in Resource::Repository::Commit.fabricate_via_api! do |commit|
commit.project = project
commit.commit_message = 'Add .gitlab-ci.yml'
commit.add_files(
[
{
file_path: '.gitlab-ci.yml',
content: <<~EOF
test:
tags: [#{@group.name}]
script: echo 'OK'
only:
- merge_requests
EOF
}
]
)
end
@project.visit! Flow::Login.sign_in
project.visit!
Page::Project::Menu.perform(&:go_to_general_settings) Page::Project::Menu.perform(&:go_to_general_settings)
Page::Project::Settings::Main.perform do |main| Page::Project::Settings::Main.perform do |main|
...@@ -46,7 +55,7 @@ module QA ...@@ -46,7 +55,7 @@ module QA
end end
after(:context) do after(:context) do
Service::DockerRun::GitlabRunner.new(@executor).remove! Service::DockerRun::GitlabRunner.new(@group.name).remove!
end end
it 'creates a pipeline with merged results' do it 'creates a pipeline with merged results' do
...@@ -54,7 +63,7 @@ module QA ...@@ -54,7 +63,7 @@ module QA
# Create a branch that will be merged into master # Create a branch that will be merged into master
Resource::Repository::ProjectPush.fabricate! do |project_push| Resource::Repository::ProjectPush.fabricate! do |project_push|
project_push.project = @project project_push.project = project
project_push.new_branch = true project_push.new_branch = true
project_push.branch_name = branch_name project_push.branch_name = branch_name
project_push.file_name = "file-#{SecureRandom.hex(8)}.txt" project_push.file_name = "file-#{SecureRandom.hex(8)}.txt"
...@@ -62,7 +71,7 @@ module QA ...@@ -62,7 +71,7 @@ module QA
# Create a merge request to merge the branch we just created # Create a merge request to merge the branch we just created
Resource::MergeRequest.fabricate_via_api! do |merge_request| Resource::MergeRequest.fabricate_via_api! do |merge_request|
merge_request.project = @project merge_request.project = project
merge_request.source_branch = branch_name merge_request.source_branch = branch_name
merge_request.no_preparation = true merge_request.no_preparation = true
end.visit! end.visit!
...@@ -89,7 +98,7 @@ module QA ...@@ -89,7 +98,7 @@ module QA
# Create a branch that will be merged into master # Create a branch that will be merged into master
Resource::Repository::ProjectPush.fabricate! do |project_push| Resource::Repository::ProjectPush.fabricate! do |project_push|
project_push.project = @project project_push.project = project
project_push.new_branch = true project_push.new_branch = true
project_push.branch_name = branch_name project_push.branch_name = branch_name
project_push.file_name = "file-#{SecureRandom.hex(8)}.txt" project_push.file_name = "file-#{SecureRandom.hex(8)}.txt"
...@@ -98,7 +107,7 @@ module QA ...@@ -98,7 +107,7 @@ module QA
# Create a merge request to merge the branch we just created # Create a merge request to merge the branch we just created
Resource::MergeRequest.fabricate_via_api! do |merge_request| Resource::MergeRequest.fabricate_via_api! do |merge_request|
merge_request.project = @project merge_request.project = project
merge_request.source_branch = branch_name merge_request.source_branch = branch_name
merge_request.no_preparation = true merge_request.no_preparation = true
end.visit! end.visit!
......
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