newrelic_rpm 3.7.3.204 → 3.8.0.218

Sign up to get free protection for your applications and to get access to all the features.
Files changed (154) hide show
  1. data.tar.gz.sig +0 -0
  2. data/CHANGELOG +73 -0
  3. data/README.md +1 -1
  4. data/Rakefile +1 -5
  5. data/lib/new_relic/agent.rb +1 -0
  6. data/lib/new_relic/agent/agent.rb +47 -18
  7. data/lib/new_relic/agent/agent_logger.rb +11 -1
  8. data/lib/new_relic/agent/configuration/default_source.rb +85 -1
  9. data/lib/new_relic/agent/configuration/manager.rb +5 -1
  10. data/lib/new_relic/agent/datastores/mongo.rb +8 -3
  11. data/lib/new_relic/agent/harvester.rb +5 -1
  12. data/lib/new_relic/agent/instrumentation/action_controller_subscriber.rb +1 -0
  13. data/lib/new_relic/agent/instrumentation/active_merchant.rb +7 -3
  14. data/lib/new_relic/agent/instrumentation/controller_instrumentation.rb +13 -3
  15. data/lib/new_relic/agent/instrumentation/rails/action_controller.rb +7 -1
  16. data/lib/new_relic/agent/instrumentation/sidekiq.rb +3 -1
  17. data/lib/new_relic/agent/instrumentation/sinatra.rb +3 -1
  18. data/lib/new_relic/agent/new_relic_service.rb +8 -0
  19. data/lib/new_relic/agent/request_sampler.rb +1 -1
  20. data/lib/new_relic/agent/sampler.rb +22 -2
  21. data/lib/new_relic/agent/sampler_collection.rb +13 -1
  22. data/lib/new_relic/agent/samplers/cpu_sampler.rb +3 -1
  23. data/lib/new_relic/agent/samplers/delayed_job_sampler.rb +2 -1
  24. data/lib/new_relic/agent/samplers/memory_sampler.rb +2 -1
  25. data/lib/new_relic/agent/samplers/object_sampler.rb +1 -3
  26. data/lib/new_relic/agent/samplers/vm_sampler.rb +126 -0
  27. data/lib/new_relic/agent/stats.rb +0 -15
  28. data/lib/new_relic/agent/stats_engine/gc_profiler.rb +66 -75
  29. data/lib/new_relic/agent/stats_engine/stats_hash.rb +1 -1
  30. data/lib/new_relic/agent/supported_versions.rb +2 -2
  31. data/lib/new_relic/agent/transaction.rb +6 -3
  32. data/lib/new_relic/agent/vm/monotonic_gc_profiler.rb +17 -5
  33. data/lib/new_relic/agent/vm/mri_vm.rb +2 -1
  34. data/lib/new_relic/agent/vm/snapshot.rb +5 -1
  35. data/lib/new_relic/control/instance_methods.rb +8 -5
  36. data/lib/new_relic/control/instrumentation.rb +0 -9
  37. data/lib/new_relic/environment_report.rb +1 -1
  38. data/lib/new_relic/language_support.rb +4 -0
  39. data/lib/new_relic/local_environment.rb +39 -14
  40. data/lib/new_relic/noticed_error.rb +7 -4
  41. data/lib/new_relic/rack/browser_monitoring.rb +16 -3
  42. data/lib/new_relic/version.rb +2 -2
  43. data/newrelic_rpm.gemspec +1 -1
  44. data/test/agent_helper.rb +5 -3
  45. data/test/environments/lib/environments/runner.rb +8 -7
  46. data/test/environments/norails/Gemfile +1 -1
  47. data/test/environments/rails21/Gemfile +1 -0
  48. data/test/environments/rails22/Gemfile +1 -0
  49. data/test/environments/rails23/Gemfile +1 -0
  50. data/test/environments/rails30/Gemfile +4 -1
  51. data/test/environments/rails31/Gemfile +4 -1
  52. data/test/environments/rails32/Gemfile +3 -4
  53. data/test/environments/rails40/Gemfile +1 -1
  54. data/test/environments/rails41/Gemfile +1 -1
  55. data/test/flaky_proxy/lib/flaky_proxy/proxy.rb +1 -0
  56. data/test/multiverse/lib/multiverse/output_collector.rb +3 -1
  57. data/test/multiverse/lib/multiverse/runner.rb +2 -10
  58. data/test/multiverse/lib/multiverse/suite.rb +100 -30
  59. data/test/multiverse/suites/activemerchant/Envfile +16 -0
  60. data/test/multiverse/suites/activemerchant/activemerchant_test.rb +65 -0
  61. data/test/multiverse/suites/agent_only/custom_queue_time_test.rb +57 -0
  62. data/test/multiverse/suites/config_file_loading/config_file_loading_test.rb +1 -1
  63. data/test/multiverse/suites/mongo/Envfile +9 -1
  64. data/test/multiverse/suites/rails/Envfile +2 -2
  65. data/test/multiverse/suites/rails/app.rb +3 -0
  66. data/test/multiverse/suites/rails/bad_instrumentation_test.rb +0 -2
  67. data/test/multiverse/suites/rails/error_tracing_test.rb +1 -2
  68. data/test/multiverse/suites/rails/gc_instrumentation_test.rb +17 -8
  69. data/test/multiverse/suites/rails/ignore_test.rb +0 -2
  70. data/test/multiverse/suites/rails/mongrel_queue_depth_test.rb +0 -2
  71. data/test/multiverse/suites/rails/queue_time_test.rb +40 -11
  72. data/test/multiverse/suites/rails/request_statistics_test.rb +0 -3
  73. data/test/multiverse/suites/rails/view_instrumentation_test.rb +0 -2
  74. data/test/multiverse/suites/sidekiq/Envfile +7 -2
  75. data/test/multiverse/suites/sinatra/Envfile +1 -1
  76. data/test/multiverse/suites/sinatra/nested_middleware_test.rb +41 -0
  77. data/test/multiverse/suites/sinatra/sinatra_metric_explosion_test.rb +1 -1
  78. data/test/new_relic/agent/agent/connect_test.rb +32 -4
  79. data/test/new_relic/agent/agent/start_test.rb +9 -1
  80. data/test/new_relic/agent/agent_logger_test.rb +23 -2
  81. data/test/new_relic/agent/agent_test.rb +49 -7
  82. data/test/new_relic/agent/configuration/manager_test.rb +8 -0
  83. data/test/new_relic/agent/configuration/orphan_configuration_test.rb +7 -0
  84. data/test/new_relic/agent/cross_app_monitor_test.rb +5 -6
  85. data/test/new_relic/agent/harvester_test.rb +13 -8
  86. data/test/new_relic/agent/instrumentation/action_controller_subscriber_test.rb +28 -7
  87. data/test/new_relic/agent/instrumentation/controller_instrumentation_test.rb +32 -21
  88. data/test/new_relic/agent/new_relic_service_test.rb +14 -0
  89. data/test/new_relic/agent/request_sampler_test.rb +5 -3
  90. data/test/new_relic/agent/rpm_agent_test.rb +2 -3
  91. data/test/new_relic/agent/sampler_collection_test.rb +15 -5
  92. data/test/new_relic/agent/sampler_test.rb +43 -0
  93. data/test/new_relic/agent/{cpu_sampler_test.rb → samplers/cpu_sampler_test.rb} +1 -1
  94. data/test/new_relic/agent/samplers/vm_sampler_test.rb +349 -0
  95. data/test/new_relic/agent/stats_engine/gc_profiler_test.rb +165 -44
  96. data/test/new_relic/agent/stats_hash_test.rb +1 -1
  97. data/test/new_relic/agent/transaction_test.rb +14 -0
  98. data/test/new_relic/agent/vm/monotonic_gc_profiler_test.rb +5 -5
  99. data/test/new_relic/agent/vm/mri_vm_test.rb +7 -0
  100. data/test/new_relic/agent/vm/snapshot_test.rb +5 -0
  101. data/test/new_relic/agent_test.rb +2 -2
  102. data/test/new_relic/control/instance_methods_test.rb +30 -0
  103. data/test/new_relic/control_test.rb +43 -21
  104. data/test/new_relic/dispatcher_test.rb +5 -0
  105. data/test/new_relic/local_environment_test.rb +3 -26
  106. data/test/new_relic/multiverse_helpers.rb +5 -0
  107. data/test/new_relic/noticed_error_test.rb +7 -0
  108. data/test/new_relic/rack/browser_monitoring_test.rb +13 -14
  109. data/test/test_helper.rb +2 -1
  110. metadata +56 -68
  111. metadata.gz.sig +1 -1
  112. data/lib/new_relic/agent/instrumentation/puma.rb +0 -25
  113. data/lib/new_relic/agent/instrumentation/unicorn_instrumentation.rb +0 -26
  114. data/test/multiverse/script/run_one +0 -5
  115. data/test/rum/basic.result.html +0 -10
  116. data/test/rum/basic.source.html +0 -10
  117. data/test/rum/comments1.result.html +0 -24
  118. data/test/rum/comments1.source.html +0 -24
  119. data/test/rum/comments2.result.html +0 -24
  120. data/test/rum/comments2.source.html +0 -24
  121. data/test/rum/gt_in_quotes1.result.html +0 -27
  122. data/test/rum/gt_in_quotes1.source.html +0 -27
  123. data/test/rum/gt_in_quotes2.result.html +0 -24
  124. data/test/rum/gt_in_quotes2.source.html +0 -24
  125. data/test/rum/gt_in_quotes_mismatch.result.html +0 -24
  126. data/test/rum/gt_in_quotes_mismatch.source.html +0 -24
  127. data/test/rum/gt_in_single_quotes1.result.html +0 -25
  128. data/test/rum/gt_in_single_quotes1.source.html +0 -25
  129. data/test/rum/gt_in_single_quotes_mismatch.result.html +0 -25
  130. data/test/rum/gt_in_single_quotes_mismatch.source.html +0 -25
  131. data/test/rum/incomplete_non_meta_tags.result.html +0 -10
  132. data/test/rum/incomplete_non_meta_tags.source.html +0 -10
  133. data/test/rum/no_body.result.html +0 -21
  134. data/test/rum/no_body.source.html +0 -21
  135. data/test/rum/no_header.result.html +0 -7
  136. data/test/rum/no_header.source.html +0 -7
  137. data/test/rum/no_html_and_no_header.result.html +0 -3
  138. data/test/rum/no_html_and_no_header.source.html +0 -3
  139. data/test/rum/no_start_header.result.html +0 -9
  140. data/test/rum/no_start_header.source.html +0 -9
  141. data/test/rum/script1.result.html +0 -19
  142. data/test/rum/script1.source.html +0 -19
  143. data/test/rum/script2.result.html +0 -17
  144. data/test/rum/script2.source.html +0 -17
  145. data/test/rum/x_ua_meta_tag.result.html +0 -10
  146. data/test/rum/x_ua_meta_tag.source.html +0 -10
  147. data/test/rum/x_ua_meta_tag_multiline.result.html +0 -11
  148. data/test/rum/x_ua_meta_tag_multiline.source.html +0 -11
  149. data/test/rum/x_ua_meta_tag_spaces_around_equals.result.html +0 -10
  150. data/test/rum/x_ua_meta_tag_spaces_around_equals.source.html +0 -10
  151. data/test/rum/x_ua_meta_tag_with_others.result.html +0 -11
  152. data/test/rum/x_ua_meta_tag_with_others.source.html +0 -11
  153. data/test/rum/x_ua_meta_tag_with_spaces.result.html +0 -10
  154. data/test/rum/x_ua_meta_tag_with_spaces.source.html +0 -10
