newrelic_rpm 2.14.1 → 3.0.0.beta1

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.

Files changed (123) hide show
  1. data/CHANGELOG +8 -0
  2. data/README.rdoc +2 -0
  3. data/install.rb +2 -2
  4. data/lib/new_relic/agent.rb +34 -1
  5. data/lib/new_relic/agent/agent.rb +34 -25
  6. data/lib/new_relic/agent/browser_monitoring.rb +111 -0
  7. data/lib/new_relic/agent/error_collector.rb +4 -4
  8. data/lib/new_relic/agent/instrumentation/acts_as_solr.rb +3 -3
  9. data/lib/new_relic/agent/instrumentation/controller_instrumentation.rb +5 -7
  10. data/lib/new_relic/agent/instrumentation/data_mapper.rb +8 -8
  11. data/lib/new_relic/agent/instrumentation/delayed_job_instrumentation.rb +1 -1
  12. data/lib/new_relic/agent/instrumentation/memcache.rb +1 -1
  13. data/lib/new_relic/agent/instrumentation/merb/controller.rb +1 -1
  14. data/lib/new_relic/agent/instrumentation/merb/errors.rb +1 -1
  15. data/lib/new_relic/agent/instrumentation/metric_frame.rb +1 -0
  16. data/lib/new_relic/agent/instrumentation/queue_time.rb +26 -26
  17. data/lib/new_relic/agent/instrumentation/rails/action_web_service.rb +1 -1
  18. data/lib/new_relic/agent/instrumentation/rails/errors.rb +1 -1
  19. data/lib/new_relic/agent/instrumentation/rails3/action_controller.rb +2 -2
  20. data/lib/new_relic/agent/instrumentation/sinatra.rb +1 -1
  21. data/lib/new_relic/agent/method_tracer.rb +15 -15
  22. data/lib/new_relic/agent/shim_agent.rb +2 -0
  23. data/lib/new_relic/agent/stats_engine/metric_stats.rb +3 -3
  24. data/lib/new_relic/agent/stats_engine/samplers.rb +2 -2
  25. data/lib/new_relic/agent/stats_engine/transactions.rb +2 -1
  26. data/lib/new_relic/agent/transaction_sample_builder.rb +101 -0
  27. data/lib/new_relic/agent/transaction_sampler.rb +299 -251
  28. data/lib/new_relic/control.rb +2 -2
  29. data/lib/new_relic/control/class_methods.rb +0 -5
  30. data/lib/new_relic/control/configuration.rb +4 -3
  31. data/lib/new_relic/control/frameworks/rails.rb +9 -12
  32. data/lib/new_relic/control/instance_methods.rb +2 -2
  33. data/lib/new_relic/control/instrumentation.rb +1 -1
  34. data/lib/new_relic/control/server_methods.rb +2 -2
  35. data/lib/new_relic/delayed_job_injection.rb +1 -1
  36. data/lib/new_relic/local_environment.rb +7 -7
  37. data/lib/new_relic/rack/browser_monitoring.rb +61 -0
  38. data/lib/new_relic/stats.rb +6 -6
  39. data/lib/new_relic/version.rb +4 -4
  40. data/newrelic.yml +19 -0
  41. data/newrelic_rpm.gemspec +9 -4
  42. data/test/active_record_fixtures.rb +5 -5
  43. data/test/config/test_control.rb +3 -3
  44. data/test/new_relic/agent/agent/connect_test.rb +27 -6
  45. data/test/new_relic/agent/agent/start_test.rb +13 -13
  46. data/test/new_relic/agent/agent/start_worker_thread_test.rb +8 -8
  47. data/test/new_relic/agent/agent_test.rb +85 -0
  48. data/test/new_relic/agent/agent_test_controller.rb +9 -9
  49. data/test/new_relic/agent/agent_test_controller_test.rb +37 -37
  50. data/test/new_relic/agent/browser_monitoring_test.rb +124 -0
  51. data/test/new_relic/agent/busy_calculator_test.rb +7 -7
  52. data/test/new_relic/agent/error_collector/notice_error_test.rb +9 -9
  53. data/test/new_relic/agent/error_collector_test.rb +54 -54
  54. data/test/new_relic/agent/instrumentation/active_record_instrumentation_test.rb +69 -69
  55. data/test/new_relic/agent/instrumentation/controller_instrumentation_test.rb +36 -0
  56. data/test/new_relic/agent/instrumentation/metric_frame_test.rb +3 -3
  57. data/test/new_relic/agent/instrumentation/net_instrumentation_test.rb +11 -11
  58. data/test/new_relic/agent/instrumentation/queue_time_test.rb +38 -35
  59. data/test/new_relic/agent/instrumentation/task_instrumentation_test.rb +18 -18
  60. data/test/new_relic/agent/memcache_instrumentation_test.rb +12 -12
  61. data/test/new_relic/agent/method_tracer/class_methods/add_method_tracer_test.rb +1 -1
  62. data/test/new_relic/agent/method_tracer/instance_methods/trace_execution_scoped_test.rb +16 -15
  63. data/test/new_relic/agent/method_tracer_test.rb +60 -60
  64. data/test/new_relic/agent/mock_scope_listener.rb +8 -8
  65. data/test/new_relic/agent/rpm_agent_test.rb +26 -26
  66. data/test/new_relic/agent/stats_engine/metric_stats_test.rb +17 -17
  67. data/test/new_relic/agent/stats_engine/samplers_test.rb +4 -4
  68. data/test/new_relic/agent/stats_engine/stats_engine_test.rb +51 -51
  69. data/test/new_relic/agent/transaction_sample_builder_test.rb +36 -36
  70. data/test/new_relic/agent/transaction_sampler_test.rb +727 -178
  71. data/test/new_relic/agent/worker_loop_test.rb +4 -4
  72. data/test/new_relic/collection_helper_test.rb +15 -15
  73. data/test/new_relic/command/deployments_test.rb +5 -5
  74. data/test/new_relic/control_test.rb +25 -25
  75. data/test/new_relic/local_environment_test.rb +11 -11
  76. data/test/new_relic/metric_spec_test.rb +21 -21
  77. data/test/new_relic/rack/episodes_test.rb +35 -35
  78. data/test/new_relic/stats_test.rb +61 -43
  79. data/test/new_relic/transaction_sample_subtest_test.rb +15 -15
  80. data/test/new_relic/transaction_sample_test.rb +25 -25
  81. data/test/new_relic/version_number_test.rb +11 -11
  82. data/test/test_contexts.rb +7 -7
  83. data/test/test_helper.rb +6 -6
  84. data/ui/helpers/developer_mode_helper.rb +67 -67
  85. data/ui/helpers/google_pie_chart.rb +4 -4
  86. data/vendor/gems/dependency_detection-0.0.1.build/lib/dependency_detection.rb +4 -4
  87. data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/action_mailer.rb +3 -3
  88. data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/active_merchant.rb +7 -7
  89. data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/active_record.rb +1 -1
  90. data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/apdex.rb +9 -9
  91. data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/background_transaction.rb +1 -1
  92. data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/client.rb +8 -8
  93. data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/controller.rb +9 -9
  94. data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/controller_cpu.rb +4 -4
  95. data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/controller_ext.rb +2 -2
  96. data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/database.rb +8 -8
  97. data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/database_pool.rb +3 -3
  98. data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/dot_net.rb +6 -6
  99. data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/dot_net_parser.rb +3 -3
  100. data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/external.rb +2 -2
  101. data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/frontend.rb +6 -6
  102. data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/gc.rb +2 -2
  103. data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/hibernate_session.rb +1 -1
  104. data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/java.rb +4 -4
  105. data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/java_parser.rb +3 -3
  106. data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/jsp.rb +4 -4
  107. data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/jsp_tag.rb +1 -1
  108. data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/mem_cache.rb +1 -1
  109. data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/metric_parser.rb +21 -21
  110. data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/orm.rb +2 -2
  111. data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/other_transaction.rb +6 -6
  112. data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/servlet.rb +2 -2
  113. data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/servlet_context_listener.rb +1 -1
  114. data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/servlet_filter.rb +1 -1
  115. data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/solr.rb +3 -3
  116. data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/solr_request_handler.rb +1 -1
  117. data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/spring.rb +8 -8
  118. data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/struts_action.rb +3 -3
  119. data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/struts_result.rb +3 -3
  120. data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/view.rb +5 -5
  121. data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/web_transaction.rb +20 -20
  122. metadata +15 -9
  123. data/lib/new_relic/agent/instrumentation/sequel.rb +0 -109
@@ -4,10 +4,10 @@ require File.expand_path(File.join(File.dirname(__FILE__),'..', '..', 'test_help
4
4
  require 'rack'
5
5
 
6
6
  class EpisodesTest < Test::Unit::TestCase
7
-
7
+
8
8
  def setup
9
9
  super
10
-
10
+
11
11
  @app = Mocha::Mockery.instance.named_mock 'Episodes'
12
12
  #@app = mock('Episodes')
13
13
  @e = NewRelic::Rack::Episodes.new(@app)
@@ -17,20 +17,20 @@ class EpisodesTest < Test::Unit::TestCase
17
17
  @agent.transaction_sampler.reset!
18
18
  @agent.stats_engine.clear_stats
19
19
  end
20
-
20
+
21
21
  def test_match
22
22
  @e.expects(:process).times(3)
23
23
  @app.expects(:call).times(2)
24
- @e.call(mock_env('/newrelic/episodes/page_load/stuff'))
24
+ @e.call(mock_env('/newrelic/episodes/page_load/stuff'))
25
25
  @e.call(mock_env('/newrelic/episodes/page_load'))
26
26
  @e.call(mock_env('/newrelic/episodes/page_load?'))
27
-
27
+
28
28
  @e.call(mock_env('/v2/newrelic/episodes/page_load?'))
29
29
  @e.call(mock_env('/v2'))
30
30
  end
31
-
31
+
32
32
  def test_process
33
-
33
+
34
34
  args = "ets=backend:2807,onload:7641,frontend:4835,pageready:7642,totaltime:7642&" +
35
35
  "url=/bogosity/bogus_action&"+
36
36
  "userAgent=#{Rack::Utils.escape("Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.6; en-US; rv:1.9.2.2) Gecko/20100316 Firefox/3.6.2")}"
@@ -49,7 +49,7 @@ class EpisodesTest < Test::Unit::TestCase
49
49
  Client/frontend/Mac/Firefox/3.6
50
50
  Client/backend/Mac/Firefox/3.6
51
51
  Client/onload/Mac/Firefox/3.6
52
- Client/pageready/Mac/Firefox/3.6], @agent.stats_engine.metrics
52
+ Client/pageready/Mac/Firefox/3.6], @agent.stats_engine.metrics
53
53
  totaltime = @agent.stats_engine.get_stats_no_scope('Client/totaltime')
54
54
  assert_equal 1, totaltime.call_count
55
55
  assert_equal 7.642, totaltime.average_call_time
@@ -57,38 +57,38 @@ class EpisodesTest < Test::Unit::TestCase
57
57
  assert_equal 1, totaltime.call_count
