diff --git a/test/test_helper.rb b/test/test_helper.rb index 14b0d01..f241feb 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -24,10 +24,8 @@ ENV['WITH_ADVISORY_LOCK_PREFIX'] ||= SecureRandom.hex -ActiveRecord::Base.establish_connection - def env_db - @env_db ||= ActiveRecord::Base.connection_db_config.adapter.to_sym + @env_db ||= ActiveRecord::Base.configurations.find_db_config(:default_env).adapter end ActiveRecord::Migration.verbose = false diff --git a/test/test_models.rb b/test/test_models.rb index 8d6fda1..c3cc8fa 100644 --- a/test/test_models.rb +++ b/test/test_models.rb @@ -1,5 +1,7 @@ # frozen_string_literal: true +ActiveRecord::Base.establish_connection(:default_env) + ActiveRecord::Schema.define(version: 1) do create_table 'tags', force: true do |t| t.string 'name' diff --git a/test/with_advisory_lock/parallelism_test.rb b/test/with_advisory_lock/parallelism_test.rb index 56f6a20..aa9cd26 100644 --- a/test/with_advisory_lock/parallelism_test.rb +++ b/test/with_advisory_lock/parallelism_test.rb @@ -15,7 +15,7 @@ def initialize(name, use_advisory_lock) def work_later sleep - ApplicationRecord.connection_pool.with_connection do + Tag.connection_pool.with_connection do if @use_advisory_lock Tag.with_advisory_lock(@name) { work } else @@ -46,16 +46,16 @@ def run_workers workers.each(&:join) end # Ensure we're still connected: - ApplicationRecord.connection_pool.connection + Tag.connection_pool.connection end setup do - ApplicationRecord.connection.reconnect! + Tag.connection.reconnect! @workers = 10 end test 'creates multiple duplicate rows without advisory locks' do - skip if %i[sqlite3 jdbcsqlite3].include?(env_db) + skip if is_sqlite3_adapter? @use_advisory_lock = false @iterations = 1 run_workers diff --git a/test/with_advisory_lock/shared_test.rb b/test/with_advisory_lock/shared_test.rb index 7cd23a4..7e22293 100644 --- a/test/with_advisory_lock/shared_test.rb +++ b/test/with_advisory_lock/shared_test.rb @@ -24,7 +24,7 @@ def cleanup! private def work - ApplicationRecord.connection_pool.with_connection do + Tag.connection_pool.with_connection do |connection| Tag.with_advisory_lock('test', timeout_seconds: 0, shared: @shared) do @locked = true sleep 0.01 until @cleanup @@ -36,9 +36,6 @@ def work end class SharedLocksTest < GemTestCase - def supported? - %i[trilogy mysql2 jdbcmysql].exclude?(env_db) - end test 'does not allow two exclusive locks' do one = SharedTestWorker.new(false) @@ -52,12 +49,14 @@ def supported? end end -class NotSupportedEnvironmentTest < SharedLocksTest - setup do - skip if supported? +class NotSupportedEnvironmentTest < GemTestCase + def supported? + !is_mysql_adapter? end test 'raises an error when attempting to use a shared lock' do + skip "Not supported" unless supported? + one = SharedTestWorker.new(true) assert_nil(one.locked?) @@ -69,7 +68,11 @@ class NotSupportedEnvironmentTest < SharedLocksTest end end -class SupportedEnvironmentTest < SharedLocksTest +class SupportedEnvironmentTest < GemTestCase + def supported? + !is_mysql_adapter? + end + setup do skip unless supported? end @@ -113,7 +116,7 @@ class SupportedEnvironmentTest < SharedLocksTest class PostgreSQLTest < SupportedEnvironmentTest setup do - skip unless env_db == :postgresql + skip unless is_postgresql_adapter? end def pg_lock_modes diff --git a/test/with_advisory_lock/transaction_test.rb b/test/with_advisory_lock/transaction_test.rb index 559f55c..0dbedc7 100644 --- a/test/with_advisory_lock/transaction_test.rb +++ b/test/with_advisory_lock/transaction_test.rb @@ -4,7 +4,7 @@ class TransactionScopingTest < GemTestCase def supported? - %i[postgresql jdbcpostgresql].include?(env_db) + is_postgresql_adapter? end test 'raises an error when attempting to use transaction level locks if not supported' do @@ -23,7 +23,7 @@ def supported? class PostgresqlTest < TransactionScopingTest setup do - skip unless env_db == :postgresql + skip unless is_postgresql_adapter? @pg_lock_count = lambda do ApplicationRecord.connection.select_value("SELECT COUNT(*) FROM pg_locks WHERE locktype = 'advisory';").to_i end