summaryrefslogtreecommitdiff
path: root/spec/support
diff options
context:
space:
mode:
authorSean McGivern <sean@gitlab.com>2017-11-22 11:12:47 +0000
committerSean McGivern <sean@gitlab.com>2017-11-22 15:08:55 +0000
commitdb1925f917b30571e0e9d4de63417db90dc693d7 (patch)
tree82cfe66b4c93e7c1127d2782f81b0c97d5e3e60e /spec/support
parent0efa7e24f22abd1dc04c165f31e7b77b0eb30ed4 (diff)
downloadgitlab-ce-improve-extra-queries-output.tar.gz
Improve output for extra queries in specsimprove-extra-queries-output
Previously, this used `Array#-`, which would remove all queries that matches the query text in the original set. However, sometimes we have a problem with parameterised queries, where the query text is identical both times, so we'd run a query N times instead of once, and it would be hidden from the output. Replace the logic to only remove a given query N times from the actual log, where N is the number of times it appears in the expected log.
Diffstat (limited to 'spec/support')
-rw-r--r--spec/support/query_recorder.rb11
1 files changed, 9 insertions, 2 deletions
diff --git a/spec/support/query_recorder.rb b/spec/support/query_recorder.rb
index ba0b805caad..a771b50ec4c 100644
--- a/spec/support/query_recorder.rb
+++ b/spec/support/query_recorder.rb
@@ -69,10 +69,17 @@ RSpec::Matchers.define :exceed_query_limit do |expected|
@recorder.count
end
+ def count_queries(queries)
+ queries.each_with_object(Hash.new(0)) { |query, counts| counts[query] += 1 }
+ end
+
def log_message
if expected.is_a?(ActiveRecord::QueryRecorder)
- extra_queries = (expected.log - @recorder.log).join("\n\n")
- "Extra queries: \n\n #{extra_queries}"
+ counts = count_queries(expected.log)
+ extra_queries = @recorder.log.reject { |query| counts[query] -= 1 unless counts[query].zero? }
+ extra_queries_display = count_queries(extra_queries).map { |query, count| "[#{count}] #{query}" }
+
+ (['Extra queries:'] + extra_queries_display).join("\n\n")
else
@recorder.log_message
end