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
wait_for_animated_element :merge_immediately_button
click_element :merge_immediately_button
finished_loading?
end
def merge_via_merge_train
raise ElementNotFound, "Not ready to merge" unless ready_to_merge?
click_element(:merge_button, text: "Start merge train")
finished_loading?
end
private
......
......@@ -177,7 +177,7 @@ module QA
# The number of selectors should be able to be reduced after
# migration to the new spinner is complete.
# 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
def finished_loading_block?
......
......@@ -155,6 +155,8 @@ module QA
def merge!
click_element :merge_button if ready_to_merge?
finished_loading?
raise "Merge did not appear to be successful" unless merged?
end
......
......@@ -31,6 +31,12 @@ module QA
resource_web_url(api_post)
end
def reload!
api_get
self
end
def remove_via_api!
api_delete
end
......
......@@ -16,6 +16,7 @@ module QA
attribute :id
attribute :name
attribute :runners_token
def initialize
@path = Runtime::Namespace.name
......
......@@ -6,35 +6,44 @@ module QA
context 'Release', :docker do
describe 'Pipelines for merged results and merge trains' do
before(:context) do
@project = Resource::Project.fabricate_via_api! do |project|
project.name = 'pipelines-for-merged-results-and-merge-trains'
end
@executor = "qa-runner-#{Time.now.to_i}"
@group = Resource::Group.fabricate_via_api!
Resource::Runner.fabricate_via_api! do |runner|
runner.project = @project
runner.name = @executor
runner.tags = %w[qa test]
runner.token = @group.reload!.runners_token
runner.name = @group.name
runner.tags = [@group.name]
end
end
Resource::Repository::ProjectPush.fabricate! do |project_push|
project_push.project = @project
project_push.file_name = '.gitlab-ci.yml'
project_push.commit_message = 'Add .gitlab-ci.yml'
project_push.file_content = <<~EOF
test:
tags: ["qa"]
script: echo 'OK'
only:
- merge_requests
EOF
let(:project) do
Resource::Project.fabricate_via_api! do |project|
project.name = 'pipelines-for-merged-results-and-merge-trains'
project.group = @group
end
end
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::Settings::Main.perform do |main|
......@@ -46,7 +55,7 @@ module QA
end
after(:context) do
Service::DockerRun::GitlabRunner.new(@executor).remove!
Service::DockerRun::GitlabRunner.new(@group.name).remove!
end
it 'creates a pipeline with merged results' do
......@@ -54,7 +63,7 @@ module QA
# Create a branch that will be merged into master
Resource::Repository::ProjectPush.fabricate! do |project_push|
project_push.project = @project
project_push.project = project
project_push.new_branch = true
project_push.branch_name = branch_name
project_push.file_name = "file-#{SecureRandom.hex(8)}.txt"
......@@ -62,7 +71,7 @@ module QA
# Create a merge request to merge the branch we just created
Resource::MergeRequest.fabricate_via_api! do |merge_request|
merge_request.project = @project
merge_request.project = project
merge_request.source_branch = branch_name
merge_request.no_preparation = true
end.visit!
......@@ -89,7 +98,7 @@ module QA
# Create a branch that will be merged into master
Resource::Repository::ProjectPush.fabricate! do |project_push|
project_push.project = @project
project_push.project = project
project_push.new_branch = true
project_push.branch_name = branch_name
project_push.file_name = "file-#{SecureRandom.hex(8)}.txt"
......@@ -98,7 +107,7 @@ module QA
# Create a merge request to merge the branch we just created
Resource::MergeRequest.fabricate_via_api! do |merge_request|
merge_request.project = @project
merge_request.project = project
merge_request.source_branch = branch_name
merge_request.no_preparation = true
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