Follow up: Fixed race condtion while importing history types for the first time.

This commit is contained in:
Thorsten Eckel 2016-11-29 12:56:24 +01:00
parent e72d6c3fd4
commit e0b70cb24f
2 changed files with 15 additions and 3 deletions

View file

@ -25,11 +25,22 @@ module Import
def ensure_history_attribute
history_attribute = @history_attributes[:history_attribute]
return if !history_attribute
@@created_history_attributes ||= {}
return if @@created_history_attributes[history_attribute]
return if history_attribute_exists?(history_attribute)
@@created_history_attributes[history_attribute] = true
::History.attribute_lookup(history_attribute)
end
def history_attribute_exists?(name)
@@created_history_attributes ||= {}
return false if !@@created_history_attributes[name]
# make sure the history attribute is added before we
# we perform further import
# otherwise the following import logic (add) will
# try to add the history attribute, too
sleep 1 until ::History::Attribute.find_by(name: name)
true
end
end
end
end

View file

@ -12,7 +12,8 @@ end
RSpec.shared_examples 'Import::OTRS::History' do
it 'responds to init_callback' do
expect(History).to receive(:add)
expect(::History).to receive(:add)
allow(::History::Attribute).to receive(:find_by).and_return(true)
blank_instance = described_class.new({})
expect(blank_instance).to respond_to('init_callback')
end