Commit 3ead8054 authored by Sanad Liaquat's avatar Sanad Liaquat

Merge branch 'ml-add-postreceive-e2e-test' into 'master'

Add an E2E test of PostReceive idempotency

See merge request gitlab-org/gitlab!57927
parents 9cc7d75d 79d1d3c2
......@@ -24,6 +24,18 @@ module QA
"#{api_get_path}/events"
end
def fetch_events
events_returned = nil
Support::Waiter.wait_until(max_duration: max_wait, raise_on_failure: raise_on_failure) do
events_returned = yield
events_returned.any?
end
raise EventNotFoundError, "Timed out waiting for events" unless events_returned
events_returned
end
def wait_for_event
event_found = Support::Waiter.wait_until(max_duration: max_wait, raise_on_failure: raise_on_failure) do
yield
......
......@@ -6,6 +6,13 @@ module QA
module Project
include Events::Base
def push_events(commit_message)
QA::Runtime::Logger.debug(%Q[#{self.class.name} - wait for and fetch push events"])
fetch_events do
events(action: 'pushed').select { |event| event.dig(:push_data, :commit_title) == commit_message }
end
end
def wait_for_merge(title)
QA::Runtime::Logger.debug(%Q[#{self.class.name} - wait_for_merge with title "#{title}"])
wait_for_event do
......
# frozen_string_literal: true
module QA
RSpec.describe 'Create' do
describe 'PostReceive idempotent' do
# Tests that a push does not result in multiple changes from repeated PostReceive executions.
# One of the consequences would be duplicate push events
let(:project) do
Resource::Project.fabricate_via_api! do |project|
project.name = 'push-postreceive-idempotent'
project.initialize_with_readme = true
end
end
after do
project&.remove_via_api!
end
it 'pushes and creates a single push event three times', testcase: 'https://gitlab.com/gitlab-org/quality/testcases/-/issues/1744' do
verify_single_event_per_push(repeat: 3)
end
it 'repeatedly pushes and creates a single push event several times', :transient, testcase: 'https://gitlab.com/gitlab-org/quality/testcases/-/issues/1744' do
verify_single_event_per_push(repeat: Runtime::Env.transient_trials) do |i|
QA::Runtime::Logger.info("Transient bug test action - Trial #{i}")
end
end
def verify_single_event_per_push(repeat:)
repeat.times do |i|
yield i if block_given?
commit_message = "test post-receive idempotency #{SecureRandom.hex(8)}"
Resource::Repository::ProjectPush.fabricate! do |push|
push.project = project
push.new_branch = false
push.commit_message = commit_message
end
events = project.push_events(commit_message)
aggregate_failures do
expect(events.size).to eq(1), "An unexpected number of push events was created"
expect(events.first.dig(:push_data, :commit_title)).to eq(commit_message)
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