Skip to content
Snippets Groups Projects
Commit 97265d39 authored by Mark Lapierre's avatar Mark Lapierre Committed by Ramya Authappan
Browse files

[CE] Improve `wait_for_push`

parent 25af9032
No related branches found
No related tags found
No related merge requests found
Showing
with 104 additions and 58 deletions
Loading
Loading
@@ -62,6 +62,11 @@ module QA
autoload :Fork, 'qa/resource/fork'
autoload :SSHKey, 'qa/resource/ssh_key'
 
module Events
autoload :Base, 'qa/resource/events/base'
autoload :Project, 'qa/resource/events/project'
end
module Repository
autoload :Push, 'qa/resource/repository/push'
autoload :ProjectPush, 'qa/resource/repository/project_push'
Loading
Loading
@@ -361,6 +366,7 @@ module QA
autoload :Logging, 'qa/support/page/logging'
end
autoload :Api, 'qa/support/api'
autoload :Waiter, 'qa/support/waiter'
end
end
 
Loading
Loading
Loading
Loading
@@ -18,19 +18,10 @@ module QA
page.refresh
end
 
def wait(max: 60, time: 0.1, reload: true)
start = Time.now
while Time.now - start < max
result = yield
return result if result
sleep(time)
refresh if reload
def wait(max: 60, interval: 0.1, reload: true)
QA::Support::Waiter.wait(max: max, interval: interval) do
yield || (reload && refresh && false)
end
false
end
 
def with_retry(max_attempts: 3, reload: false)
Loading
Loading
@@ -73,7 +64,7 @@ module QA
xhr.send();
JS
 
return false unless wait(time: 0.5, max: 60, reload: false) do
return false unless wait(interval: 0.5, max: 60, reload: false) do
page.evaluate_script('xhr.readyState == XMLHttpRequest.DONE')
end
 
Loading
Loading
Loading
Loading
@@ -21,11 +21,6 @@ module QA
repository_clone_location(:ssh_clone_url)
end
 
def wait_for_push
sleep 5
refresh
end
private
 
def repository_clone_location(kind)
Loading
Loading
Loading
Loading
@@ -27,11 +27,6 @@ module QA
Git::Location.new(find('#project_clone').value)
end
 
def wait_for_push
sleep 5
refresh
end
private
 
def choose_repository_clone(kind, detect_text)
Loading
Loading
Loading
Loading
@@ -148,7 +148,7 @@ module QA
end
 
def add_comment_to_diff(text)
wait(time: 5) do
wait(interval: 5) do
has_text?("No newline at end of file")
end
all_elements(:new_diff_line).first.hover
Loading
Loading
Loading
Loading
@@ -62,7 +62,7 @@ module QA
sleep 5
refresh
 
wait(time: 1) do
wait(interval: 1) do
within_element_by_index(:mirrored_repository_row, row_index) do
last_update = find_element(:mirror_last_update_at, wait: 0)
last_update.has_text?('just now') || last_update.has_text?('seconds')
Loading
Loading
Loading
Loading
@@ -27,6 +27,10 @@ module QA
attributes.each(&method(:public_send))
end
 
def wait(max: 60, interval: 0.1)
QA::Support::Waiter.wait(max: max, interval: interval)
end
private
 
