Commit d81d3cbb authored by Dylan Griffith's avatar Dylan Griffith

Merge branch 'example_file_path_rerun_argument' into 'master'

Make cross-db modification check use running spec

See merge request gitlab-org/gitlab!72735
parents a3572253 41d9b820
......@@ -5,8 +5,16 @@
- "./ee/spec/features/groups/analytics/cycle_analytics/filters_and_data_spec.rb"
- "./ee/spec/features/projects/services/user_activates_github_spec.rb"
- "./ee/spec/frontend/fixtures/analytics/value_streams.rb"
- "./ee/spec/graphql/mutations/dast_on_demand_scans/create_spec.rb"
- "./ee/spec/frontend/fixtures/analytics/value_streams_code_stage.rb"
- "./ee/spec/frontend/fixtures/analytics/value_streams_issue_stage.rb"
- "./ee/spec/frontend/fixtures/analytics/value_streams_plan_stage.rb"
- "./ee/spec/frontend/fixtures/analytics/value_streams_review_stage.rb"
- "./ee/spec/frontend/fixtures/analytics/value_streams_staging_stage.rb"
- "./ee/spec/frontend/fixtures/analytics/value_streams_test_stage.rb"
- "./ee/spec/graphql/mutations/dast/profiles/create_spec.rb"
- "./ee/spec/graphql/mutations/dast/profiles/run_spec.rb"
- "./ee/spec/graphql/mutations/dast/profiles/update_spec.rb"
- "./ee/spec/graphql/mutations/dast_on_demand_scans/create_spec.rb"
- "./ee/spec/graphql/mutations/merge_requests/accept_spec.rb"
- "./ee/spec/lib/analytics/devops_adoption/snapshot_calculator_spec.rb"
- "./ee/spec/lib/gitlab/ci/templates/Jobs/dast_default_branch_gitlab_ci_yaml_spec.rb"
......@@ -25,10 +33,12 @@
- "./ee/spec/models/group_member_spec.rb"
- "./ee/spec/models/merge_request_spec.rb"
- "./ee/spec/models/project_spec.rb"
- "./ee/spec/requests/api/graphql/mutations/dast_on_demand_scans/create_spec.rb"
- "./ee/spec/replicators/geo/pipeline_artifact_replicator_spec.rb"
- "./ee/spec/replicators/geo/terraform_state_version_replicator_spec.rb"
- "./ee/spec/requests/api/graphql/mutations/dast/profiles/create_spec.rb"
- "./ee/spec/requests/api/graphql/mutations/dast/profiles/run_spec.rb"
- "./ee/spec/requests/api/graphql/mutations/dast/profiles/update_spec.rb"
- "./ee/spec/requests/api/graphql/mutations/dast_on_demand_scans/create_spec.rb"
- "./ee/spec/requests/api/graphql/project/pipeline/dast_profile_spec.rb"
- "./ee/spec/requests/api/graphql/project/pipelines/dast_profile_spec.rb"
- "./ee/spec/services/app_sec/dast/profiles/create_service_spec.rb"
......@@ -41,6 +51,7 @@
- "./ee/spec/services/ci/destroy_pipeline_service_spec.rb"
- "./ee/spec/services/ci/minutes/track_live_consumption_service_spec.rb"
- "./ee/spec/services/ci/minutes/update_build_minutes_service_spec.rb"
- "./ee/spec/services/ci/retry_build_service_spec.rb"
- "./ee/spec/services/ci/subscribe_bridge_service_spec.rb"
- "./ee/spec/services/ci/sync_reports_to_approval_rules_service_spec.rb"
- "./ee/spec/services/ci/trigger_downstream_subscription_service_spec.rb"
......@@ -51,15 +62,6 @@
- "./ee/spec/services/projects/transfer_service_spec.rb"
- "./ee/spec/services/security/security_orchestration_policies/rule_schedule_service_spec.rb"
- "./ee/spec/services/vulnerability_feedback/create_service_spec.rb"
- "./ee/spec/support/shared_examples/fixtures/analytics_value_streams_shared_examples.rb"
- "./ee/spec/support/shared_examples/graphql/mutations/dast_on_demand_scans_shared_examples.rb"
- "./ee/spec/support/shared_examples/graphql/mutations/dast_on_demand_scan_with_user_abilities_shared_examples.rb"
- "./ee/spec/support/shared_examples/models/concerns/blob_replicator_strategy_shared_examples.rb"
- "./ee/spec/support/shared_examples/models/concerns/replicable_model_shared_examples.rb"
- "./ee/spec/support/shared_examples/models/concerns/verifiable_replicator_shared_examples.rb"
- "./ee/spec/support/shared_examples/services/audit_event_logging_shared_examples.rb"
- "./ee/spec/support/shared_examples/services/build_execute_shared_examples.rb"
- "./ee/spec/support/shared_examples/services/dast_on_demand_scans_shared_examples.rb"
- "./ee/spec/workers/refresh_license_compliance_checks_worker_spec.rb"
- "./spec/controllers/abuse_reports_controller_spec.rb"
- "./spec/controllers/admin/spam_logs_controller_spec.rb"
......@@ -69,8 +71,8 @@
- "./spec/controllers/projects/jobs_controller_spec.rb"
- "./spec/controllers/projects/merge_requests/content_controller_spec.rb"
- "./spec/controllers/projects/merge_requests_controller_spec.rb"
- "./spec/controllers/projects/pipelines_controller_spec.rb"
- "./spec/controllers/projects/pipelines/tests_controller_spec.rb"
- "./spec/controllers/projects/pipelines_controller_spec.rb"
- "./spec/controllers/projects/settings/access_tokens_controller_spec.rb"
- "./spec/factories_spec.rb"
- "./spec/features/cycle_analytics_spec.rb"
......@@ -97,11 +99,15 @@
- "./spec/lib/gitlab/ci/pipeline/chain/seed_block_spec.rb"
- "./spec/lib/gitlab/ci/pipeline/seed/build_spec.rb"
- "./spec/lib/gitlab/ci/templates/5_minute_production_app_ci_yaml_spec.rb"
- "./spec/lib/gitlab/ci/templates/auto_devops_gitlab_ci_yaml_spec.rb"
- "./spec/lib/gitlab/ci/templates/AWS/deploy_ecs_gitlab_ci_yaml_spec.rb"
- "./spec/lib/gitlab/ci/templates/Jobs/deploy_gitlab_ci_yaml_spec.rb"
- "./spec/lib/gitlab/ci/templates/auto_devops_gitlab_ci_yaml_spec.rb"
- "./spec/lib/gitlab/ci/templates/managed_cluster_applications_gitlab_ci_yaml_spec.rb"
- "./spec/lib/gitlab/data_builder/pipeline_spec.rb"
- "./spec/lib/gitlab/email/handler/create_issue_handler_spec.rb"
- "./spec/lib/gitlab/email/handler/create_merge_request_handler_spec.rb"
- "./spec/lib/gitlab/email/handler/create_note_handler_spec.rb"
- "./spec/lib/gitlab/email/handler/create_note_on_issuable_handler_spec.rb"
- "./spec/lib/gitlab/usage_data_spec.rb"
- "./spec/lib/peek/views/active_record_spec.rb"
- "./spec/mailers/emails/pipelines_spec.rb"
......@@ -116,6 +122,8 @@
- "./spec/models/ci/legacy_stage_spec.rb"
- "./spec/models/ci/pipeline_schedule_spec.rb"
- "./spec/models/ci/pipeline_spec.rb"
- "./spec/models/ci/runner_namespace_spec.rb"
- "./spec/models/ci/runner_project_spec.rb"
- "./spec/models/ci/runner_spec.rb"
- "./spec/models/ci/running_build_spec.rb"
- "./spec/models/ci/variable_spec.rb"
......@@ -140,8 +148,8 @@
- "./spec/requests/api/ci/pipelines_spec.rb"
- "./spec/requests/api/ci/runner/runners_post_spec.rb"
- "./spec/requests/api/ci/runners_spec.rb"
- "./spec/requests/api/commits_spec.rb"
- "./spec/requests/api/commit_statuses_spec.rb"
- "./spec/requests/api/commits_spec.rb"
- "./spec/requests/api/graphql/ci/runner_spec.rb"
- "./spec/requests/api/graphql/mutations/ci/pipeline_destroy_spec.rb"
- "./spec/requests/api/merge_requests_spec.rb"
......@@ -174,8 +182,8 @@
- "./spec/services/ci/pipeline_artifacts/coverage_report_service_spec.rb"
- "./spec/services/ci/pipeline_artifacts/create_code_quality_mr_diff_report_service_spec.rb"
- "./spec/services/ci/pipeline_bridge_status_service_spec.rb"
- "./spec/services/ci/pipelines/add_job_service_spec.rb"
- "./spec/services/ci/pipeline_schedule_service_spec.rb"
- "./spec/services/ci/pipelines/add_job_service_spec.rb"
- "./spec/services/ci/retry_build_service_spec.rb"
- "./spec/services/ci/update_instance_variables_service_spec.rb"
- "./spec/services/deployments/update_environment_service_spec.rb"
......@@ -189,18 +197,6 @@
- "./spec/services/resource_access_tokens/revoke_service_spec.rb"
- "./spec/services/users/destroy_service_spec.rb"
- "./spec/services/users/reject_service_spec.rb"
- "./spec/support/shared_contexts/email_shared_context.rb"
- "./spec/support/shared_examples/controllers/access_tokens_controller_shared_examples.rb"
- "./spec/support/shared_examples/models/atomic_internal_id_shared_examples.rb"
- "./spec/support/shared_examples/models/cluster_application_status_shared_examples.rb"
- "./spec/support/shared_examples/models/cluster_application_version_shared_examples.rb"
- "./spec/support/shared_examples/models/concerns/cron_schedulable_shared_examples.rb"
- "./spec/support/shared_examples/models/concerns/limitable_shared_examples.rb"
- "./spec/support/shared_examples/models/update_highest_role_shared_examples.rb"
- "./spec/support/shared_examples/models/update_project_statistics_shared_examples.rb"
- "./spec/support/shared_examples/models/with_uploads_shared_examples.rb"
- "./spec/support/shared_examples/requests/api/status_shared_examples.rb"
- "./spec/support/shared_examples/workers/idempotency_shared_examples.rb"
- "./spec/views/projects/artifacts/_artifact.html.haml_spec.rb"
- "./spec/views/projects/pipeline_schedules/_pipeline_schedule.html.haml_spec.rb"
- "./spec/views/shared/runners/_runner_details.html.haml_spec.rb"
......
......@@ -122,7 +122,7 @@ RSpec.configure do |config|
# Using before and after blocks because the around block causes problems with the let_it_be
# record creations. It makes an extra savepoint which breaks the transaction count logic.
config.before do |example_file|
if CROSS_DB_MODIFICATION_ALLOW_LIST.exclude?(example_file.file_path)
if CROSS_DB_MODIFICATION_ALLOW_LIST.exclude?(example_file.file_path_rerun_argument)
with_cross_database_modification_prevented
end
end
......
......@@ -90,23 +90,13 @@ ActiveRecord::Relation.prepend(
ALLOW_LIST = Set.new(YAML.load_file(File.join(__dir__, 'cross-join-allowlist.yml'))).freeze
# Based on https://github.com/rspec/rspec-core/blob/d57c371ee92b16211b80ac7b0b025968438f5297/lib/rspec/core/example.rb#L96-L104,
# but with file_path
def example_relative_file_path(example)
loaded_spec_files = RSpec.configuration.loaded_spec_files
RSpec::Core::Metadata.ascending(example.metadata) do |meta|
break meta[:file_path] if loaded_spec_files.include?(meta[:absolute_file_path])
end
end
RSpec.configure do |config|
config.include(::Database::PreventCrossJoins::SpecHelpers)
config.around do |example|
Thread.current[:has_cross_join_exception] = false
if ALLOW_LIST.include?(example_relative_file_path(example))
if ALLOW_LIST.include?(example.file_path_rerun_argument)
example.run
else
with_cross_joins_prevented { example.run }
......
# frozen_string_literal: true
module RSpec
module Core
module ExamplePrependedMethods
# Based on https://github.com/rspec/rspec-core/blob/d57c371ee92b16211b80ac7b0b025968438f5297/lib/rspec/core/example.rb#L96-L104,
# Same as location_rerun_argument but with line number
def file_path_rerun_argument
loaded_spec_files = RSpec.configuration.loaded_spec_files
RSpec::Core::Metadata.ascending(metadata) do |meta|
break meta[:file_path] if loaded_spec_files.include?(meta[:absolute_file_path])
end
end
end
module ExampleProcsyPrependedMethods
def file_path_rerun_argument
example.file_path_rerun_argument
end
end
end
end
RSpec::Core::Example.prepend(RSpec::Core::ExamplePrependedMethods)
RSpec::Core::Example::Procsy.prepend(RSpec::Core::ExampleProcsyPrependedMethods)
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