58
58
  assert_equal 7.642, totaltime.average_call_time
59
59
  end
60
-
60
+
61
61
  context "when normalizing user agent strings" do
62
62
  setup do
63
63
  setup
64
64
  @e.class.send :public, :identify_browser_and_os
65
65
  end
66
-
66
+
67
67
  should "parse 'like Firefox/* Gecko/*' as Gecko" do
68
68
  browser, version, os = @e.identify_browser_and_os("Mozilla/5.0 (Macintosh; U; PPC; en-US; rv:1.0rc2) Gecko/20020512 like Firefox/3.1")
69
-
69
+
70
70
  assert_equal "Mozilla Gecko", browser
71
71
  assert_equal 1.0, version
72
72
  end
73
-
73
+
74
74
  should "parse 'Chrome/' as Chrome, unknown version" do
75
75
  browser, version, os = @e.identify_browser_and_os("Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_5_6; en-US) AppleWebKit/530.5 (KHTML, like Gecko) Chrome/ Safari/530.5")
76
-
76
+
77
77
  assert_equal "Chrome", browser
78
78
  assert_equal 0, version
79
79
  end
80
-
80
+
81
81
  should "parse x.y float versions for Firefox, Gecko and Webkit" do
82
82
  browser, version, os = @e.identify_browser_and_os("Mozilla/5.0 (Windows; U; Windows NT 6.0; ru; rv:1.9.2) Gecko/20100105 Firefox/3.6")
83
83
  assert Float === version
84
-
84
+
85
85
  browser, version, os = @e.identify_browser_and_os("Mozilla/5.0 (Macintosh; U; PPC; en-US; rv:1.0rc2) Gecko/20020512 Netscape/7.0b1")
86
86
  assert Float === version
87
-
87
+
88
88
  browser, version, os = @e.identify_browser_and_os("Mozilla/5.0 (Macintosh; U; PPC Mac OS X 10_5_2; en-gb) AppleWebKit/526+ (KHTML, like Gecko) Version/3.1 iPhone")
89
89
  assert Float === version
90
90
  end
91
-
91
+
92
92
  context "in-the-wild" do
93
93
  should "identify AOL correctly" do
94
94
  assert_equal ["IE", 5, "Windows"], @e.identify_browser_and_os("Mozilla/4.0 (compatible; MSIE 5.5; AOL 6.0; Windows 98)"), "AOL 6.0 identified incorrectly"
@@ -99,7 +99,7 @@ class EpisodesTest < Test::Unit::TestCase
99
99
  assert_equal ["IE", 7, "Windows"], @e.identify_browser_and_os("Mozilla/4.0 (compatible; MSIE 7.0; AOL 8.0; Windows NT 5.1; GTB5; .NET CLR 1.1.4322; .NET CLR 2.0.50727)"), "AOL 8.0 identified incorrectly"
100
100
  assert_equal ["IE", 8, "Windows"], @e.identify_browser_and_os("Mozilla/4.0 (compatible; MSIE 8.0; AOL 9.5; AOLBuild 4337.29; Windows NT 6.0; Trident/4.0; SLCC1; .NET CLR 2.0.50727; Media Center PC 5.0; .NET CLR 3.5.21022; .NET CLR 3.5.30729; .NET CLR 3.0.30618)"), "AOL 9.5 identified incorrectly"
101
101
  end
102
-
102
+
103
103
  should "identify Camino correctly" do
104
104
  assert_equal ["Mozilla Gecko", 1.8, "Mac"], @e.identify_browser_and_os("Mozilla/5.0 (Macintosh; U; Intel Mac OS X; en-US; rv:1.8.0.1) Gecko/20060214 Camino/1.0"), "Camino 1.0 identified incorrectly"
105
105
  assert_equal ["Mozilla Gecko", 1.8, "Mac"], @e.identify_browser_and_os("Mozilla/5.0 (Macintosh; U; PPC Mac OS X Mach-O; en-US; rv:1.8.0.1) Gecko/20060119 Camino/1.0b2+"), "Camino 1.0b2+ identified incorrectly"
@@ -107,7 +107,7 @@ class EpisodesTest < Test::Unit::TestCase
107
107
  assert_equal ["Mozilla Gecko", 1.9, "Mac"], @e.identify_browser_and_os("Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.6; en; rv:1.9.0.18) Gecko/2010021619 Camino/2.0.2 (like Firefox/3.0.18)"), "Camino 2.0.2 identified incorrectly"
108
108
  assert_equal ["Mozilla Gecko", 1.9, "Mac"], @e.identify_browser_and_os("Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.5; en; rv:1.9.0.10pre) Gecko/2009041800 Camino/2.0b3pre (like Firefox/3.0.10pre)"), "Camino 2.0b3pre identified incorrectly"
109
109
  end
110
-
110
+
111
111
  should "identify Chrome correctly" do
112
112
  assert_equal ["Chrome", 0, "Mac"], @e.identify_browser_and_os("Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_5_6; en-US) AppleWebKit/530.5 (KHTML, like Gecko) Chrome/ Safari/530.5"), "Chrome identified incorrectly"
113
113
  assert_equal ["Chrome", 1, "Windows"], @e.identify_browser_and_os("Mozilla/5.0 (Windows; U; Windows NT 5.2; en-US) AppleWebKit/525.19 (KHTML, like Gecko) Chrome/1.0.154.59 Safari/525.19"), "Chrome 1.0.154.59 identified incorrectly"