def populate_attribute(name, block)
Loading
Loading
# frozen_string_literal: true
module QA
module Resource
module Events
MAX_WAIT = 10
EventNotFoundError = Class.new(RuntimeError)
module Base
def events(action: nil)
path = [api_get_events]
path << "?action=#{CGI.escape(action)}" if action
parse_body(api_get_from("#{path.join}"))
end
private
def api_get_events
"#{api_get_path}/events"
end
def wait_for_event
event_found = QA::Support::Waiter.wait(max: max_wait) do
yield
end
raise EventNotFoundError, "Timed out waiting for event" unless event_found
end
def max_wait
MAX_WAIT
end
end
end
end
end
# frozen_string_literal: true
module QA
module Resource
module Events
module Project
include Events::Base
def wait_for_push(commit_message)
QA::Runtime::Logger.debug(%Q[#{self.class.name} - wait_for_push with commit message "#{commit_message}"])
wait_for_event do
events(action: 'pushed').any? { |event| event.dig(:push_data, :commit_title) == commit_message }
end
end
def wait_for_push_new_branch(branch_name = "master")
QA::Runtime::Logger.debug(%Q[#{self.class.name} - wait_for_push_new_branch with branch_name "#{branch_name}"])
wait_for_event do
events(action: 'pushed').any? { |event| event.dig(:push_data, :ref) == branch_name }
end
end
end
end
end
end
Loading
Loading
@@ -5,12 +5,12 @@ module QA
class Fork < Base
attribute :project do
Resource::Project.fabricate! do |resource|
resource.name = push.project.name
resource.path_with_namespace = "#{user.name}/#{push.project.name}"
resource.name = upstream.project.name
resource.path_with_namespace = "#{user.name}/#{upstream.project.name}"
end
end
 
attribute :push do
attribute :upstream do
Repository::ProjectPush.fabricate!
end
 
Loading
Loading
@@ -24,7 +24,7 @@ module QA
end
 
def fabricate!
populate(:push, :user)
populate(:upstream, :user)
 
# Sign out as admin and sign is as the fork user
Page::Main::Menu.perform(&:sign_out)
Loading
Loading
@@ -33,7 +33,7 @@ module QA
login.sign_in_using_credentials(user)
end
 
push.project.visit!
upstream.project.visit!
 
Page::Project::Show.perform(&:fork_project)
 
Loading
Loading
Loading
Loading
@@ -33,7 +33,7 @@ module QA
end
 
# Ensure that the group was actually created
group_show.wait(time: 1) do
group_show.wait(interval: 1) do
group_show.has_text?(path) &&
group_show.has_new_project_or_subgroup_dropdown?
end
Loading
Loading
Loading
Loading
@@ -58,10 +58,7 @@ module QA
populate(:target, :source)
 
project.visit!
Page::Project::Show.perform do |project|
project.wait_for_push
project.new_merge_request
end
Page::Project::Show.perform(&:new_merge_request)
Page::MergeRequest::New.perform do |page|
page.fill_title(@title)
page.fill_description(@description)
Loading
Loading
Loading
Loading
@@ -5,6 +5,8 @@ require 'securerandom'
module QA
module Resource
class Project < Base
include Events::Project
attribute :name
attribute :description
 
Loading
Loading
Loading
Loading
@@ -4,6 +4,8 @@ module QA
module Resource
module Repository
class ProjectPush < Repository::Push
attr_writer :wait_for_push
attribute :project do
Project.fabricate! do |resource|
resource.name = 'project-with-code'
Loading
Loading
@@ -17,6 +19,7 @@ module QA
@commit_message = "This is a test commit"
@branch_name = 'master'
@new_branch = true
@wait_for_push = true
end
 
def repository_http_uri
Loading
Loading
@@ -30,6 +33,7 @@ module QA
def fabricate!
super
project.visit!
project.wait_for_push @commit_message if @wait_for_push
end
end
end
Loading
Loading
Loading
Loading
@@ -26,7 +26,6 @@ module QA
push.file_content = "Test with unicode characters ❤✓€❄"
end
 
Page::Project::Show.perform(&:wait_for_push)
merge_request.visit!
 
expect(page).to have_text('to be squashed')
Loading
Loading
@@ -38,9 +37,7 @@ module QA
merge_request.project.visit!
 
Git::Repository.perform do |repository|
repository.uri = Page::Project::Show.act do
repository_clone_http_location.uri
end
repository.uri = merge_request.project.repository_http_location.uri
 
repository.use_default_credentials
 
Loading
Loading
Loading
Loading
@@ -23,7 +23,6 @@ module QA
proj.name = 'project-qa-test'
proj.description = 'project for qa test'
end
project.visit!
 
Git::Repository.perform do |repository|
repository.uri = project.repository_http_location.uri
Loading
Loading
@@ -53,7 +52,8 @@ module QA
push_changes(third_branch)
end
end
Page::Project::Show.perform(&:wait_for_push)
project.wait_for_push commit_message_of_third_branch
project.visit!
end
 
it 'branches are correctly listed after CRUD operations' do
Loading
Loading
Loading
Loading
@@ -3,22 +3,18 @@
module QA
context 'Create' do
describe 'Git clone over HTTP', :ldap_no_tls do
let(:location) do
Page::Project::Show.perform(&:repository_clone_http_location).uri
end
before do
before(:all) do
Runtime::Browser.visit(:gitlab, Page::Main::Login)
Page::Main::Login.perform(&:sign_in_using_credentials)
 
project = Resource::Project.fabricate! do |scenario|
@project = Resource::Project.fabricate! do |scenario|
scenario.name = 'project-with-code'
scenario.description = 'project for git clone tests'
end
project.visit!
@project.visit!
 
Git::Repository.perform do |repository|
repository.uri = location
repository.uri = @project.repository_http_location.uri
repository.use_default_credentials
 
repository.act do
Loading
Loading
@@ -29,12 +25,12 @@ module QA
push_changes
end
end
Page::Project::Show.perform(&:wait_for_push)
@project.wait_for_push_new_branch
end
 
it 'user performs a deep clone' do
Git::Repository.perform do |repository|
repository.uri = location
repository.uri = @project.repository_http_location.uri
repository.use_default_credentials
 
repository.clone
Loading
Loading
@@ -45,7 +41,7 @@ module QA
 
it 'user performs a shallow clone' do
Git::Repository.perform do |repository|
repository.uri = location
repository.uri = @project.repository_http_location.uri
repository.use_default_credentials
 
repository.shallow_clone
Loading
Loading
Loading
Loading
@@ -35,7 +35,7 @@ module QA
end
 
project.visit!
Page::Project::Show.perform(&:wait_for_push)
project.wait_for_push_new_branch
 
# Check that the push worked
expect(page).to have_content(file_name)
Loading
Loading
Loading
Loading
@@ -70,7 +70,7 @@ module QA
end
 
project.visit!
Page::Project::Show.perform(&:wait_for_push)
project.wait_for_push_new_branch
 
# Check that the push worked
expect(page).to have_content(file_name)
Loading
Loading
Loading
Loading
@@ -23,10 +23,7 @@ module QA
 
push.project.visit!
 
Page::Project::Show.perform do |page|
page.wait_for_push
page.wait_for_viewers_to_load
end
Page::Project::Show.perform(&:wait_for_viewers_to_load)
 
expect(page).to have_content('README.md')
expect(page).to have_content('This is a test project')
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment