Makes exceed_query_limit matcher less noisy
What does this MR do and why?
The matcher will currently report query groups, and their differences.
Many groups will differ only in parameters. For example the control
query will have Project.where(id: 1)
and the test will have
Project.where(id: [1, 2, 3])
. We want to mark this as a successful
group, and exclude it from the diff, making the diff more useful
when there are failures.
How to set up and validate locally
Set up a failing test. For example:
specify do
user_a, user_b = create_list(:user, 2)
control = ActiveRecord::QueryRecorder.new do
User.id_in(user_a.id).pluck(:username)
end
test = ActiveRecord::QueryRecorder.new do
User.id_in([user_a.id, user_b.id, 3]).pluck(:username)
user_a.update_columns(username: user_a.username.upcase)
end
expect(test).not_to exceed_query_limit(control)
end
You should see the following diff:
Expected a maximum of 1 queries, got 2:
Query Diff:
-----------
UPDATE "users"...
-- (expected: 0, got: 1)
SET "username" = 'USER1' WHERE "users"."id" = 5
On master you will see:
Expected a maximum of 1 queries, got 2:
Query Diff:
-----------
SELECT "users"."username" FROM "users"...
-- (expected: 1, got: 0)
WHERE "users"."id" = 7
-- (expected: 0, got: 1)
WHERE "users"."id" IN (7, 8, 3)
UPDATE "users"...
-- (expected: 0, got: 1)
SET "username" = 'USER1' WHERE "users"."id" = 7
which includes the noisy extra section that we want to ignore.
MR acceptance checklist
This checklist encourages us to confirm any changes have been analyzed to reduce risks in quality, performance, reliability, security, and maintainability.
-
I have evaluated the MR acceptance checklist for this MR.
Edited by Alex Kalderimis