@@ -4,63 +4,184 @@
4
4
 
5
5
  require File.expand_path(File.join(File.dirname(__FILE__),'..','..','..','test_helper'))
6
6
 
7
- class NewRelic::Agent::StatsEngine::GCProfilerTest < Minitest::Test
8
- def test_init_profiler_for_rails_bench
9
- return unless defined?(::GC) && ::GC.respond_to?(:collections)
7
+ class NewRelic::Agent::StatsEngine
8
+ class GCProfilerTest < Minitest::Test
9
+ def setup
10
+ NewRelic::Agent.drop_buffered_data
10
11
 
11
- ::GC.stubs(:time)
12
- ::GC.stubs(:collections)
12
+ stub_gc_profiling_enabled
13
+ GCProfiler.reset
14
+ end
13
15
 
14
- assert_equal(NewRelic::Agent::StatsEngine::GCProfiler::RailsBenchProfiler,
15
- NewRelic::Agent::StatsEngine::GCProfiler.init.class)
16
- end
16
+ def teardown
17
+ GCProfiler.reset
18
+ end
17
19
 
18
- def test_init_profiler_for_ruby_19_and_greater
19
- return unless defined?(::GC::Profiler)
20
- return if NewRelic::LanguageSupport.using_engine?('jruby')
20
+ def test_init_profiler_for_rails_bench
21
+ return unless defined?(::GC) && ::GC.respond_to?(:collections)
21
22
 
