Skip to content
Snippets Groups Projects
Unverified Commit 75a18c17 authored by Max Woolf's avatar Max Woolf Committed by GitLab
Browse files

Merge branch 'sy-fix-flakey-server-spec' into 'master'

Increase HTTP request retries and handle presence check with assertion

See merge request https://gitlab.com/gitlab-org/gitlab/-/merge_requests/169471



Merged-by: default avatarMax Woolf <mwoolf@gitlab.com>
Approved-by: default avatarRyan Cobb <rcobb@gitlab.com>
Approved-by: default avatarMax Woolf <mwoolf@gitlab.com>
Co-authored-by: default avatarSarah Yasonik <syasonik@gitlab.com>
parents 3c528e0a 61d916ab
No related branches found
No related tags found
No related merge requests found
Pipeline #25009751 running
Loading
@@ -4,6 +4,8 @@
Loading
@@ -4,6 +4,8 @@
require_relative '../../../scripts/internal_events/server' require_relative '../../../scripts/internal_events/server'
   
RSpec.describe Server, feature_category: :service_ping do RSpec.describe Server, feature_category: :service_ping do
include WaitHelpers
let(:server) { described_class.new } let(:server) { described_class.new }
let(:port) { Gitlab::Tracking::Destinations::SnowplowMicro.new.uri.port } let(:port) { Gitlab::Tracking::Destinations::SnowplowMicro.new.uri.port }
let(:events) { server.events } let(:events) { server.events }
Loading
@@ -24,7 +26,7 @@
Loading
@@ -24,7 +26,7 @@
# rubocop:enable RSpec/ExpectOutput # rubocop:enable RSpec/ExpectOutput
   
describe 'GET /i -> trigger a single event provided through query params (backend)' do describe 'GET /i -> trigger a single event provided through query params (backend)' do
subject(:response) { with_retry { Net::HTTP.get_response url_for("/i?#{query_params}") } } subject(:response) { await { Net::HTTP.get_response url_for("/i?#{query_params}") } }
   
context 'with an internal event' do context 'with an internal event' do
let(:query_params) { internal_event_fixture('snowplow_events/internal_event_query_params') } let(:query_params) { internal_event_fixture('snowplow_events/internal_event_query_params') }
Loading
@@ -77,7 +79,7 @@
Loading
@@ -77,7 +79,7 @@
end end
   
describe 'POST /com.snowplowanalytics.snowplow/tp2 -> trigger events provided through request body (frontend)' do describe 'POST /com.snowplowanalytics.snowplow/tp2 -> trigger events provided through request body (frontend)' do
subject(:response) { with_retry { Net::HTTP.post url_for('/com.snowplowanalytics.snowplow/tp2'), body } } subject(:response) { await { Net::HTTP.post url_for('/com.snowplowanalytics.snowplow/tp2'), body } }
   
context 'when triggered on-click' do context 'when triggered on-click' do
let(:body) { internal_event_fixture('snowplow_events/internal_event_on_click.json') } let(:body) { internal_event_fixture('snowplow_events/internal_event_on_click.json') }
Loading
@@ -178,7 +180,7 @@
Loading
@@ -178,7 +180,7 @@
   
describe 'OPTIONS /com.snowplowanalytics.snowplow/tp2' do describe 'OPTIONS /com.snowplowanalytics.snowplow/tp2' do
subject(:response) do subject(:response) do
with_retry { Net::HTTP.new('localhost', port).options('/com.snowplowanalytics.snowplow/tp2') } await { Net::HTTP.new('localhost', port).options('/com.snowplowanalytics.snowplow/tp2') }
end end
   
it 'applies the correct headers' do it 'applies the correct headers' do
Loading
@@ -190,7 +192,7 @@
Loading
@@ -190,7 +192,7 @@
end end
   
describe 'GET /micro/good -> list tracked structured events' do describe 'GET /micro/good -> list tracked structured events' do
subject(:response) { with_retry { Net::HTTP.get_response url_for("/micro/good") } } subject(:response) { await { Net::HTTP.get_response url_for("/micro/good") } }
   
it 'successfully returns tracked events' do it 'successfully returns tracked events' do
expect(response.code).to eq('200') expect(response.code).to eq('200')
Loading
@@ -201,7 +203,7 @@
Loading
@@ -201,7 +203,7 @@
let(:query_params) { internal_event_fixture('snowplow_events/non_internal_event_without_context') } let(:query_params) { internal_event_fixture('snowplow_events/non_internal_event_without_context') }
   
before do before do
with_retry { Net::HTTP.get url_for("/i?#{query_params}") } await { Net::HTTP.get url_for("/i?#{query_params}") }
end end
   
it 'successfully returns tracked events' do it 'successfully returns tracked events' do
Loading
@@ -224,14 +226,12 @@
Loading
@@ -224,14 +226,12 @@
   
private private
   
def with_retry(retried: false) def await
yield wait_for('server response to be available', max_wait_time: 2.seconds) do
rescue Errno::ECONNREFUSED, Errno::EADDRNOTAVAIL yield
return if retried rescue Errno::ECONNREFUSED, Errno::EADDRNOTAVAIL
nil
retried = true end
retry
end end
   
def url_for(path) def url_for(path)
Loading
Loading
Loading
@@ -8,7 +8,7 @@ def wait_for(condition_name, max_wait_time: Capybara.default_max_wait_time, poll
Loading
@@ -8,7 +8,7 @@ def wait_for(condition_name, max_wait_time: Capybara.default_max_wait_time, poll
wait_until = Time.now + max_wait_time.seconds wait_until = Time.now + max_wait_time.seconds
loop do loop do
result = yield result = yield
break if result break result if result
   
page.refresh if reload page.refresh if reload
   
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