@@ -126,7 +126,7 @@ class EpisodesTest < Test::Unit::TestCase
126
126
  assert_equal ["Chrome", 5, "Linux"], @e.identify_browser_and_os("Mozilla/5.0 (X11; U; Linux x86_64; en-US) AppleWebKit/532.9 (KHTML, like Gecko) Chrome/5.0.309.0 Safari/532.9"), "Chrome 5.0.309.0 identified incorrectly"
127
127
  assert_equal ["Chrome", 6, "Windows"], @e.identify_browser_and_os("Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US) AppleWebKit/533.2 (KHTML, like Gecko) Chrome/6.0"), "Chrome 6.0 identified incorrectly"
128
128
  end
129
-
129
+
130
130
  should "identify Fennec correctly" do # Mozilla mobile browser
131
131
  assert_equal ["Mozilla Gecko", 1.9, "Linux"], @e.identify_browser_and_os("Mozilla/5.0 (X11; U; Linux armv6l; en-US; rv:1.9.1a1pre) Gecko/2008071707 Fennec/0.5"), "Fennec 0.5 identified incorrectly"
132
132
  assert_equal ["Mozilla Gecko", 1.9, "Linux"], @e.identify_browser_and_os("Mozilla/5.0 (X11; U; Linux armv6l; en-US; rv:1.9.1a2pre) Gecko/20080820121708 Fennec/0.7"), "Fennec 0.7 identified incorrectly"
@@ -136,7 +136,7 @@ class EpisodesTest < Test::Unit::TestCase
136
136
  assert_equal ["Mozilla Gecko", 1.9, "Linux"], @e.identify_browser_and_os("Mozilla/5.0 (X11; U; Linux armv7l; en-US; rv:1.9.2a1pre) Gecko/20090322 Fennec/1.0b2pre"), "Fennec 1.0b2pre identified incorrectly"
137
137
  assert_equal ["Mozilla Gecko", 1.8, "Windows"], @e.identify_browser_and_os("Mozilla/5.0 (Windows; U; Win98; en-US; rv:1.8.1.17) Gecko/20080829 Mozilla/5.0 (X11; U; Linux armv7l; en-US; rv:1.9.2a1pre) Gecko/20090322 Fennec/1.0b2pre"), "Fennec 1.0b2pre identified incorrectly"
138
138
  end
139
-
139
+
140
140
  should "identify Firefox correctly" do
141
141
  assert_equal ["Firefox", 1.0, "Windows"], @e.identify_browser_and_os("Mozilla/5.0 (Windows; U; Windows NT 5.2; de-DE; rv:1.7.6) Gecko/20050321 Firefox/1.0.2"), "Firefox 1.0.2 identified incorrectly"
142
142
  assert_equal ["Firefox", 1.5, "Linux"], @e.identify_browser_and_os("Mozilla/5.0 (X11; U; Linux i686; lt-LT; rv:1.6) Gecko/20051114 Firefox/1.5"), "Firefox 1.5 identified incorrectly"
@@ -153,24 +153,24 @@ class EpisodesTest < Test::Unit::TestCase
153
153
  assert_equal ["Firefox", 3.6, "Windows"], @e.identify_browser_and_os("Mozilla/5.0 (Windows; U; Windows NT 6.0; ru; rv:1.9.2) Gecko/20100105 Firefox/3.6 (.NET CLR 3.5.30729)"), "Firefox 3.6 identified incorrectly"
154
154
  assert_equal ["Firefox", 3.6, "Mac"], @e.identify_browser_and_os("Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.6; en-US; rv:1.9.2.2) Gecko/20100316 Firefox/3.6.2"), "Firefox 3.6.2 identified incorrectly"
155
155
  end
156
-
156
+
157
157
  should "identify Flock correctly" do
158
158
  assert_equal ["Firefox", 2.0, "Windows"], @e.identify_browser_and_os("Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.17) Gecko/20080910 Firefox/2.0.0.17 Flock/1.2.6"), "Flock 1.2.6 identified incorrectly"
159
159
  assert_equal ["Firefox", 3.0, "Mac"], @e.identify_browser_and_os("Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.5; en-US; rv:1.9.0.3) Gecko/2008100716 Firefox/3.0.3 Flock/2.0"), "Flock 2.0 identified incorrectly"
160
160
  assert_equal ["Firefox", 3.0, "Windows"], @e.identify_browser_and_os("Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.0.3) Gecko/2008100719 Firefox/3.0.3 Flock/2.0"), "Flock 2.0 identified incorrectly"
161
161
  assert_equal ["Safari", 0, "Windows"], @e.identify_browser_and_os("Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.1.7) Gecko/20091221 AppleWebKit/531.21.8 KHTML/4.3.2 (like Gecko) Firefox/3.5.7 Flock/2.5.6 (.NET CLR 3.5.30729)"), "Flock 2.5.6 identified incorrectly"
162
162
  end
163
-
163
+
164
164
  should "identify Fluid correctly" do # Safari-based single-site browser
165
165
  assert_equal ["Safari", 0, "Mac"], @e.identify_browser_and_os("Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_6_1; nl-nl) AppleWebKit/532.3+ (KHTML, like Gecko) Fluid/0.9.6 Safari/532.3+"), "Fluid 0.9.6 identified incorrectly"
166
166
  end
167
-
167
+
168
168
  should "identify Iceweasel correctly" do # Debian's Firefox
169
169
  assert_equal ["Firefox", 1.5, "Linux"], @e.identify_browser_and_os("Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.8.0.8pre) Gecko/20061001 Firefox/1.5.0.8pre (Iceweasel)"), "Iceweasel identified incorrectly"
170
170
  assert_equal ["Firefox", 3.0, "Linux"], @e.identify_browser_and_os("Mozilla/5.0 (X11; U; Linux i686; en-GB; rv:1.9.0.7) Gecko/2009030814 Iceweasel Firefox/3.0.7 (Debian-3.0.7-1)"), "Iceweasel identified incorrectly"
