newrelic_rpm 3.9.6.257 → 3.9.7.266

Sign up to get free protection for your applications and to get access to all the features.
Files changed (122) hide show
  1. data.tar.gz.sig +0 -0
  2. data/CHANGELOG +45 -0
  3. data/lib/new_relic/agent.rb +0 -1
  4. data/lib/new_relic/agent/agent.rb +61 -22
  5. data/lib/new_relic/agent/agent_logger.rb +11 -9
  6. data/lib/new_relic/agent/configuration/default_source.rb +25 -2
  7. data/lib/new_relic/agent/cross_app_monitor.rb +15 -53
  8. data/lib/new_relic/agent/cross_app_tracing.rb +11 -3
  9. data/lib/new_relic/agent/custom_event_aggregator.rb +98 -0
  10. data/lib/new_relic/agent/event_buffer.rb +84 -0
  11. data/lib/new_relic/agent/harvester.rb +4 -15
  12. data/lib/new_relic/agent/hostname.rb +1 -9
  13. data/lib/new_relic/agent/inbound_request_monitor.rb +41 -0
  14. data/lib/new_relic/agent/instrumentation/controller_instrumentation.rb +2 -2
  15. data/lib/new_relic/agent/instrumentation/queue_time.rb +0 -5
  16. data/lib/new_relic/agent/instrumentation/resque.rb +4 -9
  17. data/lib/new_relic/agent/javascript_instrumentor.rb +0 -12
  18. data/lib/new_relic/agent/method_tracer_helpers.rb +3 -1
  19. data/lib/new_relic/agent/new_relic_service.rb +1 -1
  20. data/lib/new_relic/agent/sampled_buffer.rb +13 -41
  21. data/lib/new_relic/agent/samplers/delayed_job_sampler.rb +52 -24
  22. data/lib/new_relic/agent/sized_buffer.rb +23 -0
  23. data/lib/new_relic/agent/synthetics_monitor.rb +50 -0
  24. data/lib/new_relic/agent/system_info.rb +28 -0
  25. data/lib/new_relic/agent/transaction.rb +78 -9
  26. data/lib/new_relic/agent/transaction/synthetics_sample_buffer.rb +25 -0
  27. data/lib/new_relic/agent/{request_sampler.rb → transaction_event_aggregator.rb} +53 -19
  28. data/lib/new_relic/agent/transaction_sample_builder.rb +3 -1
  29. data/lib/new_relic/agent/transaction_sampler.rb +10 -0
  30. data/lib/new_relic/agent/transaction_state.rb +1 -9
  31. data/lib/new_relic/coerce.rb +8 -2
  32. data/lib/new_relic/control.rb +0 -1
  33. data/lib/new_relic/local_environment.rb +12 -8
  34. data/lib/new_relic/metric_spec.rb +11 -2
  35. data/lib/new_relic/rack/developer_mode.rb +9 -1
  36. data/lib/new_relic/transaction_sample.rb +4 -10
  37. data/lib/new_relic/version.rb +1 -1
  38. data/newrelic_rpm.gemspec +1 -0
  39. data/test/agent_helper.rb +15 -2
  40. data/test/environments/norails/Gemfile +1 -0
  41. data/test/environments/rails21/Gemfile +1 -0
  42. data/test/environments/rails22/Gemfile +1 -0
  43. data/test/environments/rails23/Gemfile +1 -0
  44. data/test/environments/rails30/Gemfile +1 -0
  45. data/test/environments/rails31/Gemfile +1 -0
  46. data/test/environments/rails32/Gemfile +2 -1
  47. data/test/environments/rails40/Gemfile +2 -1
  48. data/test/environments/rails41/Gemfile +3 -1
  49. data/test/environments/rails42/Gemfile +3 -1
  50. data/test/fixtures/cross_agent_tests/README.md +6 -2
  51. data/test/fixtures/cross_agent_tests/docker_container_id/README.md +6 -0
  52. data/test/fixtures/cross_agent_tests/docker_container_id/cases.json +22 -0
  53. data/test/fixtures/cross_agent_tests/docker_container_id/docker-0.9.1.txt +10 -0
  54. data/test/fixtures/cross_agent_tests/docker_container_id/docker-1.0.0.txt +10 -0
  55. data/test/fixtures/cross_agent_tests/docker_container_id/docker-1.3.txt +9 -0
  56. data/test/fixtures/cross_agent_tests/docker_container_id/empty.txt +0 -0
  57. data/test/fixtures/cross_agent_tests/docker_container_id/lxc-containers-without-docker.txt +10 -0
  58. data/test/fixtures/cross_agent_tests/proc_meminfo/README.md +7 -0
  59. data/test/fixtures/cross_agent_tests/proc_meminfo/meminfo_4096MB.txt +47 -0
  60. data/test/fixtures/cross_agent_tests/rum_client_config.json +0 -80
  61. data/test/fixtures/cross_agent_tests/synthetics/synthetics.json +317 -0
  62. data/test/multiverse/lib/multiverse/runner.rb +1 -1
  63. data/test/multiverse/lib/multiverse/suite.rb +1 -0
  64. data/test/multiverse/suites/active_record/Envfile +42 -8
  65. data/test/multiverse/suites/active_record/ar_method_aliasing.rb +8 -4
  66. data/test/multiverse/suites/agent_only/audit_log_test.rb +0 -2
  67. data/test/multiverse/suites/agent_only/collector_exception_handling_test.rb +1 -2
  68. data/test/multiverse/suites/agent_only/cross_application_tracing_test.rb +5 -5
  69. data/test/multiverse/suites/agent_only/encoding_handling_test.rb +2 -0
  70. data/test/multiverse/suites/agent_only/harvest_timestamps_test.rb +8 -0
  71. data/test/multiverse/suites/agent_only/synthetics_test.rb +139 -0
  72. data/test/multiverse/suites/delayed_job/Envfile +79 -0
  73. data/test/multiverse/suites/delayed_job/before_suite.rb +33 -0
  74. data/test/multiverse/suites/delayed_job/config/newrelic.yml +18 -0
  75. data/test/multiverse/suites/delayed_job/delayed_job_sampler_test.rb +131 -0
  76. data/test/multiverse/suites/delayed_job/unsupported_backend_test.rb +24 -0
  77. data/test/multiverse/suites/high_security/high_security_test.rb +3 -10
  78. data/test/multiverse/suites/rails/Envfile +4 -4
  79. data/test/multiverse/suites/rails/request_statistics_test.rb +4 -4
  80. data/test/new_relic/agent/agent_test.rb +32 -4
  81. data/test/new_relic/agent/configuration/default_source_test.rb +6 -0
  82. data/test/new_relic/agent/cross_app_monitor_test.rb +23 -29
  83. data/test/new_relic/agent/custom_event_aggregator_test.rb +88 -0
  84. data/test/new_relic/agent/event_buffer_test_cases.rb +152 -0
  85. data/test/new_relic/agent/harvester_test.rb +5 -25
  86. data/test/new_relic/agent/hostname_test.rb +1 -1
  87. data/test/new_relic/agent/inbound_request_monitor_test.rb +49 -0
  88. data/test/new_relic/agent/instrumentation/controller_instrumentation_test.rb +9 -9
  89. data/test/new_relic/agent/instrumentation/queue_time_test.rb +0 -19
  90. data/test/new_relic/agent/javascript_instrumentor_test.rb +0 -45
  91. data/test/new_relic/agent/new_relic_service_test.rb +17 -12
  92. data/test/new_relic/agent/pipe_channel_manager_test.rb +4 -4
  93. data/test/new_relic/agent/sampled_buffer_test.rb +73 -145
  94. data/test/new_relic/agent/sized_buffer_test.rb +29 -0
  95. data/test/new_relic/agent/synthetics_monitor_test.rb +96 -0
  96. data/test/new_relic/agent/system_info_test.rb +19 -3
  97. data/test/new_relic/agent/transaction/developer_mode_sample_buffer_test.rb +14 -8
  98. data/test/new_relic/agent/transaction/synthetics_sample_buffer_test.rb +38 -0
  99. data/test/new_relic/agent/{request_sampler_test.rb → transaction_event_aggregator_test.rb} +55 -4
  100. data/test/new_relic/agent/transaction_sampler_test.rb +33 -11
  101. data/test/new_relic/agent/transaction_state_test.rb +0 -1
  102. data/test/new_relic/agent/transaction_test.rb +121 -19
  103. data/test/new_relic/coerce_test.rb +38 -3
  104. data/test/new_relic/control_test.rb +1 -0
  105. data/test/new_relic/fake_collector.rb +6 -2
  106. data/test/new_relic/fake_external_server.rb +2 -6
  107. data/test/new_relic/fake_server.rb +46 -29
  108. data/test/new_relic/http_client_test_cases.rb +71 -2
  109. data/test/new_relic/local_environment_test.rb +78 -0
  110. data/test/new_relic/metric_parser/metric_parser_test.rb +2 -0
  111. data/test/new_relic/metric_spec_test.rb +43 -0
  112. data/test/new_relic/multiverse_helpers.rb +11 -18
  113. data/test/new_relic/rack/browser_monitoring_test.rb +1 -18
  114. data/test/new_relic/rack/developer_mode_test.rb +1 -1
  115. data/test/new_relic/transaction_sample_test.rb +14 -4
  116. data/test/performance/suites/rack_middleware.rb +3 -1
  117. data/test/test_helper.rb +33 -0
  118. metadata +48 -7
  119. metadata.gz.sig +0 -0
  120. data/lib/new_relic/agent/browser_token.rb +0 -41
  121. data/test/multiverse/suites/agent_only/before_suite.rb +0 -7
  122. data/test/new_relic/agent/browser_token_test.rb +0 -56
@@ -0,0 +1,152 @@
1
+ # encoding: utf-8
2
+ # This file is distributed under New Relic's license terms.
3
+ # See https://github.com/newrelic/rpm/blob/master/LICENSE for complete details.
4
+
5
+ require File.expand_path(File.join(File.dirname(__FILE__),'..','..','test_helper'))
6
+ require 'new_relic/agent/event_buffer'
7
+
8
+ module NewRelic::Agent::EventBufferTestCases
9
+
10
+ # NOTE: Classes including this module must define `buffer_class`; for example:
11
+ #
12
+ # def buffer_class
13
+ # MyVerySpecialBuffer
14
+ # end
15
+
16
+ def test_limits_itself_to_capacity
17
+ buffer = buffer_class.new(10)
18
+
19
+ 11.times { |i| buffer.append(i) }
20
+
21
+ assert_equal(10, buffer.size )
22
+ assert_equal(11, buffer.num_seen )
23
+ assert_equal( 1, buffer.num_dropped)
24
+ end
25
+
26
+ def test_should_not_discard_items_if_not_needed_when_capacity_is_reset
27
+ buffer = buffer_class.new(10)
28
+ assert_equal(10, buffer.capacity)
29
+ 10.times { |i| buffer << i }
30
+
31
+ buffer.capacity = 20
32
+ assert_equal(10, buffer.size )
33
+ assert_equal(20, buffer.capacity )
34
+ assert_equal(10, buffer.num_seen )
35
+ assert_equal( 0, buffer.num_dropped)
36
+ assert_equal((0..9).to_a, buffer.to_a)
37
+ end
38
+
39
+ def test_reset_should_reset
40
+ buffer = buffer_class.new(10)
41
+ 100.times { |i| buffer << i }
42
+ buffer.reset!
43
+ assert_equal(0, buffer.size)
44
+ assert_equal([], buffer.to_a)
45
+ end
46
+
47
+ def test_to_a_returns_copy_of_items_array
48
+ buffer = buffer_class.new(5)
49
+
50
+ 5.times { |i| buffer.append(i) }
51
+
52
+ items = buffer.to_a
53
+ items << ['blarg']
54
+
55
+ assert_equal([0,1,2,3,4], buffer.to_a)
56
+ end
57
+
58
+ def test_reset_resets_stored_items
59
+ buffer = buffer_class.new(5)
60
+
61
+ 5.times { |i| buffer.append(i) }
62
+ buffer.reset!
63
+
64
+ assert_equal([], buffer.to_a)
65
+ end
66
+
67
+ def test_buffer_full_works_properly
68
+ buffer = buffer_class.new(5)
69
+
70
+ 4.times do |i|
71
+ buffer << i
72
+ assert_equal(false, buffer.full?, "#{buffer_class}#append should return false until buffer is full")
73
+ end
74
+
75
+ 4.times do |i|
76
+ buffer << 'lava'
77
+ assert_equal(true, buffer.full?, "#{buffer_class}#append should return true once buffer is full")
78
+ end
79
+ end
80
+
81
+ def test_should_keep_all_samples_up_to_capacity
82
+ buffer = buffer_class.new(100)
83
+ all = []
84
+ 100.times do |i|
85
+ buffer << i
86
+ all << i
87
+ end
88
+
89
+ assert_equal(100, buffer.size)
90
+ assert_equal(all, buffer.to_a)
91
+ end
92
+
93
+ def test_should_discard_items_as_needed_when_capacity_is_reset
94
+ buffer = buffer_class.new(10)
95
+ 10.times { |i| buffer << i }
96
+
97
+ buffer.capacity = 5
98
+ assert_equal(5, buffer.size)
99
+
100
+ # We should have 5 unique values that were all in our original set of 0-9
101
+ assert_equal(5, buffer.to_a.uniq.size)
102
+ allowed_values = (0..9).to_a
103
+ buffer.to_a.each do |v|
104
+ assert_includes(allowed_values, v)
105
+ end
106
+ assert_equal(10, buffer.num_seen )
107
+ assert_equal( 5, buffer.num_dropped)
108
+ end
109
+
110
+ def test_num_seen_counts_all_seen_samples_since_last_reset
111
+ buffer = buffer_class.new(10)
112
+ assert_equal(0, buffer.num_seen)
113
+
114
+ 20.times { |i| buffer << i }
115
+ assert_equal(20, buffer.num_seen)
116
+
117
+ buffer.reset!
118
+ assert_equal(0, buffer.num_seen)
119
+ end
120
+
121
+ def test_append_increments_drop_count_when_over_capacity
122
+ buffer = buffer_class.new(5)
123
+
124
+ 5.times { |i| buffer.append(i) }
125
+ assert_equal(0, buffer.num_dropped)
126
+
127
+ 5.times { |i| buffer.append(i) }
128
+ assert_equal(5, buffer.num_dropped)
129
+ end
130
+
131
+ def test_reset_resets_drop_count
132
+ buffer = buffer_class.new(5)
133
+
134
+ 10.times { |i| buffer.append(i) }
135
+ assert_equal(5, buffer.num_dropped)
136
+
137
+ buffer.reset!
138
+ assert_equal(0, buffer.num_dropped)
139
+ end
140
+
141
+ def test_sample_rate
142
+ buffer = buffer_class.new(10)
143
+ assert_equal(0, buffer.sample_rate)
144
+
145
+ 10.times { buffer << 'x' }
146
+ assert_equal(1.0, buffer.sample_rate)
147
+
148
+ 10.times { buffer << 'x' }
149
+ assert_equal(0.5, buffer.sample_rate)
150
+ end
151
+
152
+ end
@@ -20,19 +20,9 @@ module NewRelic
20
20
  assert_nil harvester.starting_pid
21
21
  end
22
22
 
23
- def test_marks_started_in_process
24
- pretend_started_in_another_process
25
-
26
- with_config(:restart_thread_in_children => true) do
27
- harvester.on_transaction
28
- end
29
-
30
- assert_false harvester.needs_restart?
31
- end
32
-
33
23
  def test_skips_out_early_if_already_started
34
24
  harvester.mark_started
35
- ::Mutex.any_instance.expects(:synchronize).never
25
+ @after_forker.expects(:after_fork).never
36
26
 
37
27
  with_config(:restart_thread_in_children => true) do
38
28
  harvester.on_transaction
@@ -73,22 +63,12 @@ module NewRelic
73
63
  end
74
64
  end
75
65
 
76
- def test_calls_to_restart_only_once
66
+ def test_calls_restart_every_time_until_marked_started
77
67
  pretend_started_in_another_process
78
- @after_forker.expects(:after_fork).once
68
+ @after_forker.expects(:after_fork).times(2)
79
69
 
80
- with_config(:restart_thread_in_children => true) do
81
- threads = []
82
- 100.times do
83
- threads << Thread.new do
84
- harvester.on_transaction
85
- end
86
- end
87
-
88
- threads.each do |thread|
89
- thread.join
90
- end
91
- end
70
+ harvester.on_transaction
71
+ harvester.on_transaction
92
72
  end
93
73
 
94
74
  def pretend_started_in_another_process
@@ -75,7 +75,7 @@ module NewRelic
75
75
  def test_shortens_to_prefixes_with_unsupported_object
76
76
  with_dyno_name('Imladris.1', :'heroku.use_dyno_names' => true,
77
77
  :'heroku.dyno_name_prefixes_to_shorten' => Object.new) do
78
- expects_logging(:warn, includes('Object'))
78
+ expects_logging(:error, includes('heroku.dyno_name_prefixes_to_shorten'), instance_of(ArgumentError))
79
79
  assert_equal 'Imladris.1', NewRelic::Agent::Hostname.get
80
80
  end
81
81
  end
@@ -0,0 +1,49 @@
1
+ # encoding: utf-8
2
+ # This file is distributed under New Relic's license terms.
3
+ # See https://github.com/newrelic/rpm/blob/master/LICENSE for complete details.
4
+
5
+ require File.expand_path(File.join(File.dirname(__FILE__),'..','..','test_helper'))
6
+ require 'new_relic/agent/inbound_request_monitor'
7
+
8
+ module NewRelic::Agent
9
+ class InboundRequestMonitorTest < Minitest::Test
10
+
11
+ ENCODING_KEY_NOOP = "\0"
12
+
13
+ def setup
14
+ @events = NewRelic::Agent::EventListener.new
15
+ @monitor = NewRelic::Agent::InboundRequestMonitor.new(@events)
16
+
17
+ @config = { :encoding_key => ENCODING_KEY_NOOP }
18
+ NewRelic::Agent.config.add_config_for_testing(@config)
19
+
20
+ class << @monitor
21
+ define_method(:on_finished_configuring) do |*_|
22
+ end
23
+ end
24
+
25
+ @events.notify(:finished_configuring)
26
+ end
27
+
28
+ def teardown
29
+ NewRelic::Agent.config.remove_config(@config)
30
+ end
31
+
32
+ def test_deserialize
33
+ payload = @monitor.obfuscator.obfuscate("[1,2,3]")
34
+ assert_equal [1, 2, 3], @monitor.deserialize_header(payload, "the_key")
35
+ end
36
+
37
+ def test_deserialize_nonsense
38
+ expects_logging(:debug, includes("the_key"))
39
+ assert_nil @monitor.deserialize_header("asdf", "the_key")
40
+ end
41
+
42
+ def test_deserialize_with_invalid_json
43
+ payload = @monitor.obfuscator.obfuscate("[1,2,3")
44
+
45
+ expects_logging(:debug, includes("the_key"))
46
+ assert_nil @monitor.deserialize_header(payload, "the_key")
47
+ end
48
+ end
49
+ end
@@ -145,37 +145,37 @@ module NewRelic::Agent::Instrumentation
145
145
 
