diff options
Diffstat (limited to 'spec/support')
-rw-r--r-- | spec/support/prometheus_helpers.rb | 34 | ||||
-rw-r--r-- | spec/support/slack_mattermost_notifications_shared_examples.rb | 14 | ||||
-rw-r--r-- | spec/support/wait_for_requests.rb | 8 | ||||
-rw-r--r-- | spec/support/wait_for_vue_resource.rb | 14 |
4 files changed, 62 insertions, 8 deletions
diff --git a/spec/support/prometheus_helpers.rb b/spec/support/prometheus_helpers.rb index a204365431b..51987c7767d 100644 --- a/spec/support/prometheus_helpers.rb +++ b/spec/support/prometheus_helpers.rb @@ -7,17 +7,29 @@ module PrometheusHelpers %{sum(rate(container_cpu_usage_seconds_total{container_name!="POD",environment="#{environment_slug}"}[2m])) / count(container_cpu_usage_seconds_total{container_name!="POD",environment="#{environment_slug}"}) * 100} end + def prometheus_ping_url(prometheus_query) + query = { query: prometheus_query }.to_query + + "https://prometheus.example.com/api/v1/query?#{query}" + end + def prometheus_query_url(prometheus_query) query = { query: prometheus_query }.to_query "https://prometheus.example.com/api/v1/query?#{query}" end - def prometheus_query_range_url(prometheus_query, start: 8.hours.ago) + def prometheus_query_with_time_url(prometheus_query, time) + query = { query: prometheus_query, time: time.to_f }.to_query + + "https://prometheus.example.com/api/v1/query?#{query}" + end + + def prometheus_query_range_url(prometheus_query, start: 8.hours.ago, stop: Time.now.to_f) query = { query: prometheus_query, start: start.to_f, - end: Time.now.utc.to_f, + end: stop, step: 1.minute.to_i }.to_query @@ -39,7 +51,12 @@ module PrometheusHelpers def stub_all_prometheus_requests(environment_slug, body: nil, status: 200) stub_prometheus_request( - prometheus_query_url(prometheus_memory_query(environment_slug)), + prometheus_query_with_time_url(prometheus_memory_query(environment_slug), Time.now.utc), + status: status, + body: body || prometheus_value_body + ) + stub_prometheus_request( + prometheus_query_with_time_url(prometheus_memory_query(environment_slug), 8.hours.ago), status: status, body: body || prometheus_value_body ) @@ -49,7 +66,12 @@ module PrometheusHelpers body: body || prometheus_values_body ) stub_prometheus_request( - prometheus_query_url(prometheus_cpu_query(environment_slug)), + prometheus_query_with_time_url(prometheus_cpu_query(environment_slug), Time.now.utc), + status: status, + body: body || prometheus_value_body + ) + stub_prometheus_request( + prometheus_query_with_time_url(prometheus_cpu_query(environment_slug), 8.hours.ago), status: status, body: body || prometheus_value_body ) @@ -66,8 +88,10 @@ module PrometheusHelpers metrics: { memory_values: prometheus_values_body('matrix').dig(:data, :result), memory_current: prometheus_value_body('vector').dig(:data, :result), + memory_previous: prometheus_value_body('vector').dig(:data, :result), cpu_values: prometheus_values_body('matrix').dig(:data, :result), - cpu_current: prometheus_value_body('vector').dig(:data, :result) + cpu_current: prometheus_value_body('vector').dig(:data, :result), + cpu_previous: prometheus_value_body('vector').dig(:data, :result) }, last_update: last_update } diff --git a/spec/support/slack_mattermost_notifications_shared_examples.rb b/spec/support/slack_mattermost_notifications_shared_examples.rb index b902fe90707..7e35ebb6c97 100644 --- a/spec/support/slack_mattermost_notifications_shared_examples.rb +++ b/spec/support/slack_mattermost_notifications_shared_examples.rb @@ -328,7 +328,7 @@ RSpec.shared_examples 'slack or mattermost notifications' do context 'only notify for the default branch' do context 'when enabled' do let(:pipeline) do - create(:ci_pipeline, project: project, status: 'failed', ref: 'not-the-default-branch') + create(:ci_pipeline, :failed, project: project, ref: 'not-the-default-branch') end before do @@ -342,6 +342,18 @@ RSpec.shared_examples 'slack or mattermost notifications' do expect(result).to be_falsy end end + + context 'when disabled' do + let(:pipeline) do + create(:ci_pipeline, :failed, project: project, ref: 'not-the-default-branch') + end + + before do + chat_service.notify_only_default_branch = false + end + + it_behaves_like 'call Slack/Mattermost API' + end end end end diff --git a/spec/support/wait_for_requests.rb b/spec/support/wait_for_requests.rb index 73da23391ee..a18c8e03aa6 100644 --- a/spec/support/wait_for_requests.rb +++ b/spec/support/wait_for_requests.rb @@ -1,20 +1,26 @@ require_relative './wait_for_ajax' +require_relative './wait_for_vue_resource' module WaitForRequests extend self include WaitForAjax + include WaitForVueResource # This is inspired by http://www.salsify.com/blog/engineering/tearing-capybara-ajax-tests def wait_for_requests_complete Gitlab::Testing::RequestBlockerMiddleware.block_requests! wait_for('pending AJAX requests complete') do Gitlab::Testing::RequestBlockerMiddleware.num_active_requests.zero? && - finished_all_ajax_requests? + finished_all_requests? end ensure Gitlab::Testing::RequestBlockerMiddleware.allow_requests! end + def finished_all_requests? + finished_all_ajax_requests? && finished_all_vue_resource_requests? + end + # Waits until the passed block returns true def wait_for(condition_name, max_wait_time: Capybara.default_max_wait_time, polling_interval: 0.01) wait_until = Time.now + max_wait_time.seconds diff --git a/spec/support/wait_for_vue_resource.rb b/spec/support/wait_for_vue_resource.rb index 4a4e2e16ee7..3bb3d9c2e51 100644 --- a/spec/support/wait_for_vue_resource.rb +++ b/spec/support/wait_for_vue_resource.rb @@ -1,7 +1,19 @@ module WaitForVueResource def wait_for_vue_resource(spinner: true) Timeout.timeout(Capybara.default_max_wait_time) do - loop until page.evaluate_script('window.activeVueResources').zero? + loop until finished_all_vue_resource_requests? end end + + private + + def finished_all_vue_resource_requests? + return true unless javascript_test? + + page.evaluate_script('window.activeVueResources || 0').zero? + end + + def javascript_test? + Capybara.current_driver == Capybara.javascript_driver + end end |