Sha256: 4b97f85ceac8f22734c17ef04e657d41332095b2a6d892ebfbc40c6ba73b9bb5

Contents?: true

Size: 1.86 KB

Versions: 5

Compression:

Stored size: 1.86 KB

Contents

# encoding: utf-8
# This file is distributed under New Relic"s license terms.
# See https://github.com/newrelic/rpm/blob/master/LICENSE for complete details.

require "httpclient"
require "newrelic_rpm"
require "test/unit"
require "http_client_test_cases"

require File.join(File.dirname(__FILE__), "..", "..", "..", "agent_helper")

class HTTPClientTest < MiniTest::Unit::TestCase
  include HttpClientTestCases

  def client_name
    "HTTPClient"
  end

  def get_response(url=nil, headers=nil)
    HTTPClient.get(url || default_url, :header => headers)
  end

  def head_response
    HTTPClient.head(default_url)
  end

  def post_response
    HTTPClient.post(default_url, :body => "")
  end

  def request_instance
    httpclient_req = HTTP::Message.new_request(:get, 'http://newrelic.com')
    NewRelic::Agent::HTTPClients::HTTPClientRequest.new(httpclient_req)
  end

  def response_instance(headers = {})
    httpclient_resp = HTTP::Message.new_response('')
    headers.each do |k, v|
      httpclient_resp.http_header[k] = v
    end
    NewRelic::Agent::HTTPClients::HTTPClientResponse.new(httpclient_resp)
  end

  def test_still_records_tt_node_when_pop_raises_an_exception
    in_transaction do
      test_exception = StandardError.new
      evil_connection = HTTPClient::Connection.new
      evil_connection.instance_variable_set(:@test_exception, test_exception)
      evil_connection.instance_eval do
        def new_push(request)
          @queue.push(@test_exception)
        end

        alias old_push push
        alias push new_push
      end

      HTTPClient::Connection.stubs(:new).returns(evil_connection)

      begin
        get_response(default_url)
      rescue => e
        raise e unless e == test_exception
      end

      last_segment = find_last_transaction_segment()
      assert_equal("External/localhost/HTTPClient/GET", last_segment.metric_name)
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
newrelic_rpm-3.6.8.168 test/multiverse/suites/httpclient/httpclient_test.rb
newrelic_rpm-3.6.8.164 test/multiverse/suites/httpclient/httpclient_test.rb
newrelic_rpm-3.6.7.159 test/multiverse/suites/httpclient/httpclient_test.rb
newrelic_rpm-3.6.7.159.beta test/multiverse/suites/httpclient/httpclient_test.rb
newrelic_rpm-3.6.7.152 test/multiverse/suites/httpclient/httpclient_test.rb