summaryrefslogtreecommitdiff
path: root/spec
diff options
context:
space:
mode:
authorPaco Guzman <pacoguzmanp@gmail.com>2016-10-10 14:21:28 +0200
committerPaco Guzman <pacoguzmanp@gmail.com>2016-10-11 13:15:28 +0200
commitba44420a2184476fb4c76b3b797b5d1e3e714c8a (patch)
tree9af1b29e5a14497e7c632880c8a04efe08655f24 /spec
parentb30d957fe2a85ee9ebb058010020e1c21d256a44 (diff)
downloadgitlab-shell-62-instrument-gitlab-shell.tar.gz
Instrument GitLab Shell and log metrics data to a file62-instrument-gitlab-shell
Diffstat (limited to 'spec')
-rw-r--r--spec/gitlab_keys_spec.rb4
-rw-r--r--spec/gitlab_metrics_spec.rb30
2 files changed, 32 insertions, 2 deletions
diff --git a/spec/gitlab_keys_spec.rb b/spec/gitlab_keys_spec.rb
index 67f9f40..c1c3854 100644
--- a/spec/gitlab_keys_spec.rb
+++ b/spec/gitlab_keys_spec.rb
@@ -53,7 +53,7 @@ describe GitlabKeys do
end
context "without file writing" do
- before { gitlab_keys.stub(:open) }
+ before { allow(gitlab_keys).to receive(:open) }
before { create_authorized_keys_fixture }
it "should log an add-key event" do
@@ -106,7 +106,7 @@ describe GitlabKeys do
context "without file writing" do
before do
- gitlab_keys.should_receive(:open).and_yield(mock(:file, puts: nil, chmod: nil))
+ gitlab_keys.should_receive(:open).and_yield(double(:file, puts: nil, chmod: nil))
end
it "should log an add-key event" do
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