-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathvmstat_spec.rb
48 lines (40 loc) · 1.52 KB
/
vmstat_spec.rb
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
require 'spec_helper'
describe Vmstat do
context "#boot_time" do
let(:boot_time) { Vmstat.boot_time }
it "should be an array" do
expect(boot_time).to be_a(Time)
end
it "has to be a time before now" do
expect(boot_time).to be < Time.now
end
end
context "Vmstat#filter_devices" do
unless travis? # no external ethernet devices on travis ci
it "should filter ethernet devices" do
expect(Vmstat.ethernet_devices.size).to be >= 1
end
end
it "should filter loopback devices" do
expect(Vmstat.loopback_devices.size).to be >= 1
end
end
context "performance" do
percent = RUBY_VERSION.to_i == 2 ? 26 : 10
shared_examples "a not memory leaking method" do |method_name, *args|
it "should not grow the memory in method #{method_name} " +
"more than #{percent}% " do
mem_before = Vmstat.task.resident_size
10000.times { Vmstat.send(method_name, *args) }
mem_after = Vmstat.task.resident_size
expect(mem_after).to be < (mem_before * (1 + percent / 100.0))
end
end
it_should_behave_like "a not memory leaking method", :network_interfaces
it_should_behave_like "a not memory leaking method", :cpu
it_should_behave_like "a not memory leaking method", :memory
it_should_behave_like "a not memory leaking method", :disk, "/"
it_should_behave_like "a not memory leaking method", :boot_time
it_should_behave_like "a not memory leaking method", :load_average
end if ENV['PERF'] == "1"
end