171
171
  assert_equal ["Firefox", 2.0, "Linux"], @e.identify_browser_and_os("Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.8.1.13) Gecko/20080311 Firefox/2.0 Iceweasel/2.0.0.3 (Debian-2.0.0.13-1)"), "Iceweasel 2.0.0.3 identified incorrectly"
172
172
  end
173
-
173
+
174
174
  should "identify IE correctly" do
175
175
  assert_equal ["IE", 3, "Windows"], @e.identify_browser_and_os("Mozilla/3.0 (compatible; MSIE 3.0; Windows NT 5.0)"), "Internet Explorer 3.0 identified incorrectly"
176
176
  assert_equal ["IE", 4, "Windows"], @e.identify_browser_and_os("Mozilla/2.0 (compatible; MSIE 4.0; Windows 98)"), "Internet Explorer 4.0 identified incorrectly"
@@ -189,7 +189,7 @@ class EpisodesTest < Test::Unit::TestCase
189
189
  assert_equal ["IE", 8, "Windows"], @e.identify_browser_and_os("Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; WOW64; Trident/4.0; SLCC2; Media Center PC 6.0; InfoPath.2; MS-RTC LM 8)"), "Internet Explorer 8.0 identified incorrectly"
190
190
  assert_equal ["IE", 8, "Windows"], @e.identify_browser_and_os("Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.2; Trident/4.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0)"), "Internet Explorer 8.0 identified incorrectly"
191
191
  end
192
-
192
+
193
193
  should "identify Mozilla correctly" do
194
194
  assert_equal ["Mozilla Gecko", 1.4, "Linux"], @e.identify_browser_and_os("Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.4) Gecko/20030908 Debian/1.4-4"), "Mozilla 1.4 identified incorrectly"
195
195
  assert_equal ["Mozilla Gecko", 1.4, "Windows"], @e.identify_browser_and_os("Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.4) Gecko/20030624"), "Mozilla 1.4 identified incorrectly"
@@ -199,17 +199,17 @@ class EpisodesTest < Test::Unit::TestCase
199
199
  assert_equal ["Mozilla Gecko", 1.6, "Mac"], @e.identify_browser_and_os("Mozilla/5.0 (Macintosh; U; PPC Mac OS X Mach-O; en-US; rv:1.6) Gecko/20040113"), "Mozilla 1.6 identified incorrectly"
200
200
  assert_equal ["Mozilla Gecko", 1.6, "Windows"], @e.identify_browser_and_os("Mozilla/5.0 (Windows; U; Windows NT 5.0; de-AT; rv:1.6) Gecko/20040113"), "Mozilla 1.6 identified incorrectly"
201
201
  assert_equal ["Mozilla Gecko", 1.6, "Windows"], @e.identify_browser_and_os("Mozilla/5.0 (Windows; U; Windows NT 5.1; fr-FR; rv:1.6) Gecko/20040113"), "Mozilla 1.6 identified incorrectly"
202
-
202
+
203
203
  # no way to tell that this string isn't Firefox, so let's lump it into Firefox
204
204
  assert_equal ["Firefox", 0.9, "Windows"], @e.identify_browser_and_os("Mozilla/5.0 (Windows; U; Windows NT 5.1; es-ES; rv:1.7) Gecko/20040803 Firefox/0.9.3"), "Mozilla 1.7 identified incorrectly"
205
-
205
+
206
206
  assert_equal ["Mozilla Gecko", 1.7, "Linux"], @e.identify_browser_and_os("Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.7) Gecko/20040514"), "Mozilla 1.7 identified incorrectly"
207
207
  assert_equal ["Mozilla Gecko", 1.7, "Windows"], @e.identify_browser_and_os("Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.7) Gecko/20040616"), "Mozilla 1.7 identified incorrectly"
208
208
  assert_equal ["Mozilla Gecko", 1.8, "Windows"], @e.identify_browser_and_os("Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.0.5) Gecko/20060719 KHTML/3.5.5"), "Mozilla 1.8.0.5 identified incorrectly"
209
209
  assert_equal ["Mozilla Gecko", 1.8, "Mac"], @e.identify_browser_and_os("Mozilla/5.0 (Macintosh; U; Intel Mac OS X; en-US; rv:1.8.1.11) Gecko/20071206"), "Mozilla 1.8.1.11 identified incorrectly"
210
210
  assert_equal ["Mozilla Gecko", 1.8, "Linux"], @e.identify_browser_and_os("Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.8.1.13) Gecko/20080313"), "Mozilla 1.8.1.13 identified incorrectly"
211
211
  assert_equal ["Mozilla Gecko", 1.9, "Windows"], @e.identify_browser_and_os("Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.9.2a1pre) Gecko"), "Mozilla 1.9.2a1pre identified incorrectly"
212
-
212
+
213
213
  assert_equal ["Mozilla Gecko", 0.9, "Linux"], @e.identify_browser_and_os(" Mozilla/5.0 (X11; U; Linux i686; en-US; rv:0.9.2) Gecko/20010726 Netscape6/6.1"), "Netscape 6.1 identified incorrectly"
214
214
  assert_equal ["Mozilla Gecko", 0.9, "Mac"], @e.identify_browser_and_os(" Mozilla/5.0 (Macintosh; U; PPC; de-DE; rv:0.9.2) Gecko/20010726 Netscape6/6.1"), "Netscape 6.1 identified incorrectly"
