From f95fa7145b41dbeb0cbaea1e9677fb7dd65a2f04 Mon Sep 17 00:00:00 2001 From: Timothy Andrew Date: Thu, 17 Nov 2016 19:23:42 +0530 Subject: Write a spec covering the race condition during group deletion. - Use multiple threads / database connections to: 1. Escape the transaction the spec seems to be running in (`config.use_transactional_fixtures` is off, but `ActiveRecord::Base.connection.open_transactions` is not empty at the beginning of the spec. 2. Simulate a Sidekiq worker performing the hard delete outside of the soft-delete transaction. - The spec is a little clunky, but it was the smallest thing I could get working - and even this took a couple of hours. Let me know if you have any suggestions to improve it! --- spec/support/database_connection_helpers.rb | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 spec/support/database_connection_helpers.rb (limited to 'spec/support/database_connection_helpers.rb') diff --git a/spec/support/database_connection_helpers.rb b/spec/support/database_connection_helpers.rb new file mode 100644 index 00000000000..763329499f0 --- /dev/null +++ b/spec/support/database_connection_helpers.rb @@ -0,0 +1,9 @@ +module DatabaseConnectionHelpers + def run_with_new_database_connection + pool = ActiveRecord::Base.connection_pool + conn = pool.checkout + yield conn + ensure + pool.checkin(conn) + end +end -- cgit v1.2.1