File: profiler_spec.rb

package info (click to toggle)
puppet-agent 7.23.0-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 19,092 kB
  • sloc: ruby: 245,074; sh: 456; makefile: 38; xml: 33
file content (47 lines) | stat: -rw-r--r-- 1,179 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
require 'spec_helper'
require 'puppet/util/profiler'

describe Puppet::Util::Profiler do
  let(:profiler) { TestProfiler.new() }

  it "supports adding profilers" do
    subject.add_profiler(profiler)
    expect(subject.current[0]).to eq(profiler)
  end

  it "supports removing profilers" do
    subject.add_profiler(profiler)
    subject.remove_profiler(profiler)
    expect(subject.current.length).to eq(0)
  end

  it "supports clearing profiler list" do
    subject.add_profiler(profiler)
    subject.clear
    expect(subject.current.length).to eq(0)
  end

  it "supports profiling" do
    subject.add_profiler(profiler)
    subject.profile("hi", ["mymetric"]) {}
    expect(profiler.context[:metric_id]).to eq(["mymetric"])
    expect(profiler.context[:description]).to eq("hi")
    expect(profiler.description).to eq("hi")
  end

  class TestProfiler
    attr_accessor :context, :metric, :description

    def start(description, metric_id)
      {:metric_id => metric_id,
       :description => description}
    end

    def finish(context, description, metric_id)
      @context = context
      @metric_id = metric_id
      @description = description
    end
  end
end