fix: resolve mutex conflicts in Instagram webhook specs (#12154)
This PR fixes flaky test failures in the Instagram webhook specs that were caused by Redis mutex lock conflicts when tests ran in parallel. ### The Problem: The InstagramEventsJob uses a Redis mutex with a key based on sender_id and ig_account_id to prevent race conditions. However, all test factories were using the same hardcoded sender_id: 'Sender-id-1', causing multiple test instances to compete for the same mutex lock when running in parallel. ### The Solution: - Updated all Instagram event factories to generate unique sender IDs using SecureRandom.hex(4) - Modified test stubs and expectations to work with dynamic sender IDs instead of hardcoded values - Ensured each test instance gets its own unique mutex key, eliminating lock contention
This commit is contained in:
20
spec/support/instagram_spec_helpers.rb
Normal file
20
spec/support/instagram_spec_helpers.rb
Normal file
@@ -0,0 +1,20 @@
|
||||
module InstagramSpecHelpers
|
||||
def create_instagram_contact_for_sender(sender_id, inbox)
|
||||
contact = Contact.find_by(identifier: sender_id)
|
||||
if contact.nil?
|
||||
contact = create(:contact, identifier: sender_id, name: 'Jane Dae')
|
||||
create(:contact_inbox, contact_id: contact.id, inbox_id: inbox.id, source_id: sender_id)
|
||||
end
|
||||
contact
|
||||
end
|
||||
|
||||
def instagram_user_response_object_for(sender_id, account_id)
|
||||
{
|
||||
name: 'Jane',
|
||||
id: sender_id,
|
||||
account_id: account_id,
|
||||
profile_pic: 'https://chatwoot-assets.local/sample.png',
|
||||
username: 'some_user_name'
|
||||
}
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user