Created
February 19, 2020 20:51
-
-
Save SamSaffron/6f9ffec0162c475152a5176ab9401ee9 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'active_record' | |
config = <<~CONF | |
development: | |
adapter: sqlite3 | |
database: ":memory:" | |
host_names: | |
- test.localhost | |
CONF | |
ActiveRecord::Base.configurations = ActiveRecord::DatabaseConfigurations.new(YAML::load(config)) | |
ActiveRecord::Base.establish_connection(:development) | |
(0..4).map do |thread_number| | |
Thread.new do | |
# Obtain a reference to the schema cache, and log which connection it's using | |
my_schema_cache = ActiveRecord::Base.connection.schema_cache | |
initial_conn_id = my_schema_cache.connection.object_id | |
# Do something else | |
sleep 1 | |
# Now check the schema cache connection again | |
final_conn_id = my_schema_cache.connection.object_id | |
if initial_conn_id != final_conn_id | |
puts "Thread #{thread_number} switched connection from #{initial_conn_id} to #{final_conn_id}" | |
end | |
end | |
end.each(&:join) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment