test/test_helper.rb in newrelic_rpm-3.7.2.195 vs test/test_helper.rb in newrelic_rpm-3.7.3.199
- old
+ new
@@ -16,10 +16,14 @@
require 'rake'
require 'minitest/autorun'
require 'mocha/setup'
+unless defined?(Minitest::Test)
+ Minitest::Test = MiniTest::Unit::TestCase
+end
+
Dir.glob('test/helpers/*').each { |f| require f }
Dir.glob(File.join(NEWRELIC_PLUGIN_DIR,'test/helpers/*.rb')).each do |helper|
require helper
end
@@ -154,11 +158,20 @@
TCPSocket.stubs( :open ).returns( socket )
return socket
end
+def cross_agent_tests_dir
+ File.expand_path(File.join(File.dirname(__FILE__), 'fixtures', 'cross_agent_tests'))
+end
+def load_cross_agent_test(name)
+ test_file_path = File.join(cross_agent_tests_dir, "#{name}.json")
+ data = File.read(test_file_path)
+ NewRelic::JSONWrapper.load(data)
+end
+
class ArrayLogDevice
def initialize( array=[] )
@array = array
end
attr_reader :array
@@ -188,24 +201,41 @@
return logdev
ensure
NewRelic::Agent.logger = orig_logger
end
+def dummy_mysql_explain_result(hash=nil)
+ hash ||= {
+ 'Id' => '1',
+ 'Select Type' => 'SIMPLE',
+ 'Table' => 'sandwiches',
+ 'Type' => 'range',
+ 'Possible Keys' => 'PRIMARY',
+ 'Key' => 'PRIMARY',
+ 'Key Length' => '4',
+ 'Ref' => '',
+ 'Rows' => '1',
+ 'Extra' => 'Using index'
+ }
+ explain_result = mock('explain result')
+ explain_result.stubs(:each_hash).yields(hash)
+ explain_result
+end
module TransactionSampleTestHelper
module_function
def make_sql_transaction(*sql)
sampler = NewRelic::Agent::TransactionSampler.new
sampler.notice_first_scope_push Time.now.to_f
sampler.notice_transaction(nil, :jim => "cool")
sampler.notice_push_scope "a"
explainer = NewRelic::Agent::Instrumentation::ActiveRecord::EXPLAINER
- sql.each {|sql_statement| sampler.notice_sql(sql_statement, {:adapter => "test"}, 0, &explainer) }
+ sql.each {|sql_statement| sampler.notice_sql(sql_statement, {:adapter => "mysql"}, 0, &explainer) }
sleep 0.02
yield if block_given?
sampler.notice_pop_scope "a"
- sampler.notice_scope_empty(stub('txn', :name => '/path', :custom_parameters => {}))
+ sampler.notice_scope_empty(stub('txn', :name => '/path', :custom_parameters => {}, :guid => 'a guid'))
sampler.last_sample
end
def run_sample_trace_on(sampler, path='/path')
@@ -219,9 +249,9 @@
sampler.notice_pop_scope "ab"
sampler.notice_push_scope "lew"
sampler.notice_sql("SELECT * FROM sandwiches WHERE bread = 'french'", {}, 0)
sampler.notice_pop_scope "lew"
sampler.notice_pop_scope "Controller/sandwiches/index"
- sampler.notice_scope_empty(stub('txn', :name => path, :custom_parameters => {}))
+ sampler.notice_scope_empty(stub('txn', :name => path, :custom_parameters => {}, :guid => 'a guid'))
sampler.last_sample
end
end