-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathsinged_spec.rb
More file actions
68 lines (55 loc) · 1.78 KB
/
singed_spec.rb
File metadata and controls
68 lines (55 loc) · 1.78 KB
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# frozen_string_literal: true
RSpec.describe Singed do
around do |example|
original_enabled = Singed.enabled?
example.run
ensure
Singed.enabled = original_enabled
Singed.instance_variable_set(:@current_flamegraph, nil)
end
describe ".start" do
before { Singed.enabled = true }
it "creates a current flamegraph and starts profiling" do
current_flamegraph = Singed.start
expect(current_flamegraph).to be_a(Singed::Flamegraph)
expect(Singed.profiling?).to be true
expect(current_flamegraph.started?).to be true
end
it "does nothing when already profiling" do
Singed.start
expect(Singed.start).to be_nil
end
it "does nothing when disabled" do
Singed.enabled = false
expect(Singed.start).to be_nil
expect(Singed.profiling?).to be_falsey
end
end
describe ".stop" do
before do
Singed.enabled = true
end
it "returns nil when not profiling" do
expect(Singed.stop).to be_nil
end
it "stops profiling, saves the result file, and returns the flamegraph with profile data" do
Singed.start
# Run some code to generate profile samples
100.times { 2**10 }
flamegraph = Singed.stop
expect(flamegraph).to be_a(Singed::Flamegraph)
expect(Singed.profiling?).to be false
# Profile data is returned (StackProf results hash)
expect(flamegraph.profile).to be_a(Hash)
expect(flamegraph.profile).to include(:mode, :version, :interval)
expect(flamegraph.profile[:mode]).to eq(:wall)
expect(flamegraph.profile[:samples]).to be >= 0
end
it "creates the result file on disk" do
Singed.start
100.times { 2**10 }
flamegraph = Singed.stop
expect(Pathname(flamegraph.filename)).to exist
end
end
end