newrelic_rpm 3.1.1.beta2 → 3.1.1.beta3

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of newrelic_rpm might be problematic. Click here for more details.

@@ -223,7 +223,7 @@ class NewRelic::Agent::Agent::StartTest < Test::Unit::TestCase
223
223
  def test_notify_log_file_location_positive
224
224
  log = mocked_log
225
225
  NewRelic::Control.instance.expects(:log_file).returns('./')
226
- log.expects(:send).with(:info, "Agent Log found in ./")
226
+ log.expects(:send).with(:info, "Agent Log at ./")
227
227
  notify_log_file_location
228
228
  end
229
229
 
@@ -2,8 +2,9 @@ require File.expand_path(File.join(File.dirname(__FILE__),'..','..','test_helper
2
2
 
3
3
  memcached_ready = false
4
4
  classes = {
5
- 'memcache' => 'MemCache',
6
- 'dalli' => 'Dalli::Client',
5
+ 'memcache' => 'MemCache'
6
+ # 'dalli' => 'Dalli::Client'
7
+ # 'memcached' => 'Memcached'
7
8
  }
8
9
  begin
9
10
  TCPSocket.new('localhost', 11211)
@@ -27,10 +28,16 @@ class NewRelic::Agent::MemcacheInstrumentationTest < Test::Unit::TestCase
27
28
  def setup
28
29
  NewRelic::Agent.manual_start
29
30
  @engine = NewRelic::Agent.instance.stats_engine
30
-
31
- @cache = MEMCACHED_CLASS.new('localhost')
32
- @cache.flush_all
31
+
32
+ if MEMCACHED_CLASS.name == 'Memcached'
33
+ @cache = MEMCACHED_CLASS.new('localhost', :support_cas => true)
34
+ @cache.flush
35
+ else
36
+ @cache = MEMCACHED_CLASS.new('localhost')
37
+ @cache.flush_all
38
+ end
33
39
  @key = 'schluessel'
40
+ @cache.set('schluessel', 1)
34
41
  end
35
42
 
36
43
  def _call_test_method_in_web_transaction(method, *args)
@@ -58,7 +65,7 @@ class NewRelic::Agent::MemcacheInstrumentationTest < Test::Unit::TestCase
58
65
  end
59
66
 
60
67
  def test_writes__web
61
- %w[incr decr delete].each do |method|
68
+ %w[delete].each do |method|
62
69
  if @cache.class.method_defined?(method)
63
70
  _call_test_method_in_web_transaction(method)
64
71
  expected_metrics = ["MemCache/#{method}", "MemCache/allWeb", "MemCache/#{method}:Controller/NewRelic::Agent::MemcacheInstrumentationTest/action"]
@@ -67,6 +74,7 @@ class NewRelic::Agent::MemcacheInstrumentationTest < Test::Unit::TestCase
67
74
  end
68
75
 
69
76
  %w[set add].each do |method|
77
+ @cache.delete(@key) rescue nil
70
78
  if @cache.class.method_defined?(method)
71
79
  expected_metrics = ["MemCache/#{method}", "MemCache/allWeb", "MemCache/#{method}:Controller/NewRelic::Agent::MemcacheInstrumentationTest/action"]
72
80
  _call_test_method_in_web_transaction(method, 'value')
@@ -86,8 +94,7 @@ class NewRelic::Agent::MemcacheInstrumentationTest < Test::Unit::TestCase
86
94
  end
87
95
 
88
96
  def test_writes__background
89
-
90
- %w[incr decr delete].each do |method|
97
+ %w[delete].each do |method|
91
98
  expected_metrics = ["MemCache/#{method}", "MemCache/allOther", "MemCache/#{method}:OtherTransaction/Background/NewRelic::Agent::MemcacheInstrumentationTest/bg_task"]
92
99
  if @cache.class.method_defined?(method)
93
100
  _call_test_method_in_background_task(method)
@@ -96,6 +103,7 @@ class NewRelic::Agent::MemcacheInstrumentationTest < Test::Unit::TestCase
96
103
  end
97
104
 
98
105
  %w[set add].each do |method|
106
+ @cache.delete(@key) rescue nil
99
107
  expected_metrics = ["MemCache/#{method}", "MemCache/allOther", "MemCache/#{method}:OtherTransaction/Background/NewRelic::Agent::MemcacheInstrumentationTest/bg_task"]
100
108
  if @cache.class.method_defined?(method)
101
109
  _call_test_method_in_background_task(method, 'value')
@@ -104,4 +112,16 @@ class NewRelic::Agent::MemcacheInstrumentationTest < Test::Unit::TestCase
104
112
  end
105
113
  end
106
114
 
115
+ def test_handles_cas
116
+ expected_metrics = ["MemCache/cas", "MemCache/allOther", "MemCache/cas:OtherTransaction/Background/NewRelic::Agent::MemcacheInstrumentationTest/bg_task"]
117
+ if @cache.class.method_defined?(:cas)
118
+ @engine.clear_stats
119
+ perform_action_with_newrelic_trace(:name => 'bg_task', :category => :task) do
120
+ @cache.cas(@key) {|val| val += 2 }
121
+ end
122
+ compare_metrics expected_metrics, @engine.metrics.select{|m| m =~ /^memcache.*/i}
123
+ assert_equal 3, @cache.get(@key)
124
+ end
125
+ end
126
+
107
127
  end if memcached_ready
@@ -151,6 +151,13 @@ module NewRelic
151
151
  assert_equal(NewRelic::Agent.agent, NewRelic::Agent.instance, "should return the same agent for both identical methods")
152
152
  end
153
153
 
154
+ def test_load_data_should_not_write_files_when_serialization_disabled
155
+ NewRelic::Control.instance['disable_serialization'] = true
156
+ NewRelic::DataSerialization.expects(:read_and_write_to_file).never
157
+ NewRelic::Agent.load_data
158
+ NewRelic::Control.instance['disable_serialization'] = false
159
+ end
160
+
154
161
  private
155
162
 
156
163
  def mocked_agent
@@ -72,13 +72,7 @@ class NewRelic::CollectionHelperTest < Test::Unit::TestCase
72
72
  assert_equal Hash, myhash.class
73
73
  end
74
74
 
75
- class MyEnumerable
76
- include Enumerable
77
75
 
78
- def each
79
- yield "1"
80
- end
81
- end
82
76
 
83
77
  def test_enumerable
84
78
  e = MyEnumerable.new
@@ -101,45 +95,55 @@ class NewRelic::CollectionHelperTest < Test::Unit::TestCase
101
95
  s.each { | entry | val = entry; break }
102
96
  assert_match /^startfoo bar/, val
103
97
  end
104
-
98
+ class MyEnumerable
99
+ include Enumerable
100
+
101
+ def each
102
+ yield "1"
103
+ end
104
+ end
105
+
105
106
  def test_object
106
107
  assert_equal ["foo", '#<OpenStruct>'], normalize_params(['foo', OpenStruct.new('z'=>'q')])
107
108
  end
108
109
 
109
110
  def test_strip_backtrace
110
- begin
111
- ActiveRecordFixtures.setup
112
- # ActiveRecordFixtures::Order.add_delay
113
- ActiveRecordFixtures::Order.find 0
114
- flunk "should throw"
115
- rescue => e
116
- #puts e
117
- #puts e.backtrace.grep(/trace/).join("\n")
118
- #puts "\n\n"
119
- clean_trace = strip_nr_from_backtrace(e.backtrace)
120
- assert_equal(0, clean_trace.grep(/newrelic_rpm/).size,
121
- "should remove all instances of new relic from backtrace but got: #{clean_trace.join("\n")}")
122
- assert_equal(0, clean_trace.grep(/trace/).size,
123
- "should remove trace method tags from method names but got: #{clean_trace.join("\n")}")
124
- assert((clean_trace.grep(/find/).size >= 3),
125
- "should see at least three frames with 'find' in them (#{e}): \n#{clean_trace.join("\n")}")
126
- ensure
127
- ActiveRecordFixtures.teardown
128
- end
129
- end if defined?(::ActiveRecord)
111
+ clean_trace = strip_nr_from_backtrace(mock_backtrace)
112
+ assert_equal(0, clean_trace.grep(/newrelic_rpm/).size,
113
+ "should remove all instances of new relic from backtrace but got: #{clean_trace.join("\n")}")
114
+ assert_equal(0, clean_trace.grep(/trace/).size,
115
+ "should remove trace method tags from method names but got: #{clean_trace.join("\n")}")
116
+ assert((clean_trace.grep(/find/).size >= 3),
117
+ "should see at least three frames with 'find' in them: \n#{clean_trace.join("\n")}")
118
+ end
130
119
 
131
120
  def test_disabled_strip_backtrace
132
121
  NewRelic::Control.instance['disable_backtrace_cleanup'] = true
133
- begin
134
- flunk "should throw"
135
- rescue => e
136
- clean_trace = strip_nr_from_backtrace(e.backtrace)
137
- assert_equal(1, clean_trace.grep(/new_relic/).size,
122
+ clean_trace = strip_nr_from_backtrace(mock_backtrace)
123
+ assert_equal(1, clean_trace.grep(/new_relic/).size,
138
124
  "should not remove instances of new relic from backtrace but got: #{clean_trace.join("\n")}")
139
- assert_equal(1, clean_trace.grep(/trace/).size,
125
+ assert_equal(1, clean_trace.grep(/_trace/).size,
140
126
  "should not remove trace method tags from method names but got: #{clean_trace.join("\n")}")
141
- # assert (clean_trace.grep(/find/).size >= 3), "should see at least three frames with 'find' in them (#{e}): \n#{clean_trace.join("\n")}"
142
- end
127
+ # assert (clean_trace.grep(/find/).size >= 3), "should see at least three frames with 'find' in them (#{e}): \n#{clean_trace.join("\n")}"
143
128
  NewRelic::Control.instance['disable_backtrace_cleanup'] = false
144
129
  end
130
+
131
+ private
132
+ def mock_backtrace
133
+ [
134
+ %q{/home/app/gems/activerecord-2.3.12/lib/active_record/base.rb:1620:in `find_one_without_trace'},
135
+ %q{/home/app/gems/activerecord-2.3.12/lib/active_record/base.rb:1620:in `find_one'},
136
+ %q{/home/app/gems/activerecord-2.3.12/lib/active_record/base.rb:1603:in `find_from_ids'},
137
+ %q{./test/new_relic/collection_helper_test.rb:112:in `test_strip_stackdump'},
138
+ %q{/home/app/gems/mocha-0.9.8/lib/mocha/integration/test_unit/ruby_version_186_and_above.rb:19:in `__send__'},
139
+ %q{/home/app/gems/mocha-0.9.8/lib/mocha/integration/test_unit/ruby_version_186_and_above.rb:19:in `run'},
140
+ %q{/home/app/test/unit/testsuite.rb:34:in `run'},
141
+ %q{/home/app/test/unit/testsuite.rb:33:in `each'},
142
+ %q{/home/app/test/unit/testsuite.rb:33:in `run'},
143
+ %q{/home/app/test/unit/testsuite.rb:34:in `run'},
144
+ %q{/home/app/test/unit/testsuite.rb:33:in `each'},
145
+ %q{/home/app/test/unit/testsuite.rb:33:in `run'},
146
+ %q{/home/app/test/unit/ui/testrunnermediator.rb:46:in `run_suite'}
147
+ ]
148
+ end
145
149
  end
@@ -2,6 +2,18 @@ require File.expand_path(File.join(File.dirname(__FILE__),'/../../test_helper'))
2
2
  class NewRelic::Control::ConfigurationTest < Test::Unit::TestCase
3
3
  require 'new_relic/control/configuration'
4
4
  include NewRelic::Control::Configuration
5
+
6
+ def setup
7
+ # The log stuff is memoized so let's clear it each time.
8
+ NewRelic::Control.instance.instance_variable_set '@log_path', nil
9
+ NewRelic::Control.instance.instance_variable_set '@log_file', nil
10
+ @root = ::Rails::VERSION::MAJOR == 3 ? Rails.root : RAILS_ROOT
11
+ end
12
+
13
+ def teardown
14
+ NewRelic::Control.instance.settings.delete 'log_file_path'
15
+ end
16
+
5
17
  def test_license_key_defaults_to_env_variable
6
18
  ENV['NEWRELIC_LICENSE_KEY'] = nil
7
19
  self.expects(:fetch).with('license_key', nil)
@@ -12,14 +24,16 @@ class NewRelic::Control::ConfigurationTest < Test::Unit::TestCase
12
24
  license_key
13
25
  end
14
26
 
15
- def test_log_file_path_uses_default_if_not_set
16
- root = ::Rails::VERSION::MAJOR == 3 ? Rails.root : RAILS_ROOT
17
- assert_equal(File.join(root, 'log'),
18
- NewRelic::Control.instance.log_file_path)
27
+ def test_log_path_uses_default_if_not_set
28
+ NewRelic::Control.instance.setup_log
29
+ assert_equal(File.expand_path("log/newrelic_agent.log"),
30
+ NewRelic::Control.instance.log_file)
19
31
  end
20
32
 
21
33
  def test_log_file_path_uses_given_value
22
- NewRelic::Control.instance['log_file_path'] = '/lerg'
23
- assert_equal '/lerg', NewRelic::Control.instance.log_file_path
34
+ NewRelic::Control.instance['log_file_path'] = 'lerg'
35
+ NewRelic::Control.instance.setup_log
36
+ assert_equal("#{@root}/lerg/newrelic_agent.log",
37
+ NewRelic::Control.instance.log_file)
24
38
  end
25
39
  end
@@ -5,6 +5,7 @@ require 'fileutils'
5
5
  class BaseLoggingMethods
6
6
  # stub class to enable testing of the module
7
7
  include NewRelic::Control::LoggingMethods
8
+ def root; "."; end
8
9
  end
9
10
 
10
11
  class NewRelic::Control::LoggingMethodsTest < Test::Unit::TestCase
@@ -123,15 +124,15 @@ class NewRelic::Control::LoggingMethodsTest < Test::Unit::TestCase
123
124
 
124
125
  def test_log_path_path_exists
125
126
  @base.instance_eval { @log_path = nil }
126
- @base.expects(:fetch).with('log_file_path', 'log/').returns('log/')
127
- assert File.directory?('log/')
128
- assert_equal File.expand_path('log/'), @base.log_path
127
+ @base.expects(:fetch).with('log_file_path', 'log').returns('log')
128
+ assert File.directory?('log')
129
+ assert_equal File.expand_path('log'), @base.log_path
129
130
  end
130
131
 
131
132
  def test_log_path_path_created
132
133
  path = File.expand_path('tmp/log_path_test')
133
134
  @base.instance_eval { @log_path = nil }
134
- @base.expects(:fetch).with('log_file_path', 'log/').returns('tmp/log_path_test')
135
+ @base.expects(:fetch).with('log_file_path', 'log').returns('tmp/log_path_test')
135
136
  assert !File.directory?(path) || FileUtils.rmdir(path)
136
137
  @base.expects(:log!).never
137
138
  assert_equal path, @base.log_path
@@ -141,11 +142,11 @@ class NewRelic::Control::LoggingMethodsTest < Test::Unit::TestCase
141
142
  def test_log_path_path_unable_to_create
142
143
  path = File.expand_path('tmp/log_path_test')
143
144
  @base.instance_eval { @log_path = nil }
144
- @base.expects(:fetch).with('log_file_path', 'log/').returns('tmp/log_path_test')
145
+ @base.expects(:fetch).with('log_file_path', 'log').returns('tmp/log_path_test')
145
146
  assert !File.directory?(path) || FileUtils.rmdir(path)
146
- @base.expects(:log!).with("Error creating New Relic log directory '#{path}'", :error)
147
- Dir.expects(:mkdir).with(path).raises('cannot make directory bro!')
148
- assert_equal path, @base.log_path
147
+ @base.expects(:log!).with("Error creating log directory for New Relic log file: '#{path}'", :error)
148
+ Dir.expects(:mkdir).with(path).raises('cannot make directory bro!').at_least_once
149
+ assert_equal 'tmp/log_path_test', @base.log_path
149
150
  assert !File.directory?(path)
150
151
  end
151
152
 
@@ -1,15 +1,23 @@
1
1
  require File.expand_path(File.join(File.dirname(__FILE__),'..', 'test_helper'))
2
2
  require 'new_relic/data_serialization'
3
3
  class NewRelic::DataSerializationTest < Test::Unit::TestCase
4
+
5
+ attr_reader :file, :path
4
6
 
5
7
  def setup
6
8
  NewRelic::Control.instance['log_file_path'] = './log'
7
- FileUtils.rm_rf('./log/newrelic_agent_store.db')
8
- FileUtils.rm_rf('./log/newrelic_agent_store.age')
9
+ @path = NewRelic::Control.instance.log_path
10
+ @file = "#{path}/newrelic_agent_store.db"
11
+ Dir.mkdir(path) if !File.directory?(path)
12
+ FileUtils.rm_rf(@file)
13
+ FileUtils.rm_rf("#{@path}/newrelic_agent_store.age")
14
+ end
15
+
16
+ def teardown
17
+ NewRelic::Control.instance['disable_serialization'] = false # this gets set to true in some tests
9
18
  end
10
19
 
11
20
  def test_read_and_write_from_file_read_only
12
- file = './log/newrelic_agent_store.db'
13
21
  File.open(file, 'w') do |f|
14
22
  f.write(Marshal.dump('a happy string'))
15
23
  end
@@ -20,8 +28,16 @@ class NewRelic::DataSerializationTest < Test::Unit::TestCase
20
28
  assert_equal(0, File.size(file), "Should not leave any data in the file")
21
29
  end
22
30
 
31
+ def test_bad_paths
32
+ NewRelic::Control.instance.stubs(:log_path).returns("/bad/path")
33
+ assert NewRelic::DataSerialization.should_send_data?
34
+ NewRelic::DataSerialization.read_and_write_to_file do
35
+ 'a happy string'
36
+ end
37
+ assert !File.exists?(file)
38
+ end
39
+
23
40
  def test_read_and_write_to_file_dumping_contents
24
- file = './log/newrelic_agent_store.db'
25
41
  expected_contents = Marshal.dump('a happy string')
26
42
  NewRelic::DataSerialization.read_and_write_to_file do
27
43
  'a happy string'
@@ -30,7 +46,6 @@ class NewRelic::DataSerializationTest < Test::Unit::TestCase
30
46
  end
31
47
 
32
48
  def test_read_and_write_to_file_yields_old_data
33
- file = './log/newrelic_agent_store.db'
34
49
  expected_contents = 'a happy string'
35
50
  File.open(file, 'w') do |f|
36
51
  f.write(Marshal.dump(expected_contents))
@@ -54,8 +69,9 @@ class NewRelic::DataSerializationTest < Test::Unit::TestCase
54
69
  end
55
70
  end
56
71
 
57
- def test_should_send_data
58
- NewRelic::DataSerialization.expects(:max_size).returns(20)
72
+ def test_should_send_data_when_over_limit
73
+ # NewRelic::DataSerialization.expects(:max_size).returns(20)
74
+ NewRelic::DataSerialization.stubs(:max_size).returns(20)
59
75
  NewRelic::DataSerialization.read_and_write_to_file do
60
76
  "a" * 30
61
77
  end
@@ -63,7 +79,6 @@ class NewRelic::DataSerializationTest < Test::Unit::TestCase
63
79
  end
64
80
 
65
81
  def test_read_until_eoferror
66
- file = './log/newrelic_agent_store.db'
67
82
  File.open(file, 'w') do |f|
68
83
  f.write("a" * 10_001)
69
84
  end
@@ -75,7 +90,6 @@ class NewRelic::DataSerializationTest < Test::Unit::TestCase
75
90
  end
76
91
 
77
92
  def test_write_contents_nonblockingly
78
- file = './log/newrelic_agent_store.db'
79
93
  File.open(file, 'w') do |f|
80
94
  f.write("") # write nothing! NOTHING
81
95
  end
@@ -108,7 +122,8 @@ class NewRelic::DataSerializationTest < Test::Unit::TestCase
108
122
  end
109
123
 
110
124
  def test_spool_file_location_respects_log_file_path_setting
111
- NewRelic::Control.instance['log_file_path'] = "./tmp"
125
+ NewRelic::Control.instance.expects(:log_path).returns('./tmp')
126
+ Dir.mkdir('./tmp') if !File.directory?('./tmp')
112
127
  NewRelic::DataSerialization.read_and_write_to_file do |_|
113
128
  'a' * 30
114
129
  end
@@ -117,7 +132,8 @@ class NewRelic::DataSerializationTest < Test::Unit::TestCase
117
132
  end
118
133
 
119
134
  def test_age_file_location_respects_log_file_path_setting
120
- NewRelic::Control.instance['log_file_path'] = "./tmp"
135
+ NewRelic::Control.instance.expects(:log_path).returns('./tmp')
136
+ Dir.mkdir('./tmp') if !File.directory?('./tmp')
121
137
  NewRelic::DataSerialization.update_last_sent!
122
138
  assert(File.exists?('./tmp/newrelic_agent_store.age'),
123
139
  "Age file not created at user specified location")
metadata CHANGED
@@ -1,14 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: newrelic_rpm
3
3
  version: !ruby/object:Gem::Version
4
- hash: -1848230026
5
- prerelease: true
4
+ hash: 62196445
5
+ prerelease: 6
6
6
  segments:
7
7
  - 3
8
8
  - 1
9
9
  - 1
10
- - beta2
11
- version: 3.1.1.beta2
10
+ - beta
11
+ - 3
12
+ version: 3.1.1.beta3
12
13
  platform: ruby
13
14
  authors:
14
15
  - Bill Kayser
@@ -19,7 +20,7 @@ autorequire:
19
20
  bindir: bin
20
21
  cert_chain: []
21
22
 
22
- date: 2011-07-12 00:00:00 -07:00
23
+ date: 2011-07-13 00:00:00 -07:00
23
24
  default_executable:
24
25
  dependencies:
25
26
  - !ruby/object:Gem::Dependency
@@ -74,9 +75,9 @@ description: |
74
75
 
75
76
  email: support@newrelic.com
76
77
  executables:
77
- - mongrel_rpm
78
- - newrelic
79
78
  - newrelic_cmd
79
+ - newrelic
80
+ - mongrel_rpm
80
81
  extensions: []
81
82
 
82
83
  extra_rdoc_files:
@@ -189,6 +190,7 @@ files:
189
190
  - lib/tasks/all.rb
190
191
  - lib/tasks/install.rake
191
192
  - lib/tasks/tests.rake
193
+ - log/newrelic_agent.log
192
194
  - newrelic.yml
193
195
  - newrelic_rpm.gemspec
194
196
  - recipes/newrelic.rb
@@ -362,7 +364,6 @@ post_install_message: |
362
364
 
363
365
 
364
366
  rdoc_options:
365
- - --charset=UTF-8
366
367
  - --line-numbers
367
368
  - --inline-source
368
369
  - --title
@@ -390,7 +391,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
390
391
  requirements: []
391
392
 
392
393
  rubyforge_project:
393
- rubygems_version: 1.3.7
394
+ rubygems_version: 1.4.2
394
395
  signing_key:
395
396
  specification_version: 3
396
397
  summary: New Relic Ruby Agent