215
215
  assert_equal ["Mozilla Gecko", 0.9, "Windows"], @e.identify_browser_and_os("Mozilla/5.0 (Windows; U; Windows NT 5.1; fr-FR; rv:0.9.2) Gecko/20010726 Netscape6/6.1"), "Netscape 6.1 identified incorrectly"
@@ -217,17 +217,17 @@ class EpisodesTest < Test::Unit::TestCase
217
217
  assert_equal ["Mozilla Gecko", 1.0, "Linux"], @e.identify_browser_and_os("Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.0rc2) Gecko/20020513 Netscape/7.0b1"), "Netscape 7.0b1 identified incorrectly"
218
218
  assert_equal ["Mozilla Gecko", 1.0, "Mac"], @e.identify_browser_and_os("Mozilla/5.0 (Macintosh; U; PPC; en-US; rv:1.0rc2) Gecko/20020512 Netscape/7.0b1"), "Netscape 7.0b1 identified incorrectly"
219
219
  assert_equal ["Mozilla Gecko", 1.7, "Windows"], @e.identify_browser_and_os("Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.7.5) Gecko/20060111 Netscape/8.1"), "Netscape 8.1 identified incorrectly"
220
-
220
+
221
221
  # no way to tell that these aren't Firefox
222
222
  assert_equal ["Firefox", 2.0, "Linux"], @e.identify_browser_and_os("Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.8.1.8pre) Gecko/20071015 Firefox/2.0.0.7 Navigator/9.0"), "Netscape 9.0 identified incorrectly"
223
223
  assert_equal ["Firefox", 2.0, "Mac"], @e.identify_browser_and_os("Mozilla/5.0 (Macintosh; U; PPC Mac OS X Mach-O; en-US; rv:1.8.1.8pre) Gecko/20071015 Firefox/2.0.0.7 Navigator/9.0"), "Netscape 9.0 identified incorrectly"
224
224
  assert_equal ["Firefox", 2.0, "Windows"], @e.identify_browser_and_os("Mozilla/5.0 (Windows; U; Win 9x 4.90; en-US; rv:1.8.1.8pre) Gecko/20071015 Firefox/2.0.0.7 Navigator/9.0"), "Netscape 9.0 identified incorrectly"
225
225
  end
226
-
226
+
227
227
  should "identify OmniWeb correctly" do
228
228
  assert_equal ["Safari", 0, "Mac"], @e.identify_browser_and_os("Mozilla/5.0 (Macintosh; U; PPC Mac OS X; en-US) AppleWebKit/125.4 (KHTML, like Gecko, Safari) OmniWeb/v563.59"), "OmniWeb v563.59 identified incorrectly"
229
229
  end
230
-
230
+
231
231
  should "identify Opera correctly" do
232
232
  assert_equal ["Opera", 0, "Windows"], @e.identify_browser_and_os("Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; en) Opera"), "Opera identified incorrectly"
233
233
  assert_equal ["Opera", 0, "Mac"], @e.identify_browser_and_os("Mozilla/5.0 (Macintosh; ; Intel Mac OS X; fr; rv:1.8.1.1) Gecko/20061204 Opera"), "Opera identified incorrectly"
@@ -246,7 +246,7 @@ class EpisodesTest < Test::Unit::TestCase
246
246
  assert_equal ["Opera", 10, "Linux"], @e.identify_browser_and_os("Opera/9.80 (X11; Linux x86_64; U; en) Presto/2.2.15 Version/10.00"), "Opera 10.00 identified incorrectly"
247
247
  assert_equal ["Opera", 10, "Windows"], @e.identify_browser_and_os("Opera/9.80 (Windows NT 5.1; U; ru) Presto/2.2.15 Version/10.00"), "Opera 10.00 identified incorrectly"
248
248
  end
249
-
249
+
250
250
  should "identify Safari correctly" do
251
251
  assert_equal ["Safari", 0, "iPhone"], @e.identify_browser_and_os("Mozilla/5.0 (iPod; U; CPU iPhone OS 2_2_1 like Mac OS X; en-us) AppleWebKit/525.18.1 (KHTML, like Gecko) Mobile/5H11"), "Safari identified incorrectly"
252
252
  assert_equal ["Safari", 0, "Mac"], @e.identify_browser_and_os("Mozilla/5.0 (Macintosh; U; PPC Mac OS X; en) AppleWebKit/125.2 (KHTML, like Gecko) Safari/125.7"), "Safari 1.2.2 identified incorrectly"
@@ -262,7 +262,7 @@ class EpisodesTest < Test::Unit::TestCase
262
262
  assert_equal ["Safari", 4.0, "Mac"], @e.identify_browser_and_os("Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_6_3; en-us) AppleWebKit/531.22.7 (KHTML, like Gecko) Version/4.0.5 Safari/531.22.7"), "Safari 4.0.5 identified incorrectly"
263
263
  assert_equal ["Safari", 4.0, "Windows"], @e.identify_browser_and_os("Mozilla/5.0 (Windows; U; Windows NT 6.0; en-US) AppleWebKit/531.22.7 (KHTML, like Gecko) Version/4.0.5 Safari/531.22.7"), "Safari 4.0.5 identified incorrectly"
264
264
  end
265
-
265
+
266
266
  should "identify SeaMonkey correctly" do # Mozilla distribution of core Gecko engine
267
267
  assert_equal ["Mozilla Gecko", 1.8, "Linux"], @e.identify_browser_and_os("Mozilla/5.0 (X11; U; Linux i686; de-AT; rv:1.8.1.5) Gecko/20070716 SeaMonkey/1.1.3"), "SeaMonkey 1.1.3 identified incorrectly"
268
268
  assert_equal ["Mozilla Gecko", 1.8, "Windows"], @e.identify_browser_and_os("Mozilla/5.0 (Windows; U; Windows NT 5.1; es-ES; rv:1.8.1.5) Gecko/20070716 SeaMonkey/1.1.3"), "SeaMonkey 1.1.3 identified incorrectly"
@@ -277,7 +277,7 @@ private
277
277
 
278
278
  def mock_env(uri_override)
279
279
  path, query = uri_override.split('?')
280
-
280
+
281
281
  Hash[
282
282
  'HTTP_ACCEPT' => 'application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5',
283
283
  'HTTP_ACCEPT_ENCODING' => 'gzip, deflate',
@@ -13,6 +13,24 @@ end; end
13
13
 
14
14
 
15
15
  class NewRelic::StatsTest < Test::Unit::TestCase
16
+
17
+ def test_checked_calculation_standard
18
+ obj = NewRelic::TestObjectForStats.new
19
+
20
+ assert_equal(1.0, obj.checked_calculation(1, 1))
21
+
22
+ end
23
+
24
+ def test_checked_calculation_with_zero
25
+ obj = NewRelic::TestObjectForStats.new
26
+ assert_equal(0.0, obj.checked_calculation(1, 0))
27
+ end
28
+
29
+ def test_checked_calculation_should_return_floats
30
+ obj = NewRelic::TestObjectForStats.new
31
+ assert_equal(0.5, obj.checked_calculation(1, 2))
32
+ end
33
+
16
34
  def test_sum_attributes
17
35
  first = NewRelic::TestObjectForStats.new
18
36
  second = mock('other object')
@@ -54,7 +72,7 @@ class NewRelic::StatsTest < Test::Unit::TestCase
54
72
  def test_should_replace_end_time
55
73
  first = NewRelic::TestObjectForStats.new
56
74
  second = mock('other object')
57
-
75
+
58
76
  first.expects(:end_time).returns(Time.at(1))
59
77
  second.expects(:end_time).returns(Time.at(2))
60
78
  assert first.should_replace_end_time?(second), 'should replace end time when the other stat is larger'
@@ -84,8 +102,8 @@ class NewRelic::StatsTest < Test::Unit::TestCase
84
102
 
85
103
  def test_update_totals
86
104
  first = NewRelic::TestObjectForStats.new
87
- second = mock('other object')
88
-
105
+ second = mock('other object')
106
+
89
107
  [:total_call_time, :total_exclusive_time, :sum_of_squares].each do |method|
90
108
  mock_plusequals(first, second, method, 2.0, 3.0)
91
109
  end
@@ -95,19 +113,19 @@ class NewRelic::StatsTest < Test::Unit::TestCase
95
113
 
96
114
  def test_min_time_less
97
115
  first = NewRelic::TestObjectForStats.new
98
- second = mock('other object')
99
-
116
+ second = mock('other object')
117
+
100
118
  second.expects(:min_call_time).returns(1.0)
101
119
  first.expects(:min_call_time).returns(2.0)
102
120
  second.expects(:call_count).returns(1)
103
-
121
+
104
122
  first.min_time_less?(second)
105
123
  end
106
124
 
107
125
  def test_expand_min_max_to
108
126
  first = NewRelic::TestObjectForStats.new
109
- second = mock('other object')
110
-
127
+ second = mock('other object')
128
+
111
129
  first.expects(:min_time_less?).with(second).returns(true)
112
130
  first.expects(:max_call_time).returns(3.0)
113
131
 
@@ -119,18 +137,18 @@ class NewRelic::StatsTest < Test::Unit::TestCase
119
137
 
120
138
  first.expand_min_max_to(second)
121
139
  end
122
-
123
-
124
-
140
+
141
+
142
+
125
143
  def test_simple
126
- stats = NewRelic::MethodTraceStats.new
144
+ stats = NewRelic::MethodTraceStats.new
127
145
  validate stats, 0, 0, 0, 0
128
-
146
+
129
147
  assert_equal stats.call_count,0
130
148
  stats.trace_call 10
131
149
  stats.trace_call 20
132
150
  stats.trace_call 30
133
-
151
+
134
152
  validate stats, 3, (10+20+30), 10, 30
135
153
  end
136
154
 
@@ -143,13 +161,13 @@ class NewRelic::StatsTest < Test::Unit::TestCase
143
161
  def test_time_str
144
162
  s1 = NewRelic::MethodTraceStats.new
145
163
  assert_equal(s1.time_str(10), "10 ms")
146
- assert_equal(s1.time_str(4999), "4999 ms")
164
+ assert_equal(s1.time_str(4999), "4999 ms")
147
165
  assert_equal(s1.time_str(5000), "5.00 s")
148
166
  assert_equal(s1.time_str(5010), "5.01 s")
149
167
  assert_equal(s1.time_str(9999), "10.00 s")
150
168
  assert_equal(s1.time_str(10000), "10.0 s")
151
169
  assert_equal(s1.time_str(20000), "20.0 s")
152
- end
170
+ end
153
171
 
154
172
  def test_fraction_of
155
173
  s1 = NewRelic::MethodTraceStats.new
@@ -245,7 +263,7 @@ class NewRelic::StatsTest < Test::Unit::TestCase
245
263
  s1.trace_call 10
246
264
  s2.trace_call 20
247
265
  s2.freeze
248
-
266
+
249
267
  validate s1, 1, 10, 10, 10
250
268
  validate s2, 1, 20, 20, 20
251
269
  s1.sum_merge! s2
@@ -270,59 +288,59 @@ class NewRelic::StatsTest < Test::Unit::TestCase
270
288
  def test_merge
271
289
  s1 = NewRelic::MethodTraceStats.new
272
290
  s2 = NewRelic::MethodTraceStats.new
273
-
291
+
274
292
  s1.trace_call 10
275
293
  s2.trace_call 20
276
294
  s2.freeze
277
-
295
+
278
296
  validate s2, 1, 20, 20, 20
279
297
  s3 = s1.merge s2
280
298
  validate s3, 2, (10+20), 10, 20
281
299
  validate s1, 1, 10, 10, 10
282
300
  validate s2, 1, 20, 20, 20
283
-
301
+
284
302
  s1.merge! s2
285
303
  validate s1, 2, (10+20), 10, 20
286
304
  validate s2, 1, 20, 20, 20
287
305
  end
288
-
306
+
289
307
  def test_merge_with_exclusive
290
308
  s1 = NewRelic::MethodTraceStats.new
291
-
309
+
292
310
  s2 = NewRelic::MethodTraceStats.new
293
-
311
+
294
312
  s1.trace_call 10, 5
295
313
  s2.trace_call 20, 10
296
314
  s2.freeze
297
-
315
+
298
316
  validate s2, 1, 20, 20, 20, 10
299
317
  s3 = s1.merge s2
300
318
  validate s3, 2, (10+20), 10, 20, (10+5)
301
319
  validate s1, 1, 10, 10, 10, 5
302
320
  validate s2, 1, 20, 20, 20, 10
303
-
321
+
304
322
  s1.merge! s2
305
323
  validate s1, 2, (10+20), 10, 20, (5+10)
306
324
  validate s2, 1, 20, 20, 20, 10
307
325
  end
308
-
326
+
309
327
  def test_merge_array
310
328
  s1 = NewRelic::MethodTraceStats.new
311
329
  merges = []
312
330
  merges << (NewRelic::MethodTraceStats.new.trace_call 1)
313
331
  merges << (NewRelic::MethodTraceStats.new.trace_call 1)
314
332
  merges << (NewRelic::MethodTraceStats.new.trace_call 1)
315
-
333
+
316
334
  s1.merge! merges
317
335
  validate s1, 3, 3, 1, 1
318
336
  end
319
-
337
+
320
338
  def test_freeze
321
339
  s1 = NewRelic::MethodTraceStats.new
322
-
340
+
323
341
  s1.trace_call 10
324
342
  s1.freeze
325
-
343
+
326
344
  begin
327
345
  # the following should throw an exception because s1 is frozen
328
346
  s1.trace_call 20
@@ -332,24 +350,24 @@ class NewRelic::StatsTest < Test::Unit::TestCase
332
350
  validate s1, 1, 10, 10, 10
333
351
  end
334
352
  end
335
-
353
+
336
354
  def test_std_dev
337
355
  s = NewRelic::MethodTraceStats.new
338
356
  s.trace_call 1
339
357
  assert s.standard_deviation == 0
340
-
358
+
341
359
  s = NewRelic::MethodTraceStats.new
342
360
  s.trace_call 10
343
361
  s.trace_call 10
344
362
  s.sum_of_squares = nil
345
363
  assert s.standard_deviation == 0
346
-
364
+
347
365
  s = NewRelic::MethodTraceStats.new
348
366
  s.trace_call 0.001
349
367
  s.trace_call 0.001
350
368
  assert s.standard_deviation == 0
351
369
 
352
-
370
+
353
371
  s = NewRelic::MethodTraceStats.new
354
372
  s.trace_call 10
355
373
  s.trace_call 10
@@ -358,7 +376,7 @@ class NewRelic::StatsTest < Test::Unit::TestCase
358
376
  s.trace_call 10
359
377
  s.trace_call 10
360
378
  assert s.standard_deviation == 0
361
-
379
+
362
380
  s = NewRelic::MethodTraceStats.new
363
381
  s.trace_call 4
364
382
  s.trace_call 7
@@ -367,35 +385,35 @@ class NewRelic::StatsTest < Test::Unit::TestCase
367
385
  s.trace_call 8
368
386
  s.trace_call 4
369
387
  assert_equal(s.sum_of_squares, 4**2 + 7**2 + 13**2 + 16**2 + 8**2 + 4**2)
370
-
388
+
371
389
  s.trace_call 9
372
390
  s.trace_call 3
373
391
  s.trace_call 1000
374
392
  s.trace_call 4
375
-
393
+
376
394
  # calculated stdev (population, not sample) from a spreadsheet.
377
395
  assert_in_delta(s.standard_deviation, 297.76, 0.01)
378
396
  end
379
-
397
+
380
398
  def test_std_dev_merge
381
399
  s1 = NewRelic::MethodTraceStats.new
382
400
  s1.trace_call 4
383
401
  s1.trace_call 7
384
-
402
+
385
403
  s2 = NewRelic::MethodTraceStats.new
386
404
  s2.trace_call 13
387
405
  s2.trace_call 16
388
-
406
+
389
407
  s3 = s1.merge(s2)
390
-
408
+
391
409
  assert_equal(s1.sum_of_squares, 4*4 + 7*7)
392
410
  assert_in_delta(s1.standard_deviation, 1.5, 0.01)
393
-
411
+
394
412
  assert_in_delta(s2.standard_deviation, 1.5, 0.01)
395
413
  assert_equal(s3.sum_of_squares, 4*4 + 7*7 + 13*13 + 16*16, "check sum of squares")
396
414
  assert_in_delta(s3.standard_deviation, 4.743, 0.01)
397
415
  end
398
-
416
+
399
417
  private
400
418
  def validate (stats, count, total, min, max, exclusive = nil)
401
419
  assert_equal stats.call_count, count