DEV: Allow test-prof to be disabled completely with `PREFABRICATION` env (#25294)

Why this change?

We have been looking into a flaky system tests in one of our plugins
where the DB transaction flow can be messed up from time to time. Our
debugging effort is complicated by that fact that `test-prof` starts a
DB transaction in a `before(:all)` block which makes it hard to properly
log information. By allowing test-prof to be disabled completely, we
believe it will make it easier for us to isolate the problem we are
investigating.

What does this change do?

1. Avoid loading test-prof files if `PREFABRICATION` env has been set to
   `0`.

2. Set `PREFABRICATION=0` for plugin system tests in Github actions
This commit is contained in:
Alan Guo Xiang Tan 2024-01-17 11:00:32 +08:00 committed by GitHub
parent ebd3971533
commit 54e6c1d823
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 17 additions and 15 deletions

View File

@ -241,7 +241,7 @@ jobs:
if: matrix.build_type == 'system' && matrix.target == 'plugins'
run: |
GLOBIGNORE="plugins/chat/*";
LOAD_PLUGINS=1 RAILS_ENABLE_TEST_LOG=1 RAILS_TEST_LOG_LEVEL=error PARALLEL_TEST_PROCESSORS=4 bin/turbo_rspec --use-runtime-info --profile=50 --verbose --format documentation plugins/*/spec/system
PREFABRICATION=0 LOAD_PLUGINS=1 RAILS_ENABLE_TEST_LOG=1 RAILS_TEST_LOG_LEVEL=error PARALLEL_TEST_PROCESSORS=4 bin/turbo_rspec --use-runtime-info --profile=50 --verbose --format documentation plugins/*/spec/system
shell: bash
timeout-minutes: 30

View File

@ -61,8 +61,6 @@ require File.expand_path("../../config/environment", __FILE__)
require "rspec/rails"
require "shoulda-matchers"
require "sidekiq/testing"
require "test_prof/recipes/rspec/let_it_be"
require "test_prof/before_all/adapters/active_record"
require "selenium-webdriver"
require "capybara/rails"
@ -156,20 +154,25 @@ module TestSetup
end
end
TestProf::BeforeAll.configure do |config|
config.after(:begin) do
DB.test_transaction = ActiveRecord::Base.connection.current_transaction
TestSetup.test_setup
end
end
module Prefabrication
if ENV["PREFABRICATION"] == "0"
if ENV["PREFABRICATION"] == "0"
module Prefabrication
def fab!(name, **opts, &blk)
blk ||= proc { Fabricate(name) }
let!(name, &blk)
end
else
end
else
require "test_prof/recipes/rspec/let_it_be"
require "test_prof/before_all/adapters/active_record"
TestProf::BeforeAll.configure do |config|
config.after(:begin) do
DB.test_transaction = ActiveRecord::Base.connection.current_transaction
TestSetup.test_setup
end
end
module Prefabrication
def fab!(name, **opts, &blk)
blk ||= proc { Fabricate(name) }
let_it_be(name, refind: true, **opts, &blk)
@ -177,8 +180,6 @@ module Prefabrication
end
end
RSpec.configure { |config| config.extend Prefabrication }
PER_SPEC_TIMEOUT_SECONDS = 45
BROWSER_READ_TIMEOUT = 30
@ -186,6 +187,7 @@ RSpec.configure do |config|
config.fail_fast = ENV["RSPEC_FAIL_FAST"] == "1"
config.silence_filter_announcements = ENV["RSPEC_SILENCE_FILTER_ANNOUNCEMENTS"] == "1"
config.extend RedisSnapshotHelper
config.extend Prefabrication
config.include Helpers
config.include MessageBus
config.include RSpecHtmlMatchers