librato-rack 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,44 @@
1
+ require 'test_helper'
2
+
3
+ module Librato
4
+ class Rack
5
+ class TrackerTest < MiniTest::Unit::TestCase
6
+
7
+ def test_sets_prefix
8
+ config = Configuration.new
9
+ config.prefix = 'first'
10
+
11
+ tracker = Tracker.new(config)
12
+ assert_equal 'first', tracker.collector.prefix
13
+
14
+ config.prefix = 'second'
15
+ assert_equal 'second', tracker.collector.prefix
16
+ end
17
+
18
+ def test_requires_explicit_source_on_heroku
19
+ config = Configuration.new
20
+ config.user, config.token = 'foo', 'bar'
21
+ @buffer = StringIO.new
22
+ config.log_target = @buffer
23
+ tracker = Tracker.new(config)
24
+ tracker.on_heroku = true
25
+
26
+ assert_equal false, tracker.send(:should_start?),
27
+ 'should not start with implicit source on heroku'
28
+ assert buffer_lines[0].index('source must be provided')
29
+
30
+ config.source = 'myapp'
31
+ new_tracker = Tracker.new(config)
32
+ assert_equal true, new_tracker.send(:should_start?)
33
+ end
34
+
35
+ private
36
+
37
+ def buffer_lines
38
+ @buffer.rewind
39
+ @buffer.readlines
40
+ end
41
+
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,36 @@
1
+ require 'test_helper'
2
+ require 'stringio'
3
+
4
+ module Librato
5
+ class Rack
6
+ class WorkerTest < MiniTest::Unit::TestCase
7
+
8
+ def test_basic_use
9
+ worker = Worker.new
10
+ counter = 0
11
+ Thread.new do
12
+ worker.run_periodically(0.1) do
13
+ counter += 1
14
+ end
15
+ end
16
+ sleep 0.45
17
+ assert_equal counter, 4
18
+ end
19
+
20
+ def test_start_time
21
+ worker = Worker.new
22
+
23
+ time = Time.now
24
+ start = worker.start_time(60)
25
+ assert start >= time + 60, 'should be more than 60 seconds from when run'
26
+ assert_equal 0, start.sec, 'should start on a whole minute'
27
+
28
+ time = Time.now
29
+ start = worker.start_time(10)
30
+ assert start >= time + 10, 'should be more than 10 seconds from when run'
31
+ assert_equal 0, start.sec%10, 'should be evenly divisible with whole minutes'
32
+ end
33
+
34
+ end
35
+ end
36
+ end
metadata ADDED
@@ -0,0 +1,132 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: librato-rack
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Matt Sanders
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-02-24 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: librato-metrics
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: 1.0.2
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ version: 1.0.2
30
+ - !ruby/object:Gem::Dependency
31
+ name: minitest
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :development
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ description: Rack middleware to report key app statistics and custom instrumentation
47
+ to the Librato Metrics service.
48
+ email:
49
+ - matt@librato.com
50
+ executables: []
51
+ extensions: []
52
+ extra_rdoc_files: []
53
+ files:
54
+ - lib/librato/collector/aggregator.rb
55
+ - lib/librato/collector/counter_cache.rb
56
+ - lib/librato/collector/group.rb
57
+ - lib/librato/collector.rb
58
+ - lib/librato/rack/configuration.rb
59
+ - lib/librato/rack/errors.rb
60
+ - lib/librato/rack/logger.rb
61
+ - lib/librato/rack/tracker.rb
62
+ - lib/librato/rack/validating_queue.rb
63
+ - lib/librato/rack/version.rb
64
+ - lib/librato/rack/worker.rb
65
+ - lib/librato/rack.rb
66
+ - lib/librato-rack.rb
67
+ - LICENSE
68
+ - Rakefile
69
+ - README.md
70
+ - test/apps/basic.ru
71
+ - test/apps/custom.ru
72
+ - test/apps/heroku.ru
73
+ - test/integration/custom_test.rb
74
+ - test/integration/heroku_test.rb
75
+ - test/integration/request_test.rb
76
+ - test/remote/tracker_test.rb
77
+ - test/test_helper.rb
78
+ - test/unit/collector/aggregator_test.rb
79
+ - test/unit/collector/counter_cache_test.rb
80
+ - test/unit/collector/group_test.rb
81
+ - test/unit/collector_test.rb
82
+ - test/unit/rack/configuration_test.rb
83
+ - test/unit/rack/logger_test.rb
84
+ - test/unit/rack/tracker_test.rb
85
+ - test/unit/rack/worker_test.rb
86
+ homepage: https://github.com/librato/librato-rack
87
+ licenses: []
88
+ post_install_message:
89
+ rdoc_options: []
90
+ require_paths:
91
+ - lib
92
+ required_ruby_version: !ruby/object:Gem::Requirement
93
+ none: false
94
+ requirements:
95
+ - - ! '>='
96
+ - !ruby/object:Gem::Version
97
+ version: '0'
98
+ segments:
99
+ - 0
100
+ hash: -1368002432416974153
101
+ required_rubygems_version: !ruby/object:Gem::Requirement
102
+ none: false
103
+ requirements:
104
+ - - ! '>='
105
+ - !ruby/object:Gem::Version
106
+ version: '0'
107
+ segments:
108
+ - 0
109
+ hash: -1368002432416974153
110
+ requirements: []
111
+ rubyforge_project:
112
+ rubygems_version: 1.8.25
113
+ signing_key:
114
+ specification_version: 3
115
+ summary: Use Librato Metrics with your rack application
116
+ test_files:
117
+ - test/apps/basic.ru
118
+ - test/apps/custom.ru
119
+ - test/apps/heroku.ru
120
+ - test/integration/custom_test.rb
121
+ - test/integration/heroku_test.rb
122
+ - test/integration/request_test.rb
123
+ - test/remote/tracker_test.rb
124
+ - test/test_helper.rb
125
+ - test/unit/collector/aggregator_test.rb
126
+ - test/unit/collector/counter_cache_test.rb
127
+ - test/unit/collector/group_test.rb
128
+ - test/unit/collector_test.rb
129
+ - test/unit/rack/configuration_test.rb
130
+ - test/unit/rack/logger_test.rb
131
+ - test/unit/rack/tracker_test.rb
132
+ - test/unit/rack/worker_test.rb