146
146
  def test_transaction_name_calls_newrelic_metric_path
147
147
  @object.stubs(:newrelic_metric_path).returns('some/wacky/path')
148
- assert_equal('Controller/some/wacky/path', @txn_namer.name(nil, @object, :controller))
148
+ assert_equal('Controller/some/wacky/path', @txn_namer.name_for(nil, @object, :controller))
149
149
  end
150
150
 
151
151
  def test_transaction_name_applies_category_and_path
152
152
  assert_equal('Controller/metric/path',
153
- @txn_namer.name(nil,
153
+ @txn_namer.name_for(nil,
154
154
  @object,
155
155
  :controller,
156
156
  :path => 'metric/path'))
157
157
  assert_equal('OtherTransaction/Background/metric/path',
158
- @txn_namer.name(nil,
158
+ @txn_namer.name_for(nil,
159
159
  @object,
160
160
  :task,
161
161
  :path => 'metric/path'))
162
162
  assert_equal('Controller/Rack/metric/path',
163
- @txn_namer.name(nil,
163
+ @txn_namer.name_for(nil,
164
164
  @object,
165
165
  :rack,
166
166
  :path => 'metric/path'))
167
167
  assert_equal('Controller/metric/path',
168
- @txn_namer.name(nil,
168
+ @txn_namer.name_for(nil,
169
169
  @object,
170
170
  :uri,
171
171
  :path => 'metric/path'))
172
172
  assert_equal('Controller/Sinatra/metric/path',
173
- @txn_namer.name(nil,
173
+ @txn_namer.name_for(nil,
174
174
  @object,
175
175
  :sinatra,
176
176
  :path => 'metric/path'))
177
177
  assert_equal('Blarg/metric/path',
178
- @txn_namer.name(nil,
178
+ @txn_namer.name_for(nil,
179
179
  @object,
180
180
  'Blarg',
181
181
  :path => 'metric/path'))
@@ -183,12 +183,12 @@ module NewRelic::Agent::Instrumentation
183
183
 
184
184
  def test_transaction_name_uses_class_name_if_path_not_specified
185
185
  assert_equal('Controller/NewRelic::Agent::Instrumentation::ControllerInstrumentationTest::TestObject',
186
- @txn_namer.name(nil, @object, :controller))
186
+ @txn_namer.name_for(nil, @object, :controller))
187
187
  end
188
188
 
189
189
  def test_transaction_name_applies_action_name_if_specified_and_not_path
190
190
  assert_equal('Controller/NewRelic::Agent::Instrumentation::ControllerInstrumentationTest::TestObject/action',
191
- @txn_namer.name(nil,
191
+ @txn_namer.name_for(nil,
192
192
  @object,
193
193
  :controller,
194
194
  :name => 'action'))
@@ -73,25 +73,6 @@ class NewRelic::Agent::Instrumentation::QueueTimeTest < Minitest::Test
73
73
  assert_in_delta(now, QueueTime.parse_frontend_timestamp(header, now), 0.001)
74
74
  end
75
75
 
76
- def test_recording_queue_time_metric
77
- QueueTime.record_frontend_metrics(Time.at(Time.now.to_f - 60))
78
- assert_metrics_recorded(
79
- 'WebFrontend/QueueTime' => {
80
- :call_count => 1,
81
- :total_call_time => 60
82
- }
83
- )
84
- end
85
-
86
- def test_doesnt_record_scoped_queue_time_metric
87
- in_transaction('boo') do
88
- QueueTime.record_frontend_metrics(Time.at(Time.now.to_f - 60))
89
- end
90
- assert_metrics_not_recorded(
91
- [['WebFrontend/QueueTime', 'boo']]
92
- )
93
- end
94
-
95
76
  def test_parsing_malformed_header
96
77
  header = { 'HTTP_X_REQUEST_START' => 'gobledy gook' }
97
78
 
@@ -160,7 +160,6 @@ class NewRelic::Agent::JavascriptInstrumentorTest < Minitest::Test
160
160
  txn.stubs(:guid).returns('ABC')
161
161
 
162
162
  state = NewRelic::Agent::TransactionState.tl_get
163
- state.request_token = '0123456789ABCDEF'
164
163
 
165
164
  data = instrumentor.data_for_js_agent(state)
166
165
  expected = {
@@ -171,8 +170,6 @@ class NewRelic::Agent::JavascriptInstrumentorTest < Minitest::Test
171
170
  "transactionName" => pack("most recent transaction"),
172
171
  "queueTime" => 0,
173
172
  "applicationTime" => 10000,
174
- "ttGuid" => "ABC",
175
- "agentToken" => "0123456789ABCDEF",
176
173
  "agent" => "",
177
174
  "userAttributes" => pack('{"user":"user"}')
178
175
  }
@@ -274,48 +271,6 @@ class NewRelic::Agent::JavascriptInstrumentorTest < Minitest::Test
274
271
  assert_equal(string, instrumentor.html_safe_if_needed(string))
275
272
  end
276
273
 
277
- def test_request_guid_to_include
278
- state = NewRelic::Agent::TransactionState.tl_get
279
- with_config(:apdex_t => 2.0) do
280
- freeze_time
281
- in_transaction do |txn|
282
- state.request_token = "token"
283
- advance_time(4.0)
284
-
285
- data = instrumentor.data_for_js_agent(state)
286
- assert_equal(state.current_transaction.guid, data['ttGuid'])
287
- end
288
- end
289
- end
290
-
291
- def test_request_guid_excluded_if_request_fast_enough
292
- state = NewRelic::Agent::TransactionState.tl_get
293
- with_config(:apdex_t => 2.0) do
294
- freeze_time
295
-
296
- state.request_token = "token"
297
- in_transaction do |txn|
298
- advance_time(1.0)
299
- data = instrumentor.data_for_js_agent(state)
300
- assert_nil(data['ttGuid'])
301
- end
302
- end
303
- end
304
-
305
- def test_request_guid_excluded_if_no_token
306
- state = NewRelic::Agent::TransactionState.tl_get
307
- with_config(:apdex_t => 2.0) do
308
- freeze_time
309
-
310
- state.request_token = nil
311
- in_transaction do |txn|
312
- advance_time(4.0)
313
- data = instrumentor.data_for_js_agent(state)
314
- assert_nil(data['ttGuid'])
315
- end
316
- end
317
- end
318
-
319
274
  # Helpers
320
275
 
321
276
  BEGINNING_OF_FOOTER = '<script type="text/javascript">window.NREUM||(NREUM={});NREUM.info='
@@ -37,7 +37,7 @@ class NewRelicServiceKeepAliveTest < Minitest::Test
37
37
  assert(!block_ran, "Expected block passed to #session to have not run")
38
38
  end
39
39
 
40
- def test_session_block_reuses_http_handle
40
+ def test_session_block_reuses_http_handle_with_aggressive_keepalive_off
41
41
  handle1 = stub_net_http_handle
42
42
  handle2 = stub_net_http_handle
43
43
  @service.stubs(:create_http_connection).returns(handle1, handle2)
@@ -47,13 +47,15 @@ class NewRelicServiceKeepAliveTest < Minitest::Test
47
47
  handle2.expects(:start).never
48
48
 
49
49
  block_ran = false
50
- @service.session do
51
- block_ran = true
52
- assert(@service.http_connection)
50
+ with_config(:aggressive_keepalive => false) do
51
+ @service.session do
52
+ block_ran = true
53
+ assert(@service.http_connection)
53
54
 
54
- # check we get the same object back each time we call http_connection in the block
55
- assert_equal(@service.http_connection.object_id, handle1.object_id)
56
- assert_equal(@service.http_connection.object_id, handle1.object_id)
55
+ # check we get the same object back each time we call http_connection in the block
56
+ assert_equal(@service.http_connection.object_id, handle1.object_id)
57
+ assert_equal(@service.http_connection.object_id, handle1.object_id)
58
+ end
57
59
  end
58
60
  assert(block_ran)
59
61
  end
@@ -67,17 +69,20 @@ class NewRelicServiceKeepAliveTest < Minitest::Test
67
69
  end
68
70
 
69
71
 
70
- def test_session_starts_and_finishes_http_session
72
+ def test_session_starts_and_finishes_http_session_with_aggressive_keepalive_off
71
73
  handle1 = stub_net_http_handle
72
74
  handle1.expects(:start).once
73
75
  handle1.expects(:finish).once
74
76
  @service.stubs(:create_http_connection).returns(handle1)
75
77
 
76
78
  block_ran = false
77
- @service.session do
78
- block_ran = true
79
- # mocks expect #start and #finish to be called. This is how Net::HTTP
80
- # implements keep alive
79
+
80
+ with_config(:aggressive_keepalive => false) do
81
+ @service.session do
82
+ block_ran = true
83
+ # mocks expect #start and #finish to be called. This is how Net::HTTP
84
+ # implements keep alive
85
+ end
81
86
  end
82
87
  assert(block_ran)
83
88
  end