wd_newrelic_rpm 3.3.4.1
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +591 -0
- data/LICENSE +64 -0
- data/README.rdoc +179 -0
- data/bin/mongrel_rpm +33 -0
- data/bin/newrelic +13 -0
- data/bin/newrelic_cmd +5 -0
- data/cert/cacert.pem +118 -0
- data/cert/oldsite.pem +28 -0
- data/cert/site.pem +27 -0
- data/install.rb +9 -0
- data/lib/conditional_vendored_dependency_detection.rb +3 -0
- data/lib/conditional_vendored_metric_parser.rb +5 -0
- data/lib/new_relic/agent.rb +467 -0
- data/lib/new_relic/agent/agent.rb +1325 -0
- data/lib/new_relic/agent/beacon_configuration.rb +121 -0
- data/lib/new_relic/agent/browser_monitoring.rb +142 -0
- data/lib/new_relic/agent/busy_calculator.rb +99 -0
- data/lib/new_relic/agent/chained_call.rb +13 -0
- data/lib/new_relic/agent/database.rb +223 -0
- data/lib/new_relic/agent/error_collector.rb +251 -0
- data/lib/new_relic/agent/instrumentation.rb +9 -0
- data/lib/new_relic/agent/instrumentation/active_merchant.rb +29 -0
- data/lib/new_relic/agent/instrumentation/active_record.rb +137 -0
- data/lib/new_relic/agent/instrumentation/acts_as_solr.rb +68 -0
- data/lib/new_relic/agent/instrumentation/authlogic.rb +19 -0
- data/lib/new_relic/agent/instrumentation/controller_instrumentation.rb +443 -0
- data/lib/new_relic/agent/instrumentation/data_mapper.rb +238 -0
- data/lib/new_relic/agent/instrumentation/delayed_job_instrumentation.rb +52 -0
- data/lib/new_relic/agent/instrumentation/memcache.rb +80 -0
- data/lib/new_relic/agent/instrumentation/merb/controller.rb +41 -0
- data/lib/new_relic/agent/instrumentation/merb/errors.rb +29 -0
- data/lib/new_relic/agent/instrumentation/metric_frame.rb +353 -0
- data/lib/new_relic/agent/instrumentation/metric_frame/pop.rb +80 -0
- data/lib/new_relic/agent/instrumentation/net.rb +29 -0
- data/lib/new_relic/agent/instrumentation/passenger_instrumentation.rb +37 -0
- data/lib/new_relic/agent/instrumentation/queue_time.rb +210 -0
- data/lib/new_relic/agent/instrumentation/rack.rb +98 -0
- data/lib/new_relic/agent/instrumentation/rails/action_controller.rb +114 -0
- data/lib/new_relic/agent/instrumentation/rails/action_web_service.rb +42 -0
- data/lib/new_relic/agent/instrumentation/rails/errors.rb +42 -0
- data/lib/new_relic/agent/instrumentation/rails3/action_controller.rb +180 -0
- data/lib/new_relic/agent/instrumentation/rails3/errors.rb +37 -0
- data/lib/new_relic/agent/instrumentation/sinatra.rb +78 -0
- data/lib/new_relic/agent/instrumentation/sunspot.rb +29 -0
- data/lib/new_relic/agent/instrumentation/unicorn_instrumentation.rb +21 -0
- data/lib/new_relic/agent/method_tracer.rb +528 -0
- data/lib/new_relic/agent/sampler.rb +50 -0
- data/lib/new_relic/agent/samplers/cpu_sampler.rb +58 -0
- data/lib/new_relic/agent/samplers/delayed_job_lock_sampler.rb +40 -0
- data/lib/new_relic/agent/samplers/memory_sampler.rb +143 -0
- data/lib/new_relic/agent/samplers/object_sampler.rb +26 -0
- data/lib/new_relic/agent/shim_agent.rb +29 -0
- data/lib/new_relic/agent/sql_sampler.rb +286 -0
- data/lib/new_relic/agent/stats_engine.rb +26 -0
- data/lib/new_relic/agent/stats_engine/gc_profiler.rb +123 -0
- data/lib/new_relic/agent/stats_engine/metric_stats.rb +187 -0
- data/lib/new_relic/agent/stats_engine/samplers.rb +95 -0
- data/lib/new_relic/agent/stats_engine/transactions.rb +125 -0
- data/lib/new_relic/agent/transaction_info.rb +74 -0
- data/lib/new_relic/agent/transaction_sample_builder.rb +116 -0
- data/lib/new_relic/agent/transaction_sampler.rb +468 -0
- data/lib/new_relic/agent/worker_loop.rb +89 -0
- data/lib/new_relic/collection_helper.rb +77 -0
- data/lib/new_relic/command.rb +85 -0
- data/lib/new_relic/commands/deployments.rb +105 -0
- data/lib/new_relic/commands/install.rb +80 -0
- data/lib/new_relic/control.rb +46 -0
- data/lib/new_relic/control/class_methods.rb +53 -0
- data/lib/new_relic/control/configuration.rb +206 -0
- data/lib/new_relic/control/frameworks.rb +10 -0
- data/lib/new_relic/control/frameworks/external.rb +16 -0
- data/lib/new_relic/control/frameworks/merb.rb +31 -0
- data/lib/new_relic/control/frameworks/rails.rb +164 -0
- data/lib/new_relic/control/frameworks/rails3.rb +75 -0
- data/lib/new_relic/control/frameworks/ruby.rb +42 -0
- data/lib/new_relic/control/frameworks/sinatra.rb +20 -0
- data/lib/new_relic/control/instance_methods.rb +179 -0
- data/lib/new_relic/control/instrumentation.rb +100 -0
- data/lib/new_relic/control/logging_methods.rb +143 -0
- data/lib/new_relic/control/profiling.rb +25 -0
- data/lib/new_relic/control/server_methods.rb +114 -0
- data/lib/new_relic/data_serialization.rb +151 -0
- data/lib/new_relic/delayed_job_injection.rb +51 -0
- data/lib/new_relic/language_support.rb +73 -0
- data/lib/new_relic/local_environment.rb +428 -0
- data/lib/new_relic/merbtasks.rb +6 -0
- data/lib/new_relic/metric_data.rb +51 -0
- data/lib/new_relic/metric_spec.rb +76 -0
- data/lib/new_relic/metrics.rb +9 -0
- data/lib/new_relic/noticed_error.rb +29 -0
- data/lib/new_relic/rack/browser_monitoring.rb +76 -0
- data/lib/new_relic/rack/developer_mode.rb +268 -0
- data/lib/new_relic/recipes.rb +77 -0
- data/lib/new_relic/stats.rb +335 -0
- data/lib/new_relic/timer_lib.rb +27 -0
- data/lib/new_relic/transaction_analysis.rb +77 -0
- data/lib/new_relic/transaction_analysis/segment_summary.rb +49 -0
- data/lib/new_relic/transaction_sample.rb +261 -0
- data/lib/new_relic/transaction_sample/composite_segment.rb +27 -0
- data/lib/new_relic/transaction_sample/fake_segment.rb +9 -0
- data/lib/new_relic/transaction_sample/segment.rb +203 -0
- data/lib/new_relic/transaction_sample/summary_segment.rb +21 -0
- data/lib/new_relic/url_rule.rb +14 -0
- data/lib/new_relic/version.rb +55 -0
- data/lib/newrelic_rpm.rb +49 -0
- data/lib/tasks/all.rb +4 -0
- data/lib/tasks/install.rake +7 -0
- data/lib/tasks/tests.rake +19 -0
- data/newrelic.yml +265 -0
- data/newrelic_rpm.gemspec +312 -0
- data/recipes/newrelic.rb +6 -0
- data/test/active_record_fixtures.rb +77 -0
- data/test/config/newrelic.yml +48 -0
- data/test/config/test_control.rb +48 -0
- data/test/fixtures/proc_cpuinfo.txt +575 -0
- data/test/new_relic/agent/agent/connect_test.rb +403 -0
- data/test/new_relic/agent/agent/start_test.rb +255 -0
- data/test/new_relic/agent/agent/start_worker_thread_test.rb +153 -0
- data/test/new_relic/agent/agent_test.rb +140 -0
- data/test/new_relic/agent/agent_test_controller.rb +77 -0
- data/test/new_relic/agent/agent_test_controller_test.rb +382 -0
- data/test/new_relic/agent/apdex_from_server_test.rb +9 -0
- data/test/new_relic/agent/beacon_configuration_test.rb +111 -0
- data/test/new_relic/agent/browser_monitoring_test.rb +323 -0
- data/test/new_relic/agent/busy_calculator_test.rb +81 -0
- data/test/new_relic/agent/database_test.rb +149 -0
- data/test/new_relic/agent/error_collector/notice_error_test.rb +257 -0
- data/test/new_relic/agent/error_collector_test.rb +192 -0
- data/test/new_relic/agent/instrumentation/active_record_instrumentation_test.rb +576 -0
- data/test/new_relic/agent/instrumentation/controller_instrumentation_test.rb +34 -0
- data/test/new_relic/agent/instrumentation/instrumentation_test.rb +11 -0
- data/test/new_relic/agent/instrumentation/metric_frame/pop_test.rb +171 -0
- data/test/new_relic/agent/instrumentation/metric_frame_test.rb +50 -0
- data/test/new_relic/agent/instrumentation/net_instrumentation_test.rb +84 -0
- data/test/new_relic/agent/instrumentation/queue_time_test.rb +382 -0
- data/test/new_relic/agent/instrumentation/rack_test.rb +35 -0
- data/test/new_relic/agent/instrumentation/task_instrumentation_test.rb +184 -0
- data/test/new_relic/agent/memcache_instrumentation_test.rb +143 -0
- data/test/new_relic/agent/method_tracer/class_methods/add_method_tracer_test.rb +164 -0
- data/test/new_relic/agent/method_tracer/instance_methods/trace_execution_scoped_test.rb +234 -0
- data/test/new_relic/agent/method_tracer_test.rb +386 -0
- data/test/new_relic/agent/mock_scope_listener.rb +23 -0
- data/test/new_relic/agent/rpm_agent_test.rb +149 -0
- data/test/new_relic/agent/sampler_test.rb +19 -0
- data/test/new_relic/agent/shim_agent_test.rb +20 -0
- data/test/new_relic/agent/sql_sampler_test.rb +192 -0
- data/test/new_relic/agent/stats_engine/metric_stats/harvest_test.rb +150 -0
- data/test/new_relic/agent/stats_engine/metric_stats_test.rb +82 -0
- data/test/new_relic/agent/stats_engine/samplers_test.rb +99 -0
- data/test/new_relic/agent/stats_engine_test.rb +220 -0
- data/test/new_relic/agent/transaction_info_test.rb +13 -0
- data/test/new_relic/agent/transaction_sample_builder_test.rb +219 -0
- data/test/new_relic/agent/transaction_sampler_test.rb +967 -0
- data/test/new_relic/agent/worker_loop_test.rb +66 -0
- data/test/new_relic/agent_test.rb +187 -0
- data/test/new_relic/collection_helper_test.rb +149 -0
- data/test/new_relic/command/deployments_test.rb +68 -0
- data/test/new_relic/control/class_methods_test.rb +62 -0
- data/test/new_relic/control/configuration_test.rb +84 -0
- data/test/new_relic/control/logging_methods_test.rb +185 -0
- data/test/new_relic/control_test.rb +256 -0
- data/test/new_relic/data_serialization_test.rb +208 -0
- data/test/new_relic/delayed_job_injection_test.rb +16 -0
- data/test/new_relic/local_environment_test.rb +85 -0
- data/test/new_relic/metric_data_test.rb +125 -0
- data/test/new_relic/metric_parser/metric_parser_test.rb +11 -0
- data/test/new_relic/metric_spec_test.rb +95 -0
- data/test/new_relic/rack/all_test.rb +11 -0
- data/test/new_relic/rack/browser_monitoring_test.rb +142 -0
- data/test/new_relic/rack/developer_mode_helper_test.rb +141 -0
- data/test/new_relic/rack/developer_mode_test.rb +74 -0
- data/test/new_relic/stats_test.rb +411 -0
- data/test/new_relic/transaction_analysis/segment_summary_test.rb +91 -0
- data/test/new_relic/transaction_analysis_test.rb +121 -0
- data/test/new_relic/transaction_sample/composite_segment_test.rb +35 -0
- data/test/new_relic/transaction_sample/fake_segment_test.rb +17 -0
- data/test/new_relic/transaction_sample/segment_test.rb +389 -0
- data/test/new_relic/transaction_sample/summary_segment_test.rb +31 -0
- data/test/new_relic/transaction_sample_subtest_test.rb +56 -0
- data/test/new_relic/transaction_sample_test.rb +177 -0
- data/test/new_relic/version_number_test.rb +89 -0
- data/test/script/build_test_gem.sh +51 -0
- data/test/script/ci.sh +94 -0
- data/test/script/ci_bench.sh +52 -0
- data/test/test_contexts.rb +29 -0
- data/test/test_helper.rb +155 -0
- data/ui/helpers/developer_mode_helper.rb +357 -0
- data/ui/helpers/google_pie_chart.rb +48 -0
- data/ui/views/layouts/newrelic_default.rhtml +47 -0
- data/ui/views/newrelic/_explain_plans.rhtml +27 -0
- data/ui/views/newrelic/_sample.rhtml +20 -0
- data/ui/views/newrelic/_segment.rhtml +28 -0
- data/ui/views/newrelic/_segment_limit_message.rhtml +1 -0
- data/ui/views/newrelic/_segment_row.rhtml +12 -0
- data/ui/views/newrelic/_show_sample_detail.rhtml +24 -0
- data/ui/views/newrelic/_show_sample_sql.rhtml +24 -0
- data/ui/views/newrelic/_show_sample_summary.rhtml +3 -0
- data/ui/views/newrelic/_sql_row.rhtml +16 -0
- data/ui/views/newrelic/_stack_trace.rhtml +15 -0
- data/ui/views/newrelic/_table.rhtml +12 -0
- data/ui/views/newrelic/explain_sql.rhtml +43 -0
- data/ui/views/newrelic/file/images/arrow-close.png +0 -0
- data/ui/views/newrelic/file/images/arrow-open.png +0 -0
- data/ui/views/newrelic/file/images/blue_bar.gif +0 -0
- data/ui/views/newrelic/file/images/file_icon.png +0 -0
- data/ui/views/newrelic/file/images/gray_bar.gif +0 -0
- data/ui/views/newrelic/file/images/new-relic-rpm-desktop.gif +0 -0
- data/ui/views/newrelic/file/images/new_relic_rpm_desktop.gif +0 -0
- data/ui/views/newrelic/file/images/textmate.png +0 -0
- data/ui/views/newrelic/file/javascript/jquery-1.4.2.js +6240 -0
- data/ui/views/newrelic/file/javascript/transaction_sample.js +120 -0
- data/ui/views/newrelic/file/stylesheets/style.css +490 -0
- data/ui/views/newrelic/index.rhtml +71 -0
- data/ui/views/newrelic/sample_not_found.rhtml +2 -0
- data/ui/views/newrelic/show_sample.rhtml +80 -0
- data/ui/views/newrelic/show_source.rhtml +3 -0
- data/ui/views/newrelic/threads.rhtml +53 -0
- data/vendor/gems/dependency_detection-0.0.1.build/LICENSE +5 -0
- data/vendor/gems/dependency_detection-0.0.1.build/lib/dependency_detection.rb +67 -0
- data/vendor/gems/dependency_detection-0.0.1.build/lib/dependency_detection/version.rb +3 -0
- data/vendor/gems/metric_parser-0.1.0.pre1/lib/metric_parser.rb +1 -0
- data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser.rb +64 -0
- data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/action_mailer.rb +14 -0
- data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/active_merchant.rb +31 -0
- data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/active_record.rb +33 -0
- data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/apdex.rb +89 -0
- data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/background_transaction.rb +7 -0
- data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/client.rb +46 -0
- data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/controller.rb +67 -0
- data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/controller_cpu.rb +43 -0
- data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/controller_ext.rb +17 -0
- data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/database.rb +48 -0
- data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/database_pool.rb +24 -0
- data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/dot_net.rb +28 -0
- data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/dot_net_parser.rb +17 -0
- data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/errors.rb +11 -0
- data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/external.rb +55 -0
- data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/frontend.rb +40 -0
- data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/gc.rb +20 -0
- data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/hibernate_session.rb +7 -0
- data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/java.rb +31 -0
- data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/java_parser.rb +17 -0
- data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/jsp.rb +34 -0
- data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/jsp_tag.rb +7 -0
- data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/mem_cache.rb +55 -0
- data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/metric_parser.rb +135 -0
- data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/orm.rb +27 -0
- data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/other_transaction.rb +40 -0
- data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/servlet.rb +7 -0
- data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/servlet_context_listener.rb +7 -0
- data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/servlet_filter.rb +7 -0
- data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/solr.rb +27 -0
- data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/solr_request_handler.rb +15 -0
- data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/spring.rb +54 -0
- data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/spring_controller.rb +6 -0
- data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/spring_view.rb +6 -0
- data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/struts_action.rb +20 -0
- data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/struts_result.rb +20 -0
- data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/version.rb +5 -0
- data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/view.rb +70 -0
- data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/web_frontend.rb +18 -0
- data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/web_service.rb +14 -0
- data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/web_transaction.rb +133 -0
- metadata +376 -0
@@ -0,0 +1,403 @@
|
|
1
|
+
require File.expand_path(File.join(File.dirname(__FILE__),'..', '..', '..','test_helper'))
|
2
|
+
class NewRelic::Agent::Agent::ConnectTest < Test::Unit::TestCase
|
3
|
+
require 'new_relic/agent/agent'
|
4
|
+
|
5
|
+
# I don't like this, we should be testing a third party, not ourselves -Jon
|
6
|
+
include NewRelic::Agent::Agent::Connect
|
7
|
+
|
8
|
+
def setup
|
9
|
+
@connected = nil
|
10
|
+
@keep_retrying = nil
|
11
|
+
@connect_attempts = 1
|
12
|
+
@connect_retry_period = 0
|
13
|
+
@transaction_sampler = NewRelic::Agent::TransactionSampler.new
|
14
|
+
@sql_sampler = NewRelic::Agent::SqlSampler.new
|
15
|
+
end
|
16
|
+
|
17
|
+
def test_tried_to_connect?
|
18
|
+
# base case, should default to false
|
19
|
+
assert !tried_to_connect?({})
|
20
|
+
end
|
21
|
+
|
22
|
+
def test_tried_to_connect_connected
|
23
|
+
# is true if connected is true.
|
24
|
+
@connected = true
|
25
|
+
assert tried_to_connect?({})
|
26
|
+
end
|
27
|
+
|
28
|
+
def test_tried_to_connect_forced
|
29
|
+
# is false if force_reconnect is true
|
30
|
+
assert !tried_to_connect?({:force_reconnect => true})
|
31
|
+
end
|
32
|
+
|
33
|
+
def test_should_keep_retrying_base
|
34
|
+
# default to true
|
35
|
+
should_keep_retrying?({})
|
36
|
+
assert @keep_retrying, "should keep retrying by default"
|
37
|
+
end
|
38
|
+
|
39
|
+
def test_should_keep_retrying_option_true
|
40
|
+
# should be true if keep_retrying is true
|
41
|
+
should_keep_retrying?({:keep_retrying => true})
|
42
|
+
end
|
43
|
+
|
44
|
+
def test_get_retry_period
|
45
|
+
(1..6).each do |x|
|
46
|
+
@connect_attempts = x
|
47
|
+
assert_equal get_retry_period, x * 60, "should be #{x} minutes"
|
48
|
+
end
|
49
|
+
@connect_attempts = 100
|
50
|
+
assert_equal get_retry_period, 600, "should max out at 10 minutes after 6 tries"
|
51
|
+
end
|
52
|
+
|
53
|
+
def test_increment_retry_period
|
54
|
+
@connect_retry_period = 0
|
55
|
+
@connect_attempts = 1
|
56
|
+
assert_equal 0, connect_retry_period
|
57
|
+
increment_retry_period!
|
58
|
+
assert_equal 60, connect_retry_period
|
59
|
+
end
|
60
|
+
|
61
|
+
def test_should_retry_true
|
62
|
+
@keep_retrying = true
|
63
|
+
@connect_attempts = 1
|
64
|
+
log.expects(:info).once
|
65
|
+
self.expects(:increment_retry_period!).once
|
66
|
+
assert should_retry?, "should retry in this circumstance"
|
67
|
+
assert_equal 2, @connect_attempts, "should be on the second attempt"
|
68
|
+
end
|
69
|
+
|
70
|
+
def test_should_retry_false
|
71
|
+
@keep_retrying = false
|
72
|
+
self.expects(:disconnect).once
|
73
|
+
assert !should_retry?
|
74
|
+
end
|
75
|
+
|
76
|
+
def test_disconnect
|
77
|
+
assert disconnect
|
78
|
+
end
|
79
|
+
|
80
|
+
def test_attr_accessor_connect_retry_period
|
81
|
+
assert_accessor(:connect_retry_period)
|
82
|
+
end
|
83
|
+
|
84
|
+
def test_attr_accessor_connect_attempts
|
85
|
+
assert_accessor(:connect_attempts)
|
86
|
+
end
|
87
|
+
|
88
|
+
def test_log_error
|
89
|
+
error = mock('error')
|
90
|
+
error.expects(:backtrace).once.returns(["line", "secondline"])
|
91
|
+
error.expects(:message).once.returns("message")
|
92
|
+
fake_control = mock()
|
93
|
+
fake_control.expects(:server).returns("server")
|
94
|
+
self.expects(:control).once.returns(fake_control)
|
95
|
+
log.expects(:error).with("Error establishing connection with New Relic Service at server: message")
|
96
|
+
log.expects(:debug).with("line\nsecondline")
|
97
|
+
log_error(error)
|
98
|
+
end
|
99
|
+
|
100
|
+
def test_handle_license_error
|
101
|
+
error = mock('error')
|
102
|
+
self.expects(:disconnect).once
|
103
|
+
log.expects(:error).once.with("error message")
|
104
|
+
log.expects(:info).once.with("Visit NewRelic.com to obtain a valid license key, or to upgrade your account.")
|
105
|
+
error.expects(:message).returns("error message")
|
106
|
+
handle_license_error(error)
|
107
|
+
end
|
108
|
+
|
109
|
+
def test_log_seed_token
|
110
|
+
fake_control = mocked_control
|
111
|
+
fake_control.expects(:validate_seed).times(2).returns("many seeds")
|
112
|
+
fake_control.expects(:validate_token).once.returns("a token, man")
|
113
|
+
log.expects(:debug).with("Connecting with validation seed/token: many seeds/a token, man").once
|
114
|
+
log_seed_token
|
115
|
+
end
|
116
|
+
|
117
|
+
def test_no_seed_token
|
118
|
+
fake_control = mocked_control
|
119
|
+
fake_control.expects(:validate_seed).once.returns(nil)
|
120
|
+
log.expects(:debug).never
|
121
|
+
log_seed_token
|
122
|
+
end
|
123
|
+
|
124
|
+
def mocks_for_positive_environment_for_connect(value_for_control)
|
125
|
+
control = mocked_control
|
126
|
+
control.expects(:'[]').with('send_environment_info').once.returns(value_for_control)
|
127
|
+
fake_env = mock('local_env')
|
128
|
+
fake_env.expects(:snapshot).once.returns("snapshot")
|
129
|
+
control.expects(:local_env).once.returns(fake_env)
|
130
|
+
end
|
131
|
+
|
132
|
+
def test_environment_for_connect_nil
|
133
|
+
mocks_for_positive_environment_for_connect(nil)
|
134
|
+
assert_equal 'snapshot', environment_for_connect
|
135
|
+
end
|
136
|
+
|
137
|
+
def test_environment_for_connect_positive
|
138
|
+
mocks_for_positive_environment_for_connect(true)
|
139
|
+
assert_equal 'snapshot', environment_for_connect
|
140
|
+
end
|
141
|
+
|
142
|
+
def test_environment_for_connect_negative
|
143
|
+
control = mocked_control
|
144
|
+
control.expects(:'[]').with('send_environment_info').once.returns(false)
|
145
|
+
assert_equal [], environment_for_connect
|
146
|
+
end
|
147
|
+
|
148
|
+
def test_validate_settings
|
149
|
+
control = mocked_control
|
150
|
+
control.expects(:validate_seed).once
|
151
|
+
control.expects(:validate_token).once
|
152
|
+
assert_equal({:seed => nil, :token => nil}, validate_settings)
|
153
|
+
end
|
154
|
+
|
155
|
+
def test_connect_settings
|
156
|
+
control = mocked_control
|
157
|
+
control.expects(:app_names)
|
158
|
+
control.expects(:settings)
|
159
|
+
self.expects(:validate_settings)
|
160
|
+
self.expects(:environment_for_connect)
|
161
|
+
keys = %w(pid host app_name language agent_version environment settings validate)
|
162
|
+
value = connect_settings
|
163
|
+
keys.each do |k|
|
164
|
+
assert(value.has_key?(k.to_sym), "should include the key #{k}")
|
165
|
+
end
|
166
|
+
end
|
167
|
+
|
168
|
+
def test_configure_error_collector_base
|
169
|
+
fake_collector = mocked_error_collector
|
170
|
+
fake_collector.expects(:config_enabled).returns(false)
|
171
|
+
fake_collector.expects(:enabled=).with(false)
|
172
|
+
log.expects(:debug).with("Errors will not be sent to the New Relic service.")
|
173
|
+
configure_error_collector!(false)
|
174
|
+
end
|
175
|
+
|
176
|
+
def test_configure_error_collector_enabled
|
177
|
+
fake_collector = mocked_error_collector
|
178
|
+
fake_collector.expects(:config_enabled).returns(true)
|
179
|
+
fake_collector.expects(:enabled=).with(true)
|
180
|
+
log.expects(:debug).with("Errors will be sent to the New Relic service.")
|
181
|
+
configure_error_collector!(true)
|
182
|
+
end
|
183
|
+
|
184
|
+
def test_configure_error_collector_server_disabled
|
185
|
+
fake_collector = mocked_error_collector
|
186
|
+
fake_collector.expects(:config_enabled).returns(true)
|
187
|
+
fake_collector.expects(:enabled=).with(false)
|
188
|
+
log.expects(:debug).with("Errors will not be sent to the New Relic service.")
|
189
|
+
configure_error_collector!(false)
|
190
|
+
end
|
191
|
+
|
192
|
+
def test_enable_random_samples
|
193
|
+
sampling_rate = 10
|
194
|
+
ts = @transaction_sampler = mock('ts')
|
195
|
+
ts.expects(:random_sampling=).with(true)
|
196
|
+
ts.expects(:sampling_rate=).with(sampling_rate)
|
197
|
+
ts.expects(:sampling_rate).returns(sampling_rate)
|
198
|
+
log.expects(:info).with("Transaction sampling enabled, rate = 10")
|
199
|
+
enable_random_samples!(sampling_rate)
|
200
|
+
end
|
201
|
+
|
202
|
+
def test_enable_random_samples_with_no_sampling_rate
|
203
|
+
# testing that we set a sane default for sampling rate
|
204
|
+
sampling_rate = 0
|
205
|
+
ts = @transaction_sampler = mock('ts')
|
206
|
+
ts.expects(:random_sampling=).with(true)
|
207
|
+
ts.expects(:sampling_rate=).with(10)
|
208
|
+
ts.expects(:sampling_rate).returns(10)
|
209
|
+
log.expects(:info).with("Transaction sampling enabled, rate = 10")
|
210
|
+
enable_random_samples!(sampling_rate)
|
211
|
+
end
|
212
|
+
|
213
|
+
def test_config_transaction_tracer
|
214
|
+
NewRelic::Control.instance.settings['transaction_tracer'] = {
|
215
|
+
'enabled' => true,
|
216
|
+
'random_sample' => false,
|
217
|
+
'explain_threshold' => 0.75,
|
218
|
+
'explain_enabled' => true
|
219
|
+
}
|
220
|
+
|
221
|
+
config_transaction_tracer
|
222
|
+
|
223
|
+
assert @transaction_sampler.enabled?
|
224
|
+
assert_equal 0.75, @transaction_sampler.explain_threshold
|
225
|
+
assert @transaction_sampler.explain_enabled
|
226
|
+
# assert_equal 1.5, @transaction_sampler.transaction_threshold
|
227
|
+
end
|
228
|
+
|
229
|
+
def test_configure_transaction_tracer_with_random_sampling
|
230
|
+
@config_should_send_samples = true
|
231
|
+
@should_send_random_samples = true
|
232
|
+
@slowest_transaction_threshold = 5
|
233
|
+
log.stubs(:debug)
|
234
|
+
self.expects(:enable_random_samples!).with(10)
|
235
|
+
configure_transaction_tracer!(true, 10)
|
236
|
+
assert @should_send_samples
|
237
|
+
assert_equal 5, @transaction_sampler.slow_capture_threshold
|
238
|
+
end
|
239
|
+
|
240
|
+
def test_configure_transaction_tracer_positive
|
241
|
+
@config_should_send_samples = true
|
242
|
+
@slowest_transaction_threshold = 5
|
243
|
+
log.stubs(:debug)
|
244
|
+
configure_transaction_tracer!(true, 10)
|
245
|
+
assert @should_send_samples
|
246
|
+
assert_equal 5, @transaction_sampler.slow_capture_threshold
|
247
|
+
end
|
248
|
+
|
249
|
+
def test_configure_transaction_tracer_negative
|
250
|
+
@config_should_send_samples = false
|
251
|
+
log.expects(:debug).with('Transaction traces will not be sent to the New Relic service.')
|
252
|
+
configure_transaction_tracer!(true, 10)
|
253
|
+
assert !@should_send_samples
|
254
|
+
end
|
255
|
+
|
256
|
+
def test_configure_transaction_tracer_server_disabled
|
257
|
+
@config_should_send_samples = true
|
258
|
+
log.expects(:debug).with('Transaction traces will not be sent to the New Relic service.')
|
259
|
+
configure_transaction_tracer!(false, 10)
|
260
|
+
assert !@should_send_samples
|
261
|
+
end
|
262
|
+
|
263
|
+
def test_apdex_f
|
264
|
+
NewRelic::Control.instance.expects(:apdex_t).returns(10)
|
265
|
+
assert_equal 40, apdex_f
|
266
|
+
end
|
267
|
+
|
268
|
+
def test_apdex_f_threshold_positive
|
269
|
+
NewRelic::Control.instance.settings['transaction_tracer'] = { 'transaction_threshold' => 'apdex_f' }
|
270
|
+
assert apdex_f_threshold?
|
271
|
+
end
|
272
|
+
|
273
|
+
def test_apdex_f_threshold_negative
|
274
|
+
NewRelic::Control.instance.settings['transaction_tracer'] = { 'transaction_threshold' => 'WHEE' }
|
275
|
+
assert !apdex_f_threshold?
|
276
|
+
end
|
277
|
+
|
278
|
+
def test_set_sql_recording_default
|
279
|
+
NewRelic::Control.instance.settings['transaction_tracer'] = { }
|
280
|
+
self.expects(:log_sql_transmission_warning?)
|
281
|
+
set_sql_recording!
|
282
|
+
assert_equal :obfuscated, @record_sql, " should default to :obfuscated, was #{@record_sql}"
|
283
|
+
end
|
284
|
+
|
285
|
+
def test_set_sql_recording_off
|
286
|
+
NewRelic::Control.instance.settings['transaction_tracer'] = {'record_sql' => 'off'}
|
287
|
+
self.expects(:log_sql_transmission_warning?)
|
288
|
+
set_sql_recording!
|
289
|
+
assert_equal :off, @record_sql, "should be set to :off, was #{@record_sql}"
|
290
|
+
end
|
291
|
+
|
292
|
+
def test_set_sql_recording_none
|
293
|
+
NewRelic::Control.instance.settings['transaction_tracer'] = {'record_sql' => 'none'}
|
294
|
+
self.expects(:log_sql_transmission_warning?)
|
295
|
+
set_sql_recording!
|
296
|
+
assert_equal :off, @record_sql, "should be set to :off, was #{@record_sql}"
|
297
|
+
end
|
298
|
+
|
299
|
+
def test_set_sql_recording_raw
|
300
|
+
NewRelic::Control.instance.settings['transaction_tracer'] = {'record_sql' => 'raw'}
|
301
|
+
self.expects(:log_sql_transmission_warning?)
|
302
|
+
set_sql_recording!
|
303
|
+
assert_equal :raw, @record_sql, "should be set to :raw, was #{@record_sql}"
|
304
|
+
end
|
305
|
+
|
306
|
+
def test_set_sql_recording_falsy
|
307
|
+
NewRelic::Control.instance.settings['transaction_tracer'] = {'record_sql' => false}
|
308
|
+
self.expects(:log_sql_transmission_warning?)
|
309
|
+
set_sql_recording!
|
310
|
+
assert_equal :off, @record_sql, "should be set to :off, was #{@record_sql}"
|
311
|
+
end
|
312
|
+
|
313
|
+
def test_log_sql_transmission_warning_negative
|
314
|
+
log = mocked_log
|
315
|
+
@record_sql = :obfuscated
|
316
|
+
log.expects(:warn).never
|
317
|
+
log_sql_transmission_warning?
|
318
|
+
end
|
319
|
+
|
320
|
+
def test_log_sql_transmission_warning_positive
|
321
|
+
log = mocked_log
|
322
|
+
@record_sql = :raw
|
323
|
+
log.expects(:warn).with('Agent is configured to send raw SQL to the service')
|
324
|
+
log_sql_transmission_warning?
|
325
|
+
end
|
326
|
+
|
327
|
+
def test_set_collector_host_positive
|
328
|
+
control = mocked_control
|
329
|
+
self.expects(:invoke_remote).with(:get_redirect_host).returns('collector-deux.newrelic.com')
|
330
|
+
control.expects(:server_from_host).with('collector-deux.newrelic.com').returns('correct')
|
331
|
+
set_collector_host!
|
332
|
+
assert_equal 'correct', @collector
|
333
|
+
end
|
334
|
+
|
335
|
+
def test_set_collector_host_negative
|
336
|
+
@collector = 'initial value'
|
337
|
+
control = mocked_control
|
338
|
+
self.expects(:invoke_remote).with(:get_redirect_host).returns(nil)
|
339
|
+
set_collector_host!
|
340
|
+
assert_equal 'initial value', @collector, "should not modify collector value"
|
341
|
+
end
|
342
|
+
|
343
|
+
def test_query_server_for_configuration
|
344
|
+
self.expects(:set_collector_host!)
|
345
|
+
self.expects(:connect_to_server).returns("so happy")
|
346
|
+
self.expects(:finish_setup).with("so happy")
|
347
|
+
query_server_for_configuration
|
348
|
+
end
|
349
|
+
|
350
|
+
def test_finish_setup
|
351
|
+
config = {
|
352
|
+
'agent_run_id' => 'fishsticks',
|
353
|
+
'data_report_period' => 'pasta sauce',
|
354
|
+
'url_rules' => 'tamales',
|
355
|
+
'collect_traces' => true,
|
356
|
+
'collect_errors' => true,
|
357
|
+
'sample_rate' => 10
|
358
|
+
}
|
359
|
+
NewRelic::Control.instance.settings['transaction_tracer'] = {'enabled' => true}
|
360
|
+
self.expects(:log_connection!).with(config)
|
361
|
+
self.expects(:configure_transaction_tracer!).with(true, 10)
|
362
|
+
self.expects(:configure_error_collector!).with(true)
|
363
|
+
@transaction_sampler = stub('transaction sampler', :configure! => true,
|
364
|
+
:config => {})
|
365
|
+
@sql_sampler = stub('sql sampler', :configure! => true)
|
366
|
+
finish_setup(config)
|
367
|
+
assert_equal 'fishsticks', @agent_id
|
368
|
+
assert_equal 'pasta sauce', @report_period
|
369
|
+
assert_equal 'tamales', @url_rules
|
370
|
+
end
|
371
|
+
|
372
|
+
private
|
373
|
+
|
374
|
+
def mocked_control
|
375
|
+
fake_control = mock('control')
|
376
|
+
self.stubs(:control).returns(fake_control)
|
377
|
+
fake_control
|
378
|
+
end
|
379
|
+
|
380
|
+
def mocked_log
|
381
|
+
fake_log = mock('log')
|
382
|
+
self.stubs(:log).returns(fake_log)
|
383
|
+
fake_log
|
384
|
+
end
|
385
|
+
|
386
|
+
def mocked_error_collector
|
387
|
+
fake_collector = mock('error collector')
|
388
|
+
self.stubs(:error_collector).returns(fake_collector)
|
389
|
+
fake_collector
|
390
|
+
end
|
391
|
+
|
392
|
+
def log
|
393
|
+
@logger ||= Object.new
|
394
|
+
end
|
395
|
+
|
396
|
+
def assert_accessor(sym)
|
397
|
+
var_name = "@#{sym}"
|
398
|
+
instance_variable_set(var_name, 1)
|
399
|
+
assert (self.send(sym) == 1)
|
400
|
+
self.send(sym.to_s + '=', 10)
|
401
|
+
assert (instance_variable_get(var_name) == 10)
|
402
|
+
end
|
403
|
+
end
|
@@ -0,0 +1,255 @@
|
|
1
|
+
require File.expand_path(File.join(File.dirname(__FILE__),'..','..','..','test_helper'))
|
2
|
+
class NewRelic::Agent::Agent::StartTest < Test::Unit::TestCase
|
3
|
+
require 'new_relic/agent/agent'
|
4
|
+
include NewRelic::Agent::Agent::Start
|
5
|
+
|
6
|
+
def test_already_started_positive
|
7
|
+
control = mocked_control
|
8
|
+
control.expects(:log!).with("Agent Started Already!", :error)
|
9
|
+
self.expects(:started?).returns(true)
|
10
|
+
assert already_started?, "should have already started"
|
11
|
+
end
|
12
|
+
|
13
|
+
def test_already_started_negative
|
14
|
+
self.expects(:started?).returns(false)
|
15
|
+
assert !already_started?
|
16
|
+
end
|
17
|
+
|
18
|
+
def test_disabled_positive
|
19
|
+
control = mocked_control
|
20
|
+
control.expects(:agent_enabled?).returns(false)
|
21
|
+
assert disabled?
|
22
|
+
end
|
23
|
+
|
24
|
+
def test_disabled_negative
|
25
|
+
control = mocked_control
|
26
|
+
control.expects(:agent_enabled?).returns(true)
|
27
|
+
assert !disabled?
|
28
|
+
end
|
29
|
+
|
30
|
+
def test_log_dispatcher_positive
|
31
|
+
control = mocked_control
|
32
|
+
log = mocked_log
|
33
|
+
control.expects(:dispatcher).returns('Y U NO SERVE WEBPAGE')
|
34
|
+
log.expects(:info).with("Dispatcher: Y U NO SERVE WEBPAGE")
|
35
|
+
log_dispatcher
|
36
|
+
end
|
37
|
+
|
38
|
+
def test_log_dispatcher_negative
|
39
|
+
control = mocked_control
|
40
|
+
log = mocked_log
|
41
|
+
control.expects(:dispatcher).returns('')
|
42
|
+
log.expects(:info).with("No dispatcher detected.")
|
43
|
+
log_dispatcher
|
44
|
+
end
|
45
|
+
|
46
|
+
def test_log_app_names
|
47
|
+
control = mocked_control
|
48
|
+
log = mocked_log
|
49
|
+
control.expects(:app_names).returns(%w(zam zam zabam))
|
50
|
+
log.expects(:info).with("Application: zam, zam, zabam")
|
51
|
+
log_app_names
|
52
|
+
end
|
53
|
+
|
54
|
+
def test_check_config_and_start_agent_disabled
|
55
|
+
self.expects(:monitoring?).returns(false)
|
56
|
+
check_config_and_start_agent
|
57
|
+
end
|
58
|
+
|
59
|
+
def test_check_config_and_start_agent_incorrect_key
|
60
|
+
self.expects(:monitoring?).returns(true)
|
61
|
+
self.expects(:has_correct_license_key?).returns(false)
|
62
|
+
check_config_and_start_agent
|
63
|
+
end
|
64
|
+
|
65
|
+
def test_check_config_and_start_agent_forking
|
66
|
+
self.expects(:monitoring?).returns(true)
|
67
|
+
self.expects(:has_correct_license_key?).returns(true)
|
68
|
+
self.expects(:using_forking_dispatcher?).returns(true)
|
69
|
+
check_config_and_start_agent
|
70
|
+
end
|
71
|
+
|
72
|
+
def test_check_config_and_start_agent_normal
|
73
|
+
self.expects(:monitoring?).returns(true)
|
74
|
+
self.expects(:has_correct_license_key?).returns(true)
|
75
|
+
self.expects(:using_forking_dispatcher?).returns(false)
|
76
|
+
control = mocked_control
|
77
|
+
control.expects(:sync_startup).returns(false)
|
78
|
+
self.expects(:start_worker_thread)
|
79
|
+
self.expects(:install_exit_handler)
|
80
|
+
check_config_and_start_agent
|
81
|
+
end
|
82
|
+
|
83
|
+
def test_check_config_and_start_agent_sync
|
84
|
+
self.expects(:monitoring?).returns(true)
|
85
|
+
self.expects(:has_correct_license_key?).returns(true)
|
86
|
+
self.expects(:using_forking_dispatcher?).returns(false)
|
87
|
+
control = mocked_control
|
88
|
+
control.expects(:sync_startup).returns(true)
|
89
|
+
self.expects(:connect_in_foreground)
|
90
|
+
self.expects(:start_worker_thread)
|
91
|
+
self.expects(:install_exit_handler)
|
92
|
+
check_config_and_start_agent
|
93
|
+
end
|
94
|
+
|
95
|
+
def test_connect_in_foreground
|
96
|
+
self.expects(:connect).with({:keep_retrying => false })
|
97
|
+
connect_in_foreground
|
98
|
+
end
|
99
|
+
|
100
|
+
def at_exit
|
101
|
+
yield
|
102
|
+
end
|
103
|
+
private :at_exit
|
104
|
+
|
105
|
+
def test_install_exit_handler_positive
|
106
|
+
control = mocked_control
|
107
|
+
control.expects(:send_data_on_exit).returns(true)
|
108
|
+
NewRelic::LanguageSupport.expects(:using_engine?).with('rbx').returns(false)
|
109
|
+
NewRelic::LanguageSupport.expects(:using_engine?).with('jruby').returns(false)
|
110
|
+
self.expects(:using_sinatra?).returns(false)
|
111
|
+
# we are overriding at_exit above, to immediately return, so we can
|
112
|
+
# test the shutdown logic. It's somewhat unfortunate, but we can't
|
113
|
+
# kill the interpreter during a test.
|
114
|
+
self.expects(:shutdown)
|
115
|
+
install_exit_handler
|
116
|
+
end
|
117
|
+
|
118
|
+
def test_install_exit_handler_negative
|
119
|
+
control = mocked_control
|
120
|
+
control.expects(:send_data_on_exit).returns(false)
|
121
|
+
install_exit_handler
|
122
|
+
end
|
123
|
+
|
124
|
+
def test_install_exit_handler_weird_ruby
|
125
|
+
control = mocked_control
|
126
|
+
control.expects(:send_data_on_exit).times(3).returns(true)
|
127
|
+
NewRelic::LanguageSupport.expects(:using_engine?).with('rbx').returns(false)
|
128
|
+
NewRelic::LanguageSupport.expects(:using_engine?).with('jruby').returns(false)
|
129
|
+
self.expects(:using_sinatra?).returns(true)
|
130
|
+
install_exit_handler
|
131
|
+
NewRelic::LanguageSupport.expects(:using_engine?).with('rbx').returns(false)
|
132
|
+
NewRelic::LanguageSupport.expects(:using_engine?).with('jruby').returns(true)
|
133
|
+
install_exit_handler
|
134
|
+
NewRelic::LanguageSupport.expects(:using_engine?).with('rbx').returns(true)
|
135
|
+
install_exit_handler
|
136
|
+
end
|
137
|
+
|
138
|
+
def test_notify_log_file_location_positive
|
139
|
+
log = mocked_log
|
140
|
+
NewRelic::Control.instance.expects(:log_file).returns('./')
|
141
|
+
log.expects(:send).with(:info, "Agent Log at ./")
|
142
|
+
notify_log_file_location
|
143
|
+
end
|
144
|
+
|
145
|
+
def test_notify_log_file_location_negative
|
146
|
+
log = mocked_log
|
147
|
+
NewRelic::Control.instance.expects(:log_file).returns(nil)
|
148
|
+
notify_log_file_location
|
149
|
+
end
|
150
|
+
|
151
|
+
def test_monitoring_positive
|
152
|
+
control = mocked_control
|
153
|
+
control.expects(:monitor_mode?).returns(true)
|
154
|
+
log = mocked_log
|
155
|
+
assert monitoring?
|
156
|
+
end
|
157
|
+
|
158
|
+
def test_monitoring_negative
|
159
|
+
control = mocked_control
|
160
|
+
log = mocked_log
|
161
|
+
control.expects(:monitor_mode?).returns(false)
|
162
|
+
log.expects(:send).with(:warn, "Agent configured not to send data in this environment - edit newrelic.yml to change this")
|
163
|
+
assert !monitoring?
|
164
|
+
end
|
165
|
+
|
166
|
+
def test_has_license_key_positive
|
167
|
+
control = mocked_control
|
168
|
+
control.expects(:license_key).returns("a" * 40)
|
169
|
+
assert has_license_key?
|
170
|
+
end
|
171
|
+
|
172
|
+
def test_has_license_key_negative
|
173
|
+
control = mocked_control
|
174
|
+
control.expects(:license_key).returns(nil)
|
175
|
+
log = mocked_log
|
176
|
+
log.expects(:send).with(:error, 'No license key found. Please edit your newrelic.yml file and insert your license key.')
|
177
|
+
assert !has_license_key?
|
178
|
+
end
|
179
|
+
|
180
|
+
def test_has_correct_license_key_positive
|
181
|
+
self.expects(:has_license_key?).returns(true)
|
182
|
+
self.expects(:correct_license_length).returns(true)
|
183
|
+
assert has_correct_license_key?
|
184
|
+
end
|
185
|
+
|
186
|
+
def test_has_correct_license_key_negative
|
187
|
+
self.expects(:has_license_key?).returns(false)
|
188
|
+
assert !has_correct_license_key?
|
189
|
+
end
|
190
|
+
|
191
|
+
def test_correct_license_length_positive
|
192
|
+
control = mocked_control
|
193
|
+
control.expects(:license_key).returns("a" * 40)
|
194
|
+
assert correct_license_length
|
195
|
+
end
|
196
|
+
|
197
|
+
def test_correct_license_length_negative
|
198
|
+
control = mocked_control
|
199
|
+
log = mocked_log
|
200
|
+
control.expects(:license_key).returns("a"*30)
|
201
|
+
log.expects(:send).with(:error, "Invalid license key: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa")
|
202
|
+
assert !correct_license_length
|
203
|
+
end
|
204
|
+
|
205
|
+
def test_using_forking_dispatcher_positive
|
206
|
+
control = mocked_control
|
207
|
+
control.expects(:dispatcher).returns(:passenger)
|
208
|
+
log = mocked_log
|
209
|
+
log.expects(:send).with(:info, "Connecting workers after forking.")
|
210
|
+
assert using_forking_dispatcher?
|
211
|
+
end
|
212
|
+
|
213
|
+
def test_using_forking_dispatcher_negative
|
214
|
+
control = mocked_control
|
215
|
+
control.expects(:dispatcher).returns(:frobnitz)
|
216
|
+
assert !using_forking_dispatcher?
|
217
|
+
end
|
218
|
+
|
219
|
+
def test_log_unless_positive
|
220
|
+
# should not log
|
221
|
+
assert log_unless(true, :warn, "DURRR")
|
222
|
+
end
|
223
|
+
def test_log_unless_negative
|
224
|
+
# should log
|
225
|
+
log = mocked_log
|
226
|
+
log.expects(:send).with(:warn, "DURRR")
|
227
|
+
assert !log_unless(false, :warn, "DURRR")
|
228
|
+
end
|
229
|
+
|
230
|
+
def test_log_if_positive
|
231
|
+
log = mocked_log
|
232
|
+
log.expects(:send).with(:warn, "WHEE")
|
233
|
+
assert log_if(true, :warn, "WHEE")
|
234
|
+
end
|
235
|
+
|
236
|
+
def test_log_if_negative
|
237
|
+
assert !log_if(false, :warn, "WHEE")
|
238
|
+
end
|
239
|
+
|
240
|
+
private
|
241
|
+
|
242
|
+
def mocked_log
|
243
|
+
fake_log = mock('log')
|
244
|
+
self.stubs(:log).returns(fake_log)
|
245
|
+
fake_log
|
246
|
+
end
|
247
|
+
|
248
|
+
|
249
|
+
def mocked_control
|
250
|
+
fake_control = mock('control')
|
251
|
+
self.stubs(:control).returns(fake_control)
|
252
|
+
fake_control
|
253
|
+
end
|
254
|
+
end
|
255
|
+
|