Commit 74bb62c7 authored by Tiffany Rea's avatar Tiffany Rea Committed by Dan Davison

Simplify test and add wait and retry logics

parent 7281c770
...@@ -225,9 +225,12 @@ module QA ...@@ -225,9 +225,12 @@ module QA
end end
def merge_via_merge_train def merge_via_merge_train
# Revisit after merge page re-architect is done https://gitlab.com/gitlab-org/gitlab/-/issues/300042
# To remove page refresh logic if possible
wait_until_ready_to_merge wait_until_ready_to_merge
wait_until { !find_element(:merge_button).has_text?("when pipeline succeeds") }
click_element(:merge_button, text: "Start merge train") click_element(:merge_button)
finished_loading? finished_loading?
end end
......
...@@ -224,8 +224,7 @@ module QA ...@@ -224,8 +224,7 @@ module QA
end end
def merge! def merge!
wait_until_ready_to_merge try_to_merge!
click_element(:merge_button)
finished_loading? finished_loading?
raise "Merge did not appear to be successful" unless merged? raise "Merge did not appear to be successful" unless merged?
...@@ -237,7 +236,11 @@ module QA ...@@ -237,7 +236,11 @@ module QA
end end
def merged? def merged?
has_element?(:merged_status_content, text: 'The changes were merged into', wait: 60) # Revisit after merge page re-architect is done https://gitlab.com/gitlab-org/gitlab/-/issues/300042
# To remove page refresh logic if possible
retry_until(max_attempts: 3, reload: true) do
has_element?(:merged_status_content, text: 'The changes were merged into', wait: 20)
end
end end
# Check if the MR is able to be merged # Check if the MR is able to be merged
...@@ -280,7 +283,10 @@ module QA ...@@ -280,7 +283,10 @@ module QA
end end
def try_to_merge! def try_to_merge!
# Revisit after merge page re-architect is done https://gitlab.com/gitlab-org/gitlab/-/issues/300042
# To remove page refresh logic if possible
wait_until_ready_to_merge wait_until_ready_to_merge
wait_until { !find_element(:merge_button).has_text?("when pipeline succeeds") }
click_element(:merge_button) click_element(:merge_button)
end end
......
# frozen_string_literal: true # frozen_string_literal: true
require 'securerandom' require 'faker'
module QA module QA
RSpec.describe 'Verify', :runner do RSpec.describe 'Verify', :runner do
describe 'Pipelines for merged results and merge trains' do describe 'Pipelines for merged results and merge trains' do
let(:group) { Resource::Group.fabricate_via_api! } let(:executor) { "qa-runner-#{Faker::Alphanumeric.alphanumeric(8)}" }
let!(:runner) do let!(:runner) do
Resource::Runner.fabricate_via_api! do |runner| Resource::Runner.fabricate_via_api! do |runner|
runner.token = group.reload!.runners_token
runner.name = group.name
runner.tags = [group.name]
runner.project = project runner.project = project
runner.name = executor
runner.tags = [executor]
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-merge-trains'
project.group = group
end end
end end
before do let!(:ci_file) do
Resource::Repository::Commit.fabricate_via_api! do |commit| Resource::Repository::Commit.fabricate_via_api! do |commit|
commit.project = project commit.project = project
commit.commit_message = 'Add .gitlab-ci.yml' commit.commit_message = 'Add .gitlab-ci.yml'
...@@ -31,29 +29,33 @@ module QA ...@@ -31,29 +29,33 @@ module QA
[ [
{ {
file_path: '.gitlab-ci.yml', file_path: '.gitlab-ci.yml',
content: <<~EOF content: <<~YAML
test: test:
tags: [#{group.name}] tags: [#{executor}]
script: echo 'OK' script: echo 'OK'
only: only:
- merge_requests - merge_requests
EOF YAML
} }
] ]
) )
end end
end
let(:merge_request) do
Resource::MergeRequest.fabricate_via_api! do |merge_request|
merge_request.project = project
merge_request.description = Faker::Lorem.sentence
merge_request.target_new_branch = false
merge_request.file_name = Faker::Lorem.word
merge_request.file_content = Faker::Lorem.sentence
end
end
before do
Flow::Login.sign_in Flow::Login.sign_in
project.visit! project.visit!
Flow::MergeRequest.enable_merge_trains
Page::Project::Menu.perform(&:go_to_general_settings)
Page::Project::Settings::Main.perform do |main|
main.expand_merge_requests_settings do |settings|
settings.click_pipelines_for_merged_results_checkbox
settings.click_merge_trains_checkbox
settings.click_save_changes
end
end
end end
after do after do
...@@ -61,77 +63,28 @@ module QA ...@@ -61,77 +63,28 @@ module QA
end end
it 'creates a pipeline with merged results', testcase: 'https://gitlab.com/gitlab-org/quality/testcases/-/issues/562' do it 'creates a pipeline with merged results', testcase: 'https://gitlab.com/gitlab-org/quality/testcases/-/issues/562' do
branch_name = "merged-results-#{SecureRandom.hex(8)}" merge_request.visit!
# Create a branch that will be merged into the default branch
Resource::Repository::ProjectPush.fabricate! do |project_push|
project_push.project = project
project_push.new_branch = true
project_push.branch_name = branch_name
project_push.file_name = "file-#{SecureRandom.hex(8)}.txt"
end
# 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.source_branch = branch_name
merge_request.no_preparation = true
end.visit!
Page::MergeRequest::Show.perform do |show| Page::MergeRequest::Show.perform do |show|
pipeline_passed = Support::Retrier.retry_until(max_attempts: 5, sleep_interval: 5) do expect(show).to have_pipeline_status('passed'), 'Expected the merge request pipeline to pass.'
show.has_pipeline_status?(/Merged result pipeline #\d+ passed/)
end
expect(pipeline_passed).to be_truthy, "Expected the merged result pipeline to pass."
# The default option is to merge via merge train, # The default option is to merge via merge train,
# but that is covered by the 'merges via a merge train' test # but that is covered by the 'merges via a merge train' test
show.skip_merge_train_and_merge_immediately show.skip_merge_train_and_merge_immediately
end
merged = Page::MergeRequest::Show.perform(&:merged?)
expect(merged).to be_truthy, "Expected content 'The changes were merged' but it did not appear." expect(show).to be_merged, "Expected content 'The changes were merged' but it did not appear."
end
end end
it 'merges via a merge train', testcase: 'https://gitlab.com/gitlab-org/quality/testcases/-/issues/561' do it 'merges via a merge train', testcase: 'https://gitlab.com/gitlab-org/quality/testcases/-/issues/561' do
branch_name = "merge-train-#{SecureRandom.hex(8)}" merge_request.visit!
# Create a branch that will be merged into the default branch
Resource::Repository::ProjectPush.fabricate! do |project_push|
project_push.project = project
project_push.new_branch = true
project_push.branch_name = branch_name
project_push.file_name = "file-#{SecureRandom.hex(8)}.txt"
project_push.file_content = "merge me"
end
# 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.source_branch = branch_name
merge_request.no_preparation = true
end.visit!
Page::MergeRequest::Show.perform do |show| Page::MergeRequest::Show.perform do |show|
pipeline_passed = show.retry_until(max_attempts: 5, sleep_interval: 5) do expect(show).to have_pipeline_status('passed'), 'Expected the merge request pipeline to pass.'
show.has_pipeline_status?(/Merged result pipeline #\d+ passed/)
end
expect(pipeline_passed).to be_truthy, "Expected the merged result pipeline to pass."
show.merge_via_merge_train show.merge_via_merge_train
# It's faster to refresh the page than to wait for the UI to expect(show).to be_merged, "Expected content 'The changes were merged' but it did not appear."
# automatically refresh, so we reload if the merge status
# doesn't update quickly.
merged = show.retry_until(max_attempts: 5, reload: true, sleep_interval: 5) do
show.merged?
end
expect(merged).to be_truthy, "Expected content 'The changes were merged' but it did not appear."
expect(show).to have_pipeline_status(/Merge train pipeline #\d+ passed/)
end end
end 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