Fix tests and formatting
This commit is contained in:
parent
a8ebed6016
commit
3c545133e8
4 changed files with 8 additions and 7 deletions
|
@ -38,6 +38,7 @@ module Gitlab
|
||||||
# This is memoized since this method is called for every instrumented
|
# This is memoized since this method is called for every instrumented
|
||||||
# method. Loading data from an external cache on every method call slows
|
# method. Loading data from an external cache on every method call slows
|
||||||
# things down too much.
|
# things down too much.
|
||||||
|
# in milliseconds
|
||||||
@method_call_threshold ||= settings[:method_call_threshold]
|
@method_call_threshold ||= settings[:method_call_threshold]
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -72,7 +72,7 @@ module Gitlab
|
||||||
# Returns true if the total runtime of this method exceeds the method call
|
# Returns true if the total runtime of this method exceeds the method call
|
||||||
# threshold.
|
# threshold.
|
||||||
def above_threshold?
|
def above_threshold?
|
||||||
real_time >= Metrics.method_call_threshold
|
real_time_milliseconds >= Metrics.method_call_threshold
|
||||||
end
|
end
|
||||||
|
|
||||||
def call_measurement_enabled?
|
def call_measurement_enabled?
|
||||||
|
|
|
@ -55,7 +55,6 @@ module Gitlab
|
||||||
#
|
#
|
||||||
# Returns the time as a Float.
|
# Returns the time as a Float.
|
||||||
def self.monotonic_time
|
def self.monotonic_time
|
||||||
|
|
||||||
Process.clock_gettime(Process::CLOCK_MONOTONIC, :float_second)
|
Process.clock_gettime(Process::CLOCK_MONOTONIC, :float_second)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -8,7 +8,8 @@ describe Gitlab::Metrics::MethodCall do
|
||||||
it 'measures the performance of the supplied block' do
|
it 'measures the performance of the supplied block' do
|
||||||
method_call.measure { 'foo' }
|
method_call.measure { 'foo' }
|
||||||
|
|
||||||
expect(method_call.real_time).to be_a_kind_of(Numeric)
|
expect(method_call.real_time_seconds).to be_a_kind_of(Numeric)
|
||||||
|
expect(method_call.real_time_milliseconds).to be_a_kind_of(Numeric)
|
||||||
expect(method_call.cpu_time).to be_a_kind_of(Numeric)
|
expect(method_call.cpu_time).to be_a_kind_of(Numeric)
|
||||||
expect(method_call.call_count).to eq(1)
|
expect(method_call.call_count).to eq(1)
|
||||||
end
|
end
|
||||||
|
@ -84,13 +85,13 @@ describe Gitlab::Metrics::MethodCall do
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'returns false when the total call time is not above the threshold' do
|
it 'returns false when the total call time is not above the threshold' do
|
||||||
expect(method_call).to receive(:real_time).and_return(9)
|
expect(method_call).to receive(:real_time_seconds).and_return(0.009)
|
||||||
|
|
||||||
expect(method_call.above_threshold?).to eq(false)
|
expect(method_call.above_threshold?).to eq(false)
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'returns true when the total call time is above the threshold' do
|
it 'returns true when the total call time is above the threshold' do
|
||||||
expect(method_call).to receive(:real_time).and_return(9000)
|
expect(method_call).to receive(:real_time_seconds).and_return(9)
|
||||||
|
|
||||||
expect(method_call.above_threshold?).to eq(true)
|
expect(method_call.above_threshold?).to eq(true)
|
||||||
end
|
end
|
||||||
|
@ -131,7 +132,7 @@ describe Gitlab::Metrics::MethodCall do
|
||||||
describe '#real_time' do
|
describe '#real_time' do
|
||||||
context 'without timings' do
|
context 'without timings' do
|
||||||
it 'returns 0.0' do
|
it 'returns 0.0' do
|
||||||
expect(method_call.real_time).to eq(0.0)
|
expect(method_call.real_time_seconds).to eq(0.0)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -139,7 +140,7 @@ describe Gitlab::Metrics::MethodCall do
|
||||||
it 'returns the total real time' do
|
it 'returns the total real time' do
|
||||||
method_call.measure { 'foo' }
|
method_call.measure { 'foo' }
|
||||||
|
|
||||||
expect(method_call.real_time >= 0.0).to be(true)
|
expect(method_call.real_time_seconds >= 0.0).to be(true)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue