Commit 09dad69c authored by Tiago Botelho's avatar Tiago Botelho

Removes potential race condition specs from Groups::DestroyService

parent 402c3d13
...@@ -82,62 +82,6 @@ describe Groups::DestroyService do ...@@ -82,62 +82,6 @@ describe Groups::DestroyService do
expect(Group.unscoped.count).to eq(2) expect(Group.unscoped.count).to eq(2)
end end
end end
context 'potential race conditions' do
context "when the `GroupDestroyWorker` task runs immediately" do
around do |example|
connections = [ActiveRecord::Base, Geo::BaseRegistry]
old_connections = connections.each_with_object({}) do |connection, memo|
memo[connection] = DatabaseCleaner[:active_record, { connection: connection }].strategy
DatabaseCleaner[:active_record, { connection: connection }].strategy = :deletion
memo
end
begin
example.run
ensure
old_connections.each do |connection, old_strategy|
DatabaseCleaner[:active_record, { connection: connection }].strategy = old_strategy
end
end
end
it "deletes the group" do
# Commit the contents of this spec's transaction so far
# so subsequent db connections can see it.
#
# DO NOT REMOVE THIS LINE, even if you see a WARNING with "No
# transaction is currently in progress". Without this, this
# spec will always be green, since the group created in setup
# cannot be seen by any other connections / threads in this spec.
Group.connection.commit_db_transaction
group_record = run_with_new_database_connection do |conn|
conn.execute("SELECT * FROM namespaces WHERE id = #{group.id}").first
end
expect(group_record).not_to be_nil
# Execute the contents of `GroupDestroyWorker` in a separate thread, to
# simulate data manipulation by the Sidekiq worker (different database
# connection / transaction).
expect(GroupDestroyWorker).to receive(:perform_async).and_wrap_original do |m, group_id, user_id|
Thread.new { m[group_id, user_id] }.join(5)
end
# Kick off the initial group destroy in a new thread, so that
# it doesn't share this spec's database transaction.
Thread.new { described_class.new(group, user).async_execute }.join(5)
group_record = run_with_new_database_connection do |conn|
conn.execute("SELECT * FROM namespaces WHERE id = #{group.id}").first
end
expect(group_record).to be_nil
end
end
end
end end
describe 'synchronous delete' do describe 'synchronous delete' do
......
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