diff options
author | Mark Lapierre <mlapierre@gitlab.com> | 2019-02-11 09:04:59 +0000 |
---|---|---|
committer | Ramya Authappan <rauthappan@gitlab.com> | 2019-02-11 09:04:59 +0000 |
commit | 97265d39e72cbb32468a3f1d671820528af02a8b (patch) | |
tree | 03c7d01e071ce0843987ad6f1eb96234fa20074a /qa/qa/resource | |
parent | 25af9032750c215860829fecb196da1e1c5ace6b (diff) | |
download | gitlab-ce-97265d39e72cbb32468a3f1d671820528af02a8b.tar.gz |
[CE] Improve `wait_for_push`
Diffstat (limited to 'qa/qa/resource')
-rw-r--r-- | qa/qa/resource/base.rb | 4 | ||||
-rw-r--r-- | qa/qa/resource/events/base.rb | 37 | ||||
-rw-r--r-- | qa/qa/resource/events/project.rb | 25 | ||||
-rw-r--r-- | qa/qa/resource/fork.rb | 10 | ||||
-rw-r--r-- | qa/qa/resource/group.rb | 2 | ||||
-rw-r--r-- | qa/qa/resource/merge_request.rb | 5 | ||||
-rw-r--r-- | qa/qa/resource/project.rb | 2 | ||||
-rw-r--r-- | qa/qa/resource/repository/project_push.rb | 4 |
8 files changed, 79 insertions, 10 deletions
diff --git a/qa/qa/resource/base.rb b/qa/qa/resource/base.rb index ffe8633dd16..523d92c7ef3 100644 --- a/qa/qa/resource/base.rb +++ b/qa/qa/resource/base.rb @@ -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) diff --git a/qa/qa/resource/events/base.rb b/qa/qa/resource/events/base.rb new file mode 100644 index 00000000000..b50b620b143 --- /dev/null +++ b/qa/qa/resource/events/base.rb @@ -0,0 +1,37 @@ +# 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 diff --git a/qa/qa/resource/events/project.rb b/qa/qa/resource/events/project.rb new file mode 100644 index 00000000000..99c78254f42 --- /dev/null +++ b/qa/qa/resource/events/project.rb @@ -0,0 +1,25 @@ +# 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 diff --git a/qa/qa/resource/fork.rb b/qa/qa/resource/fork.rb index c6243ff43fa..03bc1f0820b 100644 --- a/qa/qa/resource/fork.rb +++ b/qa/qa/resource/fork.rb @@ -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 @@ -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) @@ -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) diff --git a/qa/qa/resource/group.rb b/qa/qa/resource/group.rb index a7a6f931e28..d7f9ec6a836 100644 --- a/qa/qa/resource/group.rb +++ b/qa/qa/resource/group.rb @@ -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 diff --git a/qa/qa/resource/merge_request.rb b/qa/qa/resource/merge_request.rb index 7150098a00a..45cb317e0eb 100644 --- a/qa/qa/resource/merge_request.rb +++ b/qa/qa/resource/merge_request.rb @@ -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) diff --git a/qa/qa/resource/project.rb b/qa/qa/resource/project.rb index 433e5a8f7c9..de1e9f04c36 100644 --- a/qa/qa/resource/project.rb +++ b/qa/qa/resource/project.rb @@ -5,6 +5,8 @@ require 'securerandom' module QA module Resource class Project < Base + include Events::Project + attribute :name attribute :description diff --git a/qa/qa/resource/repository/project_push.rb b/qa/qa/resource/repository/project_push.rb index f4692c3dd4d..cad89ebb0bb 100644 --- a/qa/qa/resource/repository/project_push.rb +++ b/qa/qa/resource/repository/project_push.rb @@ -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' @@ -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 @@ -30,6 +33,7 @@ module QA def fabricate! super project.visit! + project.wait_for_push @commit_message if @wait_for_push end end end |