Handle race condition when calling ActivityStream#assets (fixes #2066)
This commit is contained in:
parent
45ed1b3638
commit
a7749d663f
2 changed files with 30 additions and 1 deletions
|
@ -31,8 +31,13 @@ class Sessions::Backend::ActivityStream
|
|||
assets = {}
|
||||
item_ids = []
|
||||
activity_stream.each do |item|
|
||||
begin
|
||||
assets = item.assets(assets)
|
||||
rescue ActiveRecord::RecordNotFound
|
||||
next
|
||||
end
|
||||
|
||||
item_ids.push item.id
|
||||
assets = item.assets(assets)
|
||||
end
|
||||
|
||||
{
|
||||
|
|
24
spec/lib/sessions/backend/activity_stream_spec.rb
Normal file
24
spec/lib/sessions/backend/activity_stream_spec.rb
Normal file
|
@ -0,0 +1,24 @@
|
|||
require 'rails_helper'
|
||||
|
||||
RSpec.describe Sessions::Backend::ActivityStream do
|
||||
context 'when async processes affect associated objects / DB records (#2066)' do
|
||||
let(:subject) { described_class.new(user, {}) }
|
||||
let(:user) { create(:agent_user, groups: [group]) }
|
||||
let(:group) { Group.find_by(name: 'Users') }
|
||||
let(:associated_tickets) { create_list(:ticket, ticket_count, group: group) }
|
||||
let(:ticket_count) { 20 }
|
||||
|
||||
before do
|
||||
Setting.set('system_init_done', true)
|
||||
|
||||
# these records must be created before the example begins
|
||||
# (same as `let!`, but harder to miss)
|
||||
associated_tickets
|
||||
end
|
||||
|
||||
it 'manages race condition' do
|
||||
Thread.new { associated_tickets.each(&:destroy) }
|
||||
expect { subject.load }.not_to raise_error
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Reference in a new issue