diff --git a/spec/support/issuable_slash_commands_shared_examples.rb b/spec/support/issuable_slash_commands_shared_examples.rb
index a51742089d010e8e61215d4b2f182fc536ea5707..a3fbba55e278fe39c74298c9eef0031268464e3e 100644
--- a/spec/support/issuable_slash_commands_shared_examples.rb
+++ b/spec/support/issuable_slash_commands_shared_examples.rb
@@ -2,6 +2,8 @@
 # It takes a `issuable_type`, and expect an `issuable`.
 
 shared_examples 'issuable record that supports slash commands in its description and notes' do |issuable_type|
+  include WaitForAjax
+
   let(:master) { create(:user) }
   let(:assignee) { create(:user, username: 'bob') }
   let(:guest) { create(:user) }
@@ -18,6 +20,11 @@ shared_examples 'issuable record that supports slash commands in its description
     login_with(master)
   end
 
+  after do
+    # Ensure all outstanding Ajax requests are complete to avoid database deadlocks
+    wait_for_ajax
+  end
+
   def write_note(text)
     Sidekiq::Testing.fake! do
       page.within('.js-main-target-form') do