diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2019-10-17 18:08:05 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2019-10-17 18:08:05 +0000 |
commit | 184c2ced0761bd8dd7032619d16d3983fed7944a (patch) | |
tree | cc82b32ee7c1797509da3cf384617e4ffa2e1733 /spec/lib/gitlab/metrics | |
parent | 238d22c07218adf2b8f3db630ee8b74ca6f29df5 (diff) | |
download | gitlab-ce-184c2ced0761bd8dd7032619d16d3983fed7944a.tar.gz |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/lib/gitlab/metrics')
-rw-r--r-- | spec/lib/gitlab/metrics/system_spec.rb | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/spec/lib/gitlab/metrics/system_spec.rb b/spec/lib/gitlab/metrics/system_spec.rb index 6d2764a06f2..a5aa80686fd 100644 --- a/spec/lib/gitlab/metrics/system_spec.rb +++ b/spec/lib/gitlab/metrics/system_spec.rb @@ -58,4 +58,44 @@ describe Gitlab::Metrics::System do expect(described_class.monotonic_time).to be_an(Float) end end + + describe '.thread_cpu_time' do + it 'returns cpu_time on supported platform' do + stub_const("Process::CLOCK_THREAD_CPUTIME_ID", 16) + + expect(Process).to receive(:clock_gettime) + .with(16, kind_of(Symbol)) { 0.111222333 } + + expect(described_class.thread_cpu_time).to eq(0.111222333) + end + + it 'returns nil on unsupported platform' do + hide_const("Process::CLOCK_THREAD_CPUTIME_ID") + + expect(described_class.thread_cpu_time).to be_nil + end + end + + describe '.thread_cpu_duration' do + let(:start_time) { described_class.thread_cpu_time } + + it 'returns difference between start and current time' do + stub_const("Process::CLOCK_THREAD_CPUTIME_ID", 16) + + expect(Process).to receive(:clock_gettime) + .with(16, kind_of(Symbol)) + .and_return( + 0.111222333, + 0.222333833 + ) + + expect(described_class.thread_cpu_duration(start_time)).to eq(0.1111115) + end + + it 'returns nil on unsupported platform' do + hide_const("Process::CLOCK_THREAD_CPUTIME_ID") + + expect(described_class.thread_cpu_duration(start_time)).to be_nil + end + end end |