22
- ::GC::Profiler.stubs(:enabled?).returns(true)
23
- ::GC::Profiler.stubs(:total_time).returns(0)
24
- ::GC.stubs(:count).returns(0)
23
+ ::GC.stubs(:time)
24
+ ::GC.stubs(:collections)
25
25
 
26
- assert_equal(NewRelic::Agent::StatsEngine::GCProfiler::CoreGCProfiler,
27
- NewRelic::Agent::StatsEngine::GCProfiler.init.class)
28
- end
26
+ assert_equal(GCProfiler::RailsBenchProfiler,
27
+ GCProfiler.init.class)
28
+ end
29
29
 
30
- def test_init_profiler_for_rbx_uses_stdlib
31
- return unless defined?(::Rubinius::GC)
30
+ def test_init_profiler_for_ruby_19_and_greater
31
+ return unless defined?(::GC::Profiler)
32
+ return if NewRelic::LanguageSupport.using_engine?('jruby')
32
33
 
33
- assert_equal(NewRelic::Agent::StatsEngine::GCProfiler::CoreGCProfiler,
34
- NewRelic::Agent::StatsEngine::GCProfiler.init.class)
35
- end
34
+ ::GC::Profiler.stubs(:enabled?).returns(true)
36
35
 
37
- def test_collect_gc_data
38
- return if NewRelic::LanguageSupport.using_engine?('jruby')
36
+ assert_equal(GCProfiler::CoreGCProfiler,
37
+ GCProfiler.init.class)
38
+ end
39
39
 
40
- GC.disable
41
- if NewRelic::LanguageSupport.using_version?('1.9')
42
- ::GC::Profiler.stubs(:enabled?).returns(true)
43
- ::GC::Profiler.stubs(:total_time).returns(1.0, 4.0)
44
- ::GC.stubs(:count).returns(1, 3)
45
- ::GC::Profiler.stubs(:clear).returns(nil)
46
- elsif NewRelic::LanguageSupport.using_version?('1.8.7') &&
47
- RUBY_DESCRIPTION =~ /Ruby Enterprise Edition/
48
- ::GC.stubs(:time).returns(1000000, 4000000)
49
- ::GC.stubs(:collections).returns(1, 3)
50
- else
51
- return true # no need to test if we're not collecting GC metrics
40
+ def test_init_profiler_for_rbx_uses_stdlib
41
+ return unless defined?(::Rubinius::GC)
42
+
43
+ assert_equal(GCProfiler::CoreGCProfiler,
44
+ GCProfiler.init.class)
52
45
  end
53
46
 
54
- with_config(:'transaction_tracer.enabled' => true) do
55
- in_transaction { }
47
+ def test_record_delta_returns_nil_when_snapshots_are_nil
48
+ result = GCProfiler.record_delta(nil, nil)
49
+ assert_nil(result)
50
+ assert_metrics_not_recorded([GCProfiler::GC_ROLLUP, GCProfiler::GC_WEB, GCProfiler::GC_OTHER])
56
51
  end
57
52
 
58
- engine = NewRelic::Agent.instance.stats_engine
59
- tracer = NewRelic::Agent.instance.transaction_sampler
53
+ using_jruby = NewRelic::LanguageSupport.jruby?
54
+ using_ree = NewRelic::LanguageSupport.ree?
55
+ using_ruby18 = NewRelic::LanguageSupport.using_version?('1.8')
56
+ using_ruby19_plus = !using_ruby18
57
+
58
+ # Only run these tests in environments where GCProfiler is usable
59
+ if !using_jruby && (using_ree || using_ruby19_plus)
60
+ def test_record_delta_returns_delta_in_seconds
61
+ GCProfiler.init
62
+
63
+ start_snapshot = GCProfiler::GCSnapshot.new(1.0, 1)
64
+ end_snapshot = GCProfiler::GCSnapshot.new(2.5, 3)
65
+
66
+ result = GCProfiler.record_delta(start_snapshot, end_snapshot)
67
+ assert_equal(1.5, result)
68
+ end
69
+
70
+ def test_record_delta_records_gc_time_and_call_count_in_metric
71
+ GCProfiler.init
72
+ start_snapshot = GCProfiler::GCSnapshot.new(1.0, 1)
73
+ end_snapshot = GCProfiler::GCSnapshot.new(2.5, 3)
74
+
75
+ GCProfiler.record_delta(start_snapshot, end_snapshot)
76
+
77
+ assert_gc_metrics(GCProfiler::GC_OTHER,
78
+ :call_count => 2, :total_call_time => 1.5)
79
+ end
80
+
81
+ # This test is asserting that the implementation of GC::Profiler provided by
82
+ # the language implementation currently in use behaves in the way we assume.
83
+ # Specifically, we expect that GC::Profiler.clear will *not* reset GC.count.
84
+ def test_gc_profiler_clear_does_not_reset_count
85
+ return unless defined?(::GC::Profiler)
86
+
87
+ GC::Profiler.enable
88
+
89
+ count_before_allocations = GC.count
90
+ 100000.times { String.new }
91
+ GC.start
92
+ count_after_allocations = GC.count
93
+ GC::Profiler.clear
94
+ count_after_clear = GC.count
95
+
96
+ assert_operator count_before_allocations, :<, count_after_allocations
97
+ assert_operator count_after_allocations, :<=, count_after_clear
98
+ ensure
99
+ GC::Profiler.disable if defined?(::GC::Profiler)
100
+ end
101
+
102
+ def test_take_snapshot_should_return_snapshot
103
+ stub_gc_timer(5.0)
104
+ stub_gc_count(10)
60
105
 
61
- gc_stats = engine.get_stats('GC/cumulative')
62
- assert_equal 2, gc_stats.call_count
63
- assert_equal 3.0, gc_stats.total_call_time
64
- assert_equal(3.0, tracer.last_sample.params[:custom_params][:gc_time])
106
+ snapshot = GCProfiler.take_snapshot
107
+
108
+ assert_equal(5.0, snapshot.gc_time_s)
109
+ assert_equal(10, snapshot.gc_call_count)
110
+ end
111
+
112
+ def test_collect_gc_data
113
+ stub_gc_timer(1.0)
114
+ stub_gc_count(1)
115
+
116
+ with_config(:'transaction_tracer.enabled' => true) do
117
+ in_transaction do
118
+ stub_gc_timer(4.0)
119
+ stub_gc_count(3)
120
+ end
121
+ end
122
+
123
+ assert_gc_metrics(GCProfiler::GC_OTHER,
124
+ :call_count => 2, :total_call_time => 3.0)
125
+ assert_metrics_not_recorded(GCProfiler::GC_WEB)
126
+
127
+ tracer = NewRelic::Agent.instance.transaction_sampler
128
+ assert_equal(3.0, tracer.last_sample.params[:custom_params][:gc_time])
129
+ end
130
+
131
+ def test_collect_gc_data_web
132
+ stub_gc_timer(1.0)
133
+ stub_gc_count(1)
134
+
135
+ with_config(:'transaction_tracer.enabled' => true) do
136
+ in_web_transaction do
137
+ stub_gc_timer(4.0)
138
+ stub_gc_count(3)
139
+ end
140
+ end
141
+
142
+ assert_gc_metrics(GCProfiler::GC_WEB,
143
+ :call_count => 2, :total_call_time => 3.0)
144
+ assert_metrics_not_recorded(GCProfiler::GC_OTHER)
145
+ end
146
+ end
147
+
148
+ def assert_gc_metrics(name, expected_values={})
149
+ assert_metrics_recorded(
150
+ [GCProfiler::GC_ROLLUP, ''] => expected_values,
151
+ name => expected_values
152
+ )
153
+ assert_metrics_not_recorded([[GCProfiler::GC_ROLLUP, 'dummy']])
154
+ end
155
+
156
+ # gc_timer_value should be specified in seconds
157
+ def stub_gc_timer(gc_timer_value_s)
158
+ profiler = GCProfiler.init
159
+
160
+ gc_timer_value_us = gc_timer_value_s * 1_000_000
161
+
162
+ case profiler
163
+ when GCProfiler::CoreGCProfiler
164
+ NewRelic::Agent.instance.monotonic_gc_profiler.stubs(:total_time_s).returns(gc_timer_value_s)
165
+ when GCProfiler::RailsBenchProfiler
166
+ ::GC.stubs(:time).returns(gc_timer_value_us)
167
+ end
168
+ end
169
+
170
+ def stub_gc_count(gc_count)
171
+ profiler = GCProfiler.init
172
+
173
+ case profiler
174
+ when GCProfiler::CoreGCProfiler
175
+ ::GC.stubs(:count).returns(gc_count)
176
+ when GCProfiler::RailsBenchProfiler
177
+ ::GC.stubs(:collections).returns(gc_count)
178
+ end
179
+ end
180
+
181
+ def stub_gc_profiling_enabled
182
+ if defined?(::GC::Profiler)
183
+ ::GC::Profiler.stubs(:enabled?).returns(true)
184
+ end
185
+ end
65
186
  end
66
187
  end
@@ -117,7 +117,7 @@ class NewRelic::Agent::StatsHashTest < Minitest::Test
117
117
  hash1 = NewRelic::Agent::StatsHash.new(t1)
118
118
 
119
119
  hash1.merge!(hash0)
120
- assert_equal(t0, hash1.started_at)
120
+ assert_equal(t0.to_f, hash1.started_at)
121
121
  end
122
122
 
123
123
  def test_marshal_dump
@@ -438,6 +438,20 @@ class NewRelic::Agent::TransactionTest < Minitest::Test
438
438
  assert_equal 1, NewRelic::Agent.instance.error_collector.errors.count
439
439
  end
440
440
 
441
+ def test_records_gc_time
442
+ gc_start = mock('gc start')
443
+ gc_end = mock('gc end')
444
+ NewRelic::Agent::StatsEngine::GCProfiler.stubs(:take_snapshot).returns(gc_start, gc_end)
445
+
446
+ txn = in_transaction do
447
+ NewRelic::Agent::StatsEngine::GCProfiler.expects(:record_delta).with(gc_start, gc_end).returns(42)
448
+ NewRelic::Agent::Transaction.current
449
+ end
450
+
451
+ trace = txn.transaction_trace
452
+ assert_equal(42, trace.params[:custom_params][:gc_time])
453
+ end
454
+
441
455
  def assert_has_custom_parameter(key, value = key)
442
456
  assert_equal(value, NewRelic::Agent::Transaction.current.custom_parameters[key])
443
457
  end
@@ -15,20 +15,20 @@ class MonotonicGCProfilerTest < Minitest::Test
15
15
 
16
16
  if NewRelic::LanguageSupport.gc_profiler_usable?
17
17
  def test_total_time_isnt_nil
18
- refute_nil profiler.total_time
18
+ refute_nil profiler.total_time_s
19
19
  end
20
20
 
21
21
  def test_total_time_reads_from_gc_profiler
22
22
  GC::Profiler.stubs(:total_time).returns(0)
23
- assert_equal 0, profiler.total_time
23
+ assert_equal 0, profiler.total_time_s
24
24
 
25
25
  GC::Profiler.stubs(:total_time).returns(100)
26
- assert_equal 100, profiler.total_time
26
+ assert_equal 100, profiler.total_time_s
27
27
  end
28
28
 
29
29
  def test_total_time_resets_underlying_gc_profiler
30
30
  GC::Profiler.expects(:clear).once
31
- profiler.total_time
31
+ profiler.total_time_s
32
32
  end
33
33
  end
34
34
 
@@ -36,7 +36,7 @@ class MonotonicGCProfilerTest < Minitest::Test
36
36
  NewRelic::LanguageSupport.stubs(:gc_profiler_enabled?).returns(false)
37
37
 
38
38
  assert_raises(NewRelic::Agent::VM::MonotonicGCProfiler::ProfilerNotEnabledError) do
39
- profiler.total_time
39
+ profiler.total_time_s
40
40
  end
41
41
  end
42
42
  end
@@ -28,6 +28,13 @@ unless NewRelic::LanguageSupport.jruby? || NewRelic::LanguageSupport.rubinius?
28
28
  @vm.gather_gc_time(@snap)
29
29
  assert_nil @snap.gc_total_time
30
30
  end
31
+
32
+ def test_gather_stats_records_gc_time_if_available
33
+ NewRelic::Agent.instance.monotonic_gc_profiler.stubs(:total_time_s).returns(999)
34
+ NewRelic::LanguageSupport.stubs(:gc_profiler_enabled?).returns(true)
35
+ @vm.gather_stats(@snap)
36
+ assert_equal(999, @snap.gc_total_time)
37
+ end
31
38
  end
32
39
  end
33
40
  end
@@ -5,4 +5,9 @@
5
5
  require 'new_relic/agent/vm/snapshot'
6
6
 
7
7
  class NewRelic::Agent::VM::SnapshotTestCase < Minitest::Test
8
+ def test_records_taken_at_on_initialization
9
+ t = freeze_time
10
+ snap = NewRelic::Agent::VM::Snapshot.new
11
+ assert_equal(t.to_f, snap.taken_at)
12
+ end
8
13
  end
@@ -28,14 +28,14 @@ module NewRelic
28
28
  end
29
29
 
30
30
  def test_shutdown_removes_manual_startup_config
31
- NewRelic::Agent.manual_start(:some_absurd_setting => true)
31
+ NewRelic::Agent.manual_start(:monitor_mode => true, :license_key => "a" * 40, :some_absurd_setting => true)
32
32
  assert NewRelic::Agent.config[:some_absurd_setting]
33
33
  NewRelic::Agent.shutdown
34
34
  assert !NewRelic::Agent.config[:some_absurd_setting]
35
35
  end
36
36
 
37
37
  def test_shutdown_removes_server_config
38
- NewRelic::Agent.manual_start
38
+ NewRelic::Agent.manual_start(:monitor_mode => true, :license_key => "a" * 40)
39
39
  NewRelic::Agent.instance.service = default_service
40
40
  NewRelic::Agent.instance.finish_setup('agent_config' =>
41
41
  { :some_absurd_setting => true })
@@ -0,0 +1,30 @@
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/control/instance_methods'
7
+ require 'new_relic/agent/configuration/yaml_source'
8
+
9
+ class TestClass
10
+ include NewRelic::Control::InstanceMethods
11
+ end
12
+
13
+ class NewRelic::Control::InstanceMethodsTest < Minitest::Test
14
+ def setup
15
+ NewRelic::Agent.config.reset_to_defaults
16
+ @test = ::TestClass.new(nil)
17
+ end
18
+
19
+ def test_configure_agent_adds_the_yaml_config
20
+ refute NewRelic::Agent.config.config_stack_index_for NewRelic::Agent::Configuration::YamlSource
21
+ @test.configure_agent('test', {})
22
+ assert NewRelic::Agent.config.config_stack_index_for NewRelic::Agent::Configuration::YamlSource
23
+ end
24
+
25
+ def test_configure_agent_adds_the_manual_config
26
+ refute NewRelic::Agent.config.config_stack_index_for NewRelic::Agent::Configuration::ManualSource
27
+ @test.configure_agent('test', {})
28
+ assert NewRelic::Agent.config.config_stack_index_for NewRelic::Agent::Configuration::ManualSource
29
+ end
30
+ end
@@ -16,24 +16,6 @@ class NewRelic::ControlTest < Minitest::Test
16
16
  NewRelic::Agent.shutdown
17
17
  end
18
18
 
19
-
20
- def test_test_config
21
- if defined?(::Rails) && ::Rails::VERSION::MAJOR.to_i == 4
22
- assert_equal :rails4, control.app
23
- elsif defined?(::Rails) && ::Rails::VERSION::MAJOR.to_i == 3
24
- assert_equal :rails3, control.app
25
- elsif defined?(::Rails)
26
- assert_equal :rails, control.app
27
- else
28
- assert_equal :test, control.app
29
- end
30
- assert_equal :test, control.framework
31
- assert("" == NewRelic::Agent.config[:dispatcher].to_s,
32
- "Expected dispatcher to be empty, but was #{NewRelic::Agent.config[:dispatcher].to_s}")
33
- assert !NewRelic::Agent.config[:monitor_mode]
34
- control.local_env
35
- end
36
-
37
19
  def test_settings_accessor
38
20
  refute_nil control.settings
39
21
  end
@@ -180,7 +162,10 @@ class NewRelic::ControlTest < Minitest::Test
180
162
 
181
163
  def test_init_plugin_loads_samplers_enabled
182
164
  reset_agent
183
- with_config(:disable_samplers => false, :agent_enabled => true) do
165
+ with_config(:disable_samplers => false,
166
+ :agent_enabled => true,
167
+ :monitor_mode => true,
168
+ :license_key => 'a'*40) do
184
169
  NewRelic::Control.instance.init_plugin
185
170
  assert NewRelic::Agent.instance.harvest_samplers.any?
186
171
  end
@@ -188,14 +173,51 @@ class NewRelic::ControlTest < Minitest::Test
188
173
 
189
174
  def test_init_plugin_loads_samplers_disabled
190
175
  reset_agent
191
- with_config(:disable_samplers => true, :agent_enabled => true) do
176
+ with_config(:disable_samplers => true,
177
+ :agent_enabled => true,
178
+ :monitor_mode => true,
179
+ :license_key => 'a'*40) do
192
180
  NewRelic::Control.instance.init_plugin
193
- assert !NewRelic::Agent.instance.harvest_samplers.any?
181
+ refute NewRelic::Agent.instance.harvest_samplers.any?
182
+ end
183
+ end
184
+
185
+ def test_agent_not_starting_does_not_load_samplers
186
+ reset_agent
187
+
188
+ NewRelic::Agent.instance.stubs(:defer_for_delayed_job?).returns(true)
189
+
190
+ with_config(:disable_samplers => false,
191
+ :agent_enabled => true,
192
+ :monitor_mode => true,
193
+ :license_key => 'a'*40) do
194
+ NewRelic::Control.instance.init_plugin
195
+ refute NewRelic::Agent.instance.already_started?
196
+ refute NewRelic::Agent.instance.harvest_samplers.any?
197
+ end
198
+ end
199
+
200
+ def test_agent_starting_after_fork_does_load_samplers
201
+ reset_agent
202
+
203
+ NewRelic::Agent.instance.stubs(:defer_for_delayed_job?).returns(true)
204
+
205
+ with_config(:disable_samplers => false,
206
+ :agent_enabled => true,
207
+ :monitor_mode => true,
208
+ :license_key => 'a'*40) do
209
+ NewRelic::Control.instance.init_plugin
210
+ NewRelic::Agent.instance.stubs(:defer_for_delayed_job?).returns(false)
211
+ NewRelic::Agent.after_fork
212
+ assert NewRelic::Agent.instance.already_started?
213
+ assert NewRelic::Agent.instance.harvest_samplers.any?
194
214
  end
195
215
  end
196
216
 
197
217
  def reset_agent
198
218
  NewRelic::Agent.shutdown
199
219
  NewRelic::Agent.instance.harvest_samplers.clear
220
+ NewRelic::Agent.instance.instance_variable_set(:@connect_state, :pending)
221
+ NewRelic::Agent.instance.instance_variable_set(:@worker_thread, nil)
200
222
  end
201
223
  end