summaryrefslogtreecommitdiff
path: root/spec/gitlab_metrics_spec.rb
diff options
context:
space:
mode:
Diffstat (limited to 'spec/gitlab_metrics_spec.rb')
-rw-r--r--spec/gitlab_metrics_spec.rb30
1 files changed, 30 insertions, 0 deletions
diff --git a/spec/gitlab_metrics_spec.rb b/spec/gitlab_metrics_spec.rb
new file mode 100644
index 0000000..885fa3b
--- /dev/null
+++ b/spec/gitlab_metrics_spec.rb
@@ -0,0 +1,30 @@
+require_relative 'spec_helper'
+require_relative '../lib/gitlab_metrics'
+
+describe GitlabMetrics do
+ describe '::measure' do
+ it 'returns the return value of the block' do
+ val = described_class.measure('foo') { 10 }
+
+ expect(val).to eq(10)
+ end
+
+ it 'write in a file metrics data' do
+ result = nil
+ expect(described_class.logger).to receive(:debug) do |&b|
+ result = b.call
+ end
+
+ described_class.measure('foo') { 10 }
+
+ expect(result).to match(/name=\"foo\" wall_time=\d+ cpu_time=\d+/)
+ end
+
+ it 'calls proper measure methods' do
+ expect(described_class::System).to receive(:monotonic_time).twice.and_call_original
+ expect(described_class::System).to receive(:cpu_time).twice.and_call_original
+
+ described_class.measure('foo') { 10 }
+ end
+ end
+end