diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2019-10-22 11:31:16 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2019-10-22 11:31:16 +0000 |
commit | 905c1110b08f93a19661cf42a276c7ea90d0a0ff (patch) | |
tree | 756d138db422392c00471ab06acdff92c5a9b69c /spec/lib/gitlab/metrics/system_spec.rb | |
parent | 50d93f8d1686950fc58dda4823c4835fd0d8c14b (diff) | |
download | gitlab-ce-905c1110b08f93a19661cf42a276c7ea90d0a0ff.tar.gz |
Add latest changes from gitlab-org/gitlab@12-4-stable-ee
Diffstat (limited to 'spec/lib/gitlab/metrics/system_spec.rb')
-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 |