mirror of
https://gh.wpcy.net/https://github.com/discourse/discourse.git
synced 2026-06-18 20:40:03 +08:00
Adds `RspecPerformanceFormatter`, an RSpec formatter that captures the SQL queries, Redis commands, and outbound network calls each example performs and emits them as NDJSON with one object per test. It gives an AI model (or a developer) concrete per-test context for spotting N+1s, redundant queries, or unexpected outbound calls. Off unless the formatter is selected, so normal runs and production are unaffected. Works with both `bin/rspec` and `bin/turbo_rspec`.
19 lines
589 B
Ruby
Vendored
19 lines
589 B
Ruby
Vendored
# frozen_string_literal: true
|
|
|
|
if ENV["DISCOURSE_RSPEC_PERFORMANCE_FORMATTER"] == "1"
|
|
require_relative "rspec_performance_formatter"
|
|
|
|
RSpec.configure do |config|
|
|
config.before(:suite) { MethodProfiler.ensure_discourse_instrumentation! }
|
|
|
|
config.around(:each) do |example|
|
|
test_summary = nil
|
|
request_groups =
|
|
RspecPerformanceFormatter.collect_requests do
|
|
test_summary = RspecPerformanceFormatter.measure { example.run }
|
|
end
|
|
|
|
example.metadata[:perf] = RspecPerformanceFormatter.assemble(test_summary, request_groups)
|
|
end
|
|
end
|
|
end
|