Follow up: Fixed race condtion while importing history types for the first time.
This commit is contained in:
parent
e72d6c3fd4
commit
e0b70cb24f
2 changed files with 15 additions and 3 deletions
|
@ -25,11 +25,22 @@ module Import
|
||||||
def ensure_history_attribute
|
def ensure_history_attribute
|
||||||
history_attribute = @history_attributes[:history_attribute]
|
history_attribute = @history_attributes[:history_attribute]
|
||||||
return if !history_attribute
|
return if !history_attribute
|
||||||
@@created_history_attributes ||= {}
|
return if history_attribute_exists?(history_attribute)
|
||||||
return if @@created_history_attributes[history_attribute]
|
|
||||||
@@created_history_attributes[history_attribute] = true
|
@@created_history_attributes[history_attribute] = true
|
||||||
::History.attribute_lookup(history_attribute)
|
::History.attribute_lookup(history_attribute)
|
||||||
end
|
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
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -12,7 +12,8 @@ end
|
||||||
|
|
||||||
RSpec.shared_examples 'Import::OTRS::History' do
|
RSpec.shared_examples 'Import::OTRS::History' do
|
||||||
it 'responds to init_callback' 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({})
|
blank_instance = described_class.new({})
|
||||||
expect(blank_instance).to respond_to('init_callback')
|
expect(blank_instance).to respond_to('init_callback')
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue