From be748b29b713b31d393882e0585ce267a3682e2b Mon Sep 17 00:00:00 2001 From: Marc Shaw Date: Thu, 20 Nov 2025 14:59:02 +0700 Subject: [PATCH] Fix flaky test: Signup on EE for SaaS The test was failing with a PG::QueryCanceled error during organization creation due to lock contention on the unique index 'unique_organizations_on_path_case_insensitive'. Root Cause: The :common_organization factory used find_or_create_by!(path: 'common-org') which created a shared database record across all tests using the :with_current_organization metadata. When multiple tests executed in parallel or rapid succession, they competed for the same unique index entry, causing lock timeouts. Solution: Replace the find_or_create_by! logic with a standard factory using sequence(:path) to generate unique organization paths for each test. This eliminates lock contention by ensuring each test gets its own isolated organization. Pattern: shared_state (4% of flaky tests) Confidence: 95% Changelog: fixed Related to https://gitlab.com/gitlab-org/quality/test-failure-issues/-/issues/7295 --- spec/factories/organizations/organizations.rb | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/spec/factories/organizations/organizations.rb b/spec/factories/organizations/organizations.rb index a4e7e9635f9fac..266fe68d8e00a4 100644 --- a/spec/factories/organizations/organizations.rb +++ b/spec/factories/organizations/organizations.rb @@ -37,14 +37,9 @@ FactoryBot.define do factory :common_organization, class: 'Organizations::Organization' do - skip_create - - initialize_with do - Organizations::Organization.find_or_create_by!(path: 'common-org') do |org| - org.name = 'Common Organization' - # This should be PRIVATE: https://gitlab.com/gitlab-org/gitlab/-/issues/556368 - org.visibility_level = Organizations::Organization::PUBLIC - end - end + sequence(:path) { |n| "common-org-#{n}" } + name { 'Common Organization' } + # This should be PRIVATE: https://gitlab.com/gitlab-org/gitlab/-/issues/556368 + visibility_level { Organizations::Organization::PUBLIC } end end -- GitLab