Commit 395abc98 authored by Sanad Liaquat's avatar Sanad Liaquat

Merge branch '324357-fix-merge-train-spec-flakiness' into 'master'

Fix merge train trainsient test flakiness

See merge request gitlab-org/gitlab!56562
parents e379d0c9 c5b78fc0
...@@ -23,7 +23,7 @@ module QA ...@@ -23,7 +23,7 @@ module QA
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 +31,23 @@ module QA ...@@ -31,29 +31,23 @@ module QA
[ [
{ {
file_path: '.gitlab-ci.yml', file_path: '.gitlab-ci.yml',
content: <<~EOF content: <<~YAML
test: test:
tags: [#{group.name}] tags: [#{group.name}]
script: echo 'OK' script: echo 'OK'
only: only:
- merge_requests - merge_requests
EOF YAML
} }
] ]
) )
end 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
...@@ -66,35 +60,25 @@ module QA ...@@ -66,35 +60,25 @@ module QA
Runtime::Env.transient_trials.times do |i| Runtime::Env.transient_trials.times do |i|
QA::Runtime::Logger.info("Transient bug test action - Trial #{i}") QA::Runtime::Logger.info("Transient bug test action - Trial #{i}")
random_string_for_this_trial = SecureRandom.hex(8)
branch_name = "merge-train-#{random_string_for_this_trial}"
title = "merge train transient bug test #{random_string_for_this_trial}" title = "merge train transient bug test #{random_string_for_this_trial}"
# Create a branch that will be merged into the default branch # Create a merge request to be merged to master
Resource::Repository::ProjectPush.fabricate! do |project_push| merge_request = Resource::MergeRequest.fabricate_via_api! do |merge_request|
project_push.project = project merge_request.title = title
project_push.new_branch = true merge_request.project = project
project_push.branch_name = branch_name merge_request.description = title
project_push.file_name = "file-#{random_string_for_this_trial}.txt" merge_request.target_new_branch = false
project_push.file_content = "merge me" merge_request.file_name = random_string_for_this_trial
merge_request.file_content = random_string_for_this_trial
end end
# Create a merge request to merge the branch we just created merge_request.visit!
Resource::MergeRequest.fabricate_via_api! do |merge_request|
merge_request.project = project
merge_request.source_branch = branch_name
merge_request.no_preparation = true
merge_request.title = title
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 check_pipeline_status(show)
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
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 # That test reloads the page at this point to avoid the problem of the merge status failing to update
...@@ -103,23 +87,49 @@ module QA ...@@ -103,23 +87,49 @@ module QA
merge_request = project.merge_request_with_title(title) merge_request = project.merge_request_with_title(title)
expect(merge_request).not_to be_nil, "There was a problem fetching the merge request" 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
check_pipeline_status(show)
# 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
mr = Resource::MergeRequest.fabricate_via_api! do |mr| merge_request_state(merge_request) == 'merged'
mr.project = project
mr.id = merge_request[:iid]
end
mr.state == 'merged'
end end
expect(show).to be_merged, "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."
expect(show).to have_pipeline_status(/Merge train pipeline #\d+ passed/)
end end
end end
end end
private
def random_string_for_this_trial
SecureRandom.hex(8)
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)
Resource::MergeRequest.fabricate_via_api! do |mr|
mr.project = project
mr.id = merge_request[:iid]
end.state
end
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