/
store_spec.rb
49 lines (39 loc) · 1.71 KB
/
store_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
49
require File.dirname(__FILE__) + '/../spec_helper'
require 'system_metrics/metric'
describe SystemMetrics::Store do
include NotificationsSupport
describe '#save' do
it 'should save an array of events hierarchically' do
parent = event(:start => Time.now - 10.seconds, :end => Time.now)
child = event(:start => Time.now - 9.seconds, :end => Time.now - 1.seconds)
grandchild = event(:start => Time.now - 8.seconds, :end => Time.now - 2.seconds)
store = SystemMetrics::Store.new
lambda {
store.save([grandchild, child, parent])
}.should change(SystemMetrics::Metric, :count).by(3)
metrics = SystemMetrics::Metric.all
verify_equal(parent, metrics[0])
verify_equal(child, metrics[0].children[0])
verify_equal(grandchild, metrics[0].children[0].children[0])
end
it 'should not attempt to save anything if passed an empty array of events' do
store = SystemMetrics::Store.new
lambda { store.save([]) }.should_not change(SystemMetrics::Metric, :count)
end
it 'should not attempt to save anything if passed a nil' do
store = SystemMetrics::Store.new
lambda { store.save(nil) }.should_not change(SystemMetrics::Metric, :count)
end
end
private
def verify_equal(event, metric)
event.name.should == metric.name
event.action.should == metric.action
event.category.should == metric.category
event.transaction_id.should == metric.transaction_id
event.payload.should == metric.payload
event.started_at.should be_within(1).of(metric.started_at)
event.duration.should be_within(1).of(metric.duration)
event.exclusive_duration.should be_within(1).of(metric.exclusive_duration)
end
end