Commit 27536206 authored by Stan Hu's avatar Stan Hu Committed by Sean McGivern

Fix intermittent failures in profiler_spec.rb

When multiple threads run in spec/lib/gitlab/profiler_spec.rb, the
output contains profiles for each thread. The previous test assumed
there were only 1 profile, but we need to account for multiple outputs.
To fix this test, we parse and test each thread profile independently.

Closes https://gitlab.com/gitlab-org/gitlab/issues/206907
parent 330b7d5e
......@@ -195,6 +195,7 @@ describe Gitlab::Profiler do
describe '.print_by_total_time' do
let(:stdout) { StringIO.new }
let(:regexp) { /^\s+\d+\.\d+\s+(\d+\.\d+)/ }
let(:output) do
stdout.rewind
......@@ -202,6 +203,8 @@ describe Gitlab::Profiler do
end
let_it_be(:result) do
Thread.new { sleep 1 }
RubyProf.profile do
sleep 0.1
1.to_s
......@@ -212,24 +215,23 @@ describe Gitlab::Profiler do
stub_const('STDOUT', stdout)
end
it 'prints a profile result sorted by total time', quarantine: 'https://gitlab.com/gitlab-org/gitlab/issues/206907' do
it 'prints a profile result sorted by total time' do
described_class.print_by_total_time(result)
total_times =
output
.scan(/^\s+\d+\.\d+\s+(\d+\.\d+)/)
.map { |(total)| total.to_f }
expect(output).to include('Kernel#sleep')
if total_times != total_times.sort.reverse
warn "Profiler test failed, output is:"
warn output
end
thread_profiles = output.split('Sort by: total_time').select { |x| x =~ regexp }
thread_profiles.each do |profile|
total_times =
profile
.scan(regexp)
.map { |(total)| total.to_f }
expect(total_times).to eq(total_times.sort.reverse)
expect(total_times).not_to eq(total_times.uniq)
end
end
it 'accepts a max_percent option' do
described_class.print_by_total_time(result, max_percent: 50)
......
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