Commit c4e9e784 authored by Stan Hu's avatar Stan Hu

Fix flaky spec in QuickActions::InterpretService#execute

The spec was attempting to test whether `/assign @userA @userB` would
only assign an issue or merge request to `userA`. However, this would
fail occasionally because the reference extractor does not guarantee
ordering with extracted Markdown references since a database lookup is
performed (e.g. `User.where`) without an ORDER BY.

We adapt the test to check that only one of the two possible users is
assigned since the behavior is ambiguous when multiple assignees is not
supported, and it would take some work with some performance
implications to ensure the first mentioned user were assigned.

Closes https://gitlab.com/gitlab-org/gitlab/-/issues/27989
parent d6805f4f
......@@ -789,12 +789,32 @@ RSpec.describe QuickActions::InterpretService do
project.add_developer(developer2)
end
it_behaves_like 'assign command' do
# There's no guarantee that the reference extractor will preserve
# the order of the mentioned users since this is dependent on the
# order in which rows are returned. We just ensure that at least
# one of the mentioned users is assigned.
shared_examples 'assigns to one of the two users' do
let(:content) { "/assign @#{developer.username} @#{developer2.username}" }
it 'assigns to a single user' do
_, updates, message = service.execute(content, issuable)
expect(updates[:assignee_ids].count).to eq(1)
assignee = updates[:assignee_ids].first
expect([developer.id, developer2.id]).to include(assignee)
user = assignee == developer.id ? developer : developer2
expect(message).to match("Assigned #{user.to_reference}.")
end
end
it_behaves_like 'assigns to one of the two users' do
let(:content) { "/assign @#{developer.username} @#{developer2.username}" }
let(:issuable) { issue }
end
it_behaves_like 'assign command', quarantine: 'https://gitlab.com/gitlab-org/gitlab/-/issues/27989' do
it_behaves_like 'assigns to one of the two users' do
let(:content) { "/assign @#{developer.username} @#{developer2.username}" }
let(:issuable) { merge_request }
end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment