newrelic_rpm 3.5.3.25 → 3.5.4.29.beta

Sign up to get free protection for your applications and to get access to all the features.
@@ -61,7 +61,8 @@ class SinatraMetricExplosionTest < Test::Unit::TestCase
61
61
  get '/hello/isitmeyourelookingfor?'
62
62
  get '/another_controller'
63
63
 
64
- metric_names = ::NewRelic::Agent.agent.stats_engine.stats_hash.keys.map{|k| k.name} - ['CPU/User Time']
64
+ metric_names = ::NewRelic::Agent.agent.stats_engine.stats_hash.keys.
65
+ map{|k| k.name} - ['CPU/User Time', "Middleware/all", "WebFrontend/QueueTime", "WebFrontend/WebServer/all"]
65
66
  assert_equal 6, metric_names.size, "Explosion detected in: #{metric_names.inspect}"
66
67
  end
67
68
 
@@ -0,0 +1,55 @@
1
+
2
+ class SinatraRouteTestApp < Sinatra::Base
3
+ configure do
4
+ # create a condition (sintra's version of a before_filter) that returns the
5
+ # value that was passed into it.
6
+ set :my_condition do |boolean|
7
+ condition do
8
+ halt 404 unless boolean
9
+ end
10
+ end
11
+ end
12
+
13
+ get '/user/login' do
14
+ "please log in"
15
+ end
16
+
17
+ # this action will always return 404 because of the condition.
18
+ get '/user/:id', :my_condition => false do |id|
19
+ "Welcome #{id}"
20
+ end
21
+ end
22
+
23
+ class SinatraTest < Test::Unit::TestCase
24
+ include Rack::Test::Methods
25
+ include ::NewRelic::Agent::Instrumentation::Sinatra
26
+
27
+ def app
28
+ SinatraRouteTestApp
29
+ end
30
+
31
+ def setup
32
+ ::NewRelic::Agent.manual_start
33
+ end
34
+
35
+ # https://support.newrelic.com/tickets/24779
36
+ def test_lower_priority_route_conditions_arent_applied_to_higher_priority_routes
37
+ get '/user/login'
38
+ assert_equal 200, last_response.status
39
+ assert_equal 'please log in', last_response.body
40
+ end
41
+
42
+ def test_conditions_are_applied_to_an_action_that_uses_them
43
+ get '/user/1'
44
+ assert_equal 404, last_response.status
45
+ end
46
+
47
+ def test_queue_time_headers_are_passed_to_agent
48
+ get '/user/login', {}, {"X-Request-Start" => 't=1234567890'}
49
+ metric_names = ::NewRelic::Agent.agent.stats_engine.stats_hash.keys.map{|k| k.name}
50
+ assert metric_names.include?("Middleware/all")
51
+ assert metric_names.include?("WebFrontend/QueueTime")
52
+ assert metric_names.include?("WebFrontend/WebServer/all")
53
+ assert ::NewRelic::Agent.agent.stats_engine.get_stats("WebFrontend/WebServer/all")
54
+ end
55
+ end
@@ -118,6 +118,20 @@ class NewRelic::Agent::Instrumentation::QueueTimeTest < Test::Unit::TestCase
118
118
  check_metric_time('WebFrontend/WebServer/serverb', 1.0, 0.1)
119
119
  end
120
120
 
121
+ def test_parse_server_time_accepting_milliseconds_resolution_separator_char
122
+ env = {'HTTP_X_REQUEST_START' => "t=1000.000000"}
123
+ create_test_start_time(env)
124
+ env['HTTP_X_QUEUE_START'] = "t=1001.000000"
125
+ assert_calls_metrics('WebFrontend/WebServer/all') do
126
+ assert_equal(Time.at(1000), parse_server_time_from(env))
127
+ end
128
+ assert_calls_metrics('WebFrontend/QueueTime') do
129
+ assert_equal(Time.at(1001), parse_queue_time_from(env))
130
+ end
131
+ check_metric_time('WebFrontend/WebServer/all', 2.0, 0.1)
132
+ check_metric_time('WebFrontend/QueueTime', 1.0, 0.1)
133
+ end
134
+
121
135
  # test for backwards compatibility with old header
122
136
  def test_parse_server_time_from_with_no_server_name
123
137
  env = {'HTTP_X_REQUEST_START' => "t=#{convert_to_microseconds(Time.at(1001))}"}
@@ -0,0 +1,25 @@
1
+ require File.expand_path(File.join(File.dirname(__FILE__), '..', '..', '..', 'test_helper'))
2
+ require 'new_relic/agent/instrumentation/sinatra'
3
+
4
+ class NewRelic::Agent::Instrumentation::SinatraTest < Test::Unit::TestCase
5
+ class SinatraTestApp
6
+ def initialize(response)
7
+ @response = response
8
+ end
9
+
10
+ def dispatch!
11
+ @response = response
12
+ end
13
+
14
+ include NewRelic::Agent::Instrumentation::Sinatra
15
+ alias dispatch_without_newrelic dispatch!
16
+ alias dispatch! dispatch_with_newrelic
17
+ end
18
+
19
+ def test_newrelic_request_headers
20
+ app = SinatraTestApp.new([200, {}, ["OK"]])
21
+ expected_headers = {:fake => :header}
22
+ app.expects(:request).returns(mock('request', :env => expected_headers))
23
+ assert_equal app.send(:newrelic_request_headers), expected_headers
24
+ end
25
+ end
@@ -86,4 +86,36 @@ class NewRelic::VersionNumberTest < Test::Unit::TestCase
86
86
  assert_equal '1.2.0', NewRelic::VersionNumber.new('1.2.0').to_s
87
87
  assert_equal '1.2', NewRelic::VersionNumber.new('1.2').to_s
88
88
  end
89
+
90
+ def test_gemspec_version_parsing
91
+ gemspec_contents = File.read(File.join(File.dirname(__FILE__), '..', '..', 'newrelic_rpm.gemspec'))
92
+ gemspec_contents =~ /s\.version\s*=\s*"(.*)"/
93
+ real_version = $1
94
+ assert_equal real_version, NewRelic::VERSION::STRING
95
+ end
96
+
97
+ def test_gemspec_parse_no_build
98
+ version = NewRelic::VERSION.parse_build_from_gemspec(NewRelic.fixture_path('gemspec_no_build.rb'))
99
+ assert_nil version
100
+ end
101
+
102
+ def test_gemspec_parse_with_build
103
+ version = NewRelic::VERSION.parse_build_from_gemspec(NewRelic.fixture_path('gemspec_with_build.rb'))
104
+ assert_equal '123', version
105
+ end
106
+
107
+ def test_gemspec_parse_with_build_and_stage
108
+ version = NewRelic::VERSION.parse_build_from_gemspec(NewRelic.fixture_path('gemspec_with_build_and_stage.rb'))
109
+ assert_equal '123.dev', version
110
+ end
111
+
112
+ def test_gemspec_parse_no_rubygems
113
+ Kernel.stubs(:const_defined?).with(:Gem).returns(false)
114
+ version = NewRelic::VERSION.parse_build_from_gemspec(NewRelic.fixture_path('gemspec_with_build_and_stage.rb'))
115
+ assert_equal '123.dev', version
116
+ end
117
+
118
+ def test_gemspec_parse_nonexistent
119
+ assert_nil NewRelic::VERSION.parse_build_from_gemspec('/really/not/a/real/path')
120
+ end
89
121
  end
@@ -137,6 +137,12 @@ def with_config(config_hash, level=0)
137
137
  end
138
138
  end
139
139
 
140
+ module NewRelic
141
+ def self.fixture_path(name)
142
+ File.join(File.dirname(__FILE__), 'fixtures', name)
143
+ end
144
+ end
145
+
140
146
  module TransactionSampleTestHelper
141
147
  module_function
142
148
  def make_sql_transaction(*sql)
metadata CHANGED
@@ -1,17 +1,18 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: newrelic_rpm
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.5.3.25
5
- prerelease:
4
+ version: 3.5.4.29.beta
5
+ prerelease: 9
6
6
  platform: ruby
7
7
  authors:
8
8
  - Jason Clark
9
9
  - Sam Goldstein
10
10
  - Jon Guymon
11
+ - Ben Weintraub
11
12
  autorequire:
12
13
  bindir: bin
13
14
  cert_chain: []
14
- date: 2012-12-05 00:00:00.000000000 Z
15
+ date: 2012-12-11 00:00:00.000000000 Z
15
16
  dependencies: []
16
17
  description: ! 'New Relic is a performance management system, developed by New Relic,
17
18
 
@@ -176,6 +177,9 @@ files:
176
177
  - test/active_record_fixtures.rb
177
178
  - test/config/newrelic.yml
178
179
  - test/config/test_control.rb
180
+ - test/fixtures/gemspec_no_build.rb
181
+ - test/fixtures/gemspec_with_build.rb
182
+ - test/fixtures/gemspec_with_build_and_stage.rb
179
183
  - test/fixtures/proc_cpuinfo.txt
180
184
  - test/intentional_fail.rb
181
185
  - test/multiverse/.gitignore
@@ -245,6 +249,7 @@ files:
245
249
  - test/multiverse/suites/sinatra/config/newrelic.yml
246
250
  - test/multiverse/suites/sinatra/sinatra_metric_explosion_test.rb
247
251
  - test/multiverse/suites/sinatra/sinatra_routes_test.rb
252
+ - test/multiverse/suites/sinatra/sinatra_test.rb
248
253
  - test/multiverse/test/multiverse_test.rb
249
254
  - test/multiverse/test/suite_examples/one/a/Envfile
250
255
  - test/multiverse/test/suite_examples/one/a/a_test.rb
@@ -283,6 +288,7 @@ files:
283
288
  - test/new_relic/agent/instrumentation/net_instrumentation_test.rb
284
289
  - test/new_relic/agent/instrumentation/queue_time_test.rb
285
290
  - test/new_relic/agent/instrumentation/rack_test.rb
291
+ - test/new_relic/agent/instrumentation/sinatra_test.rb
286
292
  - test/new_relic/agent/instrumentation/task_instrumentation_test.rb
287
293
  - test/new_relic/agent/memcache_instrumentation_test.rb
288
294
  - test/new_relic/agent/method_tracer/class_methods/add_method_tracer_test.rb