Commit f2e8d8a6 authored by Ramya Authappan's avatar Ramya Authappan

Merge branch '335571-refactor-pipeline-status-check' into 'master'

Refactor MR page pipeline status check

See merge request gitlab-org/gitlab!66018
parents d10fd759 b353949b
...@@ -202,7 +202,9 @@ module QA ...@@ -202,7 +202,9 @@ module QA
def has_pipeline_status?(text) def has_pipeline_status?(text)
# Pipelines can be slow, so we wait a bit longer than the usual 10 seconds # Pipelines can be slow, so we wait a bit longer than the usual 10 seconds
has_element?(:merge_request_pipeline_info_content, text: text, wait: 60) wait_until(sleep_interval: 5, reload: false) do
has_element?(:merge_request_pipeline_info_content, text: text, wait: 15 )
end
end end
def has_title?(title) def has_title?(title)
...@@ -236,7 +238,10 @@ module QA ...@@ -236,7 +238,10 @@ module QA
end end
def merged? def merged?
# Revisit after merge page re-architect is done https://gitlab.com/gitlab-org/gitlab/-/issues/300042 # Reloads the page at this point to avoid the problem of the merge status failing to update
# That's the transient UX issue this test is checking for, so if the MR is merged but the UI still shows the
# status as unmerged, the test will fail.
# Revisit after merge page re-architect is done https://gitlab.com/groups/gitlab-org/-/epics/5598
# To remove page refresh logic if possible # To remove page refresh logic if possible
retry_until(max_attempts: 3, reload: true) do retry_until(max_attempts: 3, reload: true) do
has_element?(:merged_status_content, text: 'The changes were merged into', wait: 20) has_element?(:merged_status_content, text: 'The changes were merged into', wait: 20)
......
...@@ -73,7 +73,7 @@ module QA ...@@ -73,7 +73,7 @@ module QA
it 'can still merge MR successfully', testcase: 'https://gitlab.com/gitlab-org/quality/testcases/-/issues/971' do it 'can still merge MR successfully', testcase: 'https://gitlab.com/gitlab-org/quality/testcases/-/issues/971' do
Page::MergeRequest::Show.perform do |show| Page::MergeRequest::Show.perform do |show|
# waiting for manual action status shows status badge 'blocked' on pipelines page # waiting for manual action status shows status badge 'blocked' on pipelines page
show.wait_until(reload: false) { show.has_pipeline_status?('waiting for manual action') } show.has_pipeline_status?('waiting for manual action')
show.merge! show.merge!
expect(show).to be_merged expect(show).to be_merged
......
...@@ -39,9 +39,7 @@ module QA ...@@ -39,9 +39,7 @@ module QA
merge_request.visit! merge_request.visit!
Page::MergeRequest::Show.perform do |mr_widget| Page::MergeRequest::Show.perform do |mr_widget|
Support::Retrier.retry_until(max_attempts: 5, sleep_interval: 5) do mr_widget.has_pipeline_status?('passed')
mr_widget.has_pipeline_status?('passed')
end
expect(mr_widget).to have_content('Test coverage 66.67%') expect(mr_widget).to have_content('Test coverage 66.67%')
end end
end end
......
...@@ -75,22 +75,17 @@ module QA ...@@ -75,22 +75,17 @@ module QA
merge_request.visit! merge_request.visit!
Page::MergeRequest::Show.perform do |show| Page::MergeRequest::Show.perform do |show|
check_pipeline_status(show) # Wait for MR first pipeline to pass first before starting merge trains
show.has_pipeline_status?('passed')
show.merge_via_merge_train show.merge_via_merge_train
check_merge_train_starts(show)
# This is also tested in pipelines_for_merged_results_and_merge_trains_spec.rb as a regular e2e test. # This is also tested in pipelines_for_merged_results_and_merge_trains_spec.rb as a regular e2e test.
# That test reloads the page at this point to avoid the problem of the merge status failing to update show.wait_until(sleep_interval: 5, reload: false) do
# That's the transient UX issue this test is checking for, so if the MR is merged but the UI still shows the show.has_content?('started a merge train')
# status as unmerged, the test will fail. end
merge_request = project.merge_request_with_title(title)
expect(merge_request).not_to be_nil, 'There was a problem fetching the merge request'
# Merge train should start another pipeline and MR won't merged until this is finished # Merge train should start another pipeline and MR won't merged until this is finished
check_pipeline_status(show) show.has_pipeline_status?('passed')
# We use the API to wait until the MR has been merged so that we know the UI should be ready to update # We use the API to wait until the MR has been merged so that we know the UI should be ready to update
show.wait_until(reload: false) do show.wait_until(reload: false) do
...@@ -108,26 +103,10 @@ module QA ...@@ -108,26 +103,10 @@ module QA
SecureRandom.hex(8) SecureRandom.hex(8)
end end
def check_pipeline_status(page_object)
pipeline_passed = page_object.retry_until(max_attempts: 5, sleep_interval: 5) do
page_object.has_pipeline_status?('passed')
end
expect(pipeline_passed).to be_truthy, 'Expected the merged result pipeline to pass.'
end
def check_merge_train_starts(page_object)
train_started = page_object.wait_until(reload: false) do
page_object.has_content? 'started a merge train'
end
expect(train_started).to be_truthy, 'Expected to have system note indicating merge train has started.'
end
def merge_request_state(merge_request) def merge_request_state(merge_request)
Resource::MergeRequest.fabricate_via_api! do |mr| Resource::MergeRequest.fabricate_via_api! do |mr|
mr.project = project mr.project = project
mr.iid = merge_request[:iid] mr.iid = merge_request.iid
end.state end.state
end end
end end
......
...@@ -5,92 +5,100 @@ require 'securerandom' ...@@ -5,92 +5,100 @@ require 'securerandom'
module QA module QA
RSpec.describe 'Release' do RSpec.describe 'Release' do
describe 'Multi-project pipelines' do describe 'Multi-project pipelines' do
let(:upstream_project_name) { "upstream-project-#{SecureRandom.hex(8)}" } let(:downstream_job_name) { 'downstream_job' }
let(:downstream_project_name) { "downstream-project-#{SecureRandom.hex(8)}" } let(:executor) { "qa-runner-#{SecureRandom.hex(4)}" }
let!(:group) { Resource::Group.fabricate_via_api! }
let(:upstream_project) do let(:upstream_project) do
Resource::Project.fabricate_via_api! do |project| Resource::Project.fabricate_via_api! do |project|
project.name = upstream_project_name project.group = group
project.name = 'upstream-project'
end end
end end
let(:downstream_project) do let(:downstream_project) do
Resource::Project.fabricate_via_api! do |project| Resource::Project.fabricate_via_api! do |project|
project.name = downstream_project_name project.group = group
project.name = 'downstream-project'
end end
end end
let!(:runner) do let!(:runner) do
Resource::Runner.fabricate_via_api! do |runner| Resource::Runner.fabricate_via_api! do |runner|
runner.project = upstream_project runner.token = group.sandbox.runners_token
runner.token = upstream_project.group.sandbox.runners_token runner.name = executor
runner.name = upstream_project_name runner.tags = [executor]
runner.tags = [upstream_project_name]
end end
end end
before do before do
Resource::Repository::ProjectPush.fabricate! do |project_push| add_ci_file(downstream_project, downstream_ci_file)
project_push.project = upstream_project add_ci_file(upstream_project, upstream_ci_file)
project_push.file_name = '.gitlab-ci.yml'
project_push.commit_message = 'Add .gitlab-ci.yml'
project_push.file_content = <<~CI
stages:
- test
- deploy
job1:
stage: test
tags: ["#{upstream_project_name}"]
script: echo "done"
staging:
stage: deploy
trigger:
project: #{downstream_project.path_with_namespace}
strategy: depend
CI
end
Resource::Repository::ProjectPush.fabricate! do |project_push|
project_push.project = downstream_project
project_push.file_name = '.gitlab-ci.yml'
project_push.commit_message = 'Add .gitlab-ci.yml'
project_push.file_content = <<~CI
downstream_job:
stage: test
tags: ["#{upstream_project_name}"]
script: echo "done"
CI
end
Flow::Login.sign_in Flow::Login.sign_in
upstream_project.visit!
Resource::MergeRequest.fabricate_via_api! do |merge_request| Flow::Pipeline.visit_latest_pipeline(pipeline_condition: 'succeeded')
merge_request.project = upstream_project
merge_request.target_new_branch = false
end.visit!
end end
after do after do
runner.remove_via_api! runner.remove_via_api!
[upstream_project, downstream_project].each(&:remove_via_api!)
end end
it 'creates a multi-project pipeline', testcase: 'https://gitlab.com/gitlab-org/quality/testcases/-/issues/560' do it 'creates a multi-project pipeline', testcase: 'https://gitlab.com/gitlab-org/quality/testcases/-/issues/560' do
Page::MergeRequest::Show.perform do |show|
expect(show.has_pipeline_status?('passed')).to be_truthy
show.click_pipeline_link
end
Page::Project::Pipeline::Show.perform do |show| Page::Project::Pipeline::Show.perform do |show|
expect(show).to have_passed expect(show).to have_passed
expect(show).not_to have_job("downstream_job") expect(show).not_to have_job(downstream_job_name)
show.expand_child_pipeline show.expand_child_pipeline
expect(show).to have_job("downstream_job") expect(show).to have_job(downstream_job_name)
end end
end end
private
def add_ci_file(project, file)
Resource::Repository::Commit.fabricate_via_api! do |commit|
commit.project = project
commit.commit_message = 'Add CI config file'
commit.add_files([file])
end
end
def upstream_ci_file
{
file_path: '.gitlab-ci.yml',
content: <<~YAML
stages:
- test
- deploy
job1:
stage: test
tags: ["#{executor}"]
script: echo 'done'
staging:
stage: deploy
trigger:
project: #{downstream_project.path_with_namespace}
strategy: depend
YAML
}
end
def downstream_ci_file
{
file_path: '.gitlab-ci.yml',
content: <<~YAML
"#{downstream_job_name}":
stage: test
tags: ["#{executor}"]
script: echo 'done'
YAML
}
end
end end
end end
end end
...@@ -47,9 +47,7 @@ module QA ...@@ -47,9 +47,7 @@ module QA
@merge_request.visit! @merge_request.visit!
Page::MergeRequest::Show.perform do |merge_request| Page::MergeRequest::Show.perform do |merge_request|
# Give time for the runner on Staging to complete pipeline # Give time for the runner on Staging to complete pipeline
Support::Retrier.retry_until(max_attempts: 5, sleep_interval: 5) do merge_request.has_pipeline_status?('passed')
merge_request.has_pipeline_status?('passed')
end
merge_request.merge! merge_request.merge!
end end
Flow::Pipeline.wait_for_latest_pipeline(pipeline_condition: 'succeeded') Flow::Pipeline.wait_for_latest_pipeline(pipeline_condition: 'succeeded')
......
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