Sha256: 79958252ca7f241e5f60b164231ded32a4e716192910659db39470d0e7bfa2fe

Contents?: true

Size: 1.89 KB

Versions: 20

Compression:

Stored size: 1.89 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 "http_client_test_cases"

class HTTPClientTest < Minitest::Test
  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 put_response
    HTTPClient.put(default_url, :body => "")
  end

  def delete_response
    HTTPClient.delete(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_node = find_last_transaction_node()
      assert_equal("External/localhost/HTTPClient/GET", last_node.metric_name)
    end
  end
end

Version data entries

20 entries across 20 versions & 2 rubygems

Version Path
newrelic_rpm-3.17.2.327 test/multiverse/suites/httpclient/httpclient_test.rb
newrelic_rpm-3.17.1.326 test/multiverse/suites/httpclient/httpclient_test.rb
newrelic_rpm-3.17.0.325 test/multiverse/suites/httpclient/httpclient_test.rb
newrelic_rpm-3.16.3.323 test/multiverse/suites/httpclient/httpclient_test.rb
newrelic_rpm-3.16.2.321 test/multiverse/suites/httpclient/httpclient_test.rb
newrelic_rpm-3.16.1.320 test/multiverse/suites/httpclient/httpclient_test.rb
newrelic_rpm-3.16.0.318 test/multiverse/suites/httpclient/httpclient_test.rb
ish_lib_manager-0.0.1 test/dummy/vendor/bundle/ruby/2.3.0/gems/newrelic_rpm-3.15.2.317/test/multiverse/suites/httpclient/httpclient_test.rb
newrelic_rpm-3.15.2.317 test/multiverse/suites/httpclient/httpclient_test.rb
newrelic_rpm-3.15.1.316 test/multiverse/suites/httpclient/httpclient_test.rb
newrelic_rpm-3.15.0.314 test/multiverse/suites/httpclient/httpclient_test.rb
newrelic_rpm-3.14.3.313 test/multiverse/suites/httpclient/httpclient_test.rb
newrelic_rpm-3.14.2.312 test/multiverse/suites/httpclient/httpclient_test.rb
newrelic_rpm-3.14.1.311 test/multiverse/suites/httpclient/httpclient_test.rb
newrelic_rpm-3.14.0.305 test/multiverse/suites/httpclient/httpclient_test.rb
newrelic_rpm-3.13.2.302 test/multiverse/suites/httpclient/httpclient_test.rb
newrelic_rpm-3.13.1.300 test/multiverse/suites/httpclient/httpclient_test.rb
newrelic_rpm-3.13.0.299 test/multiverse/suites/httpclient/httpclient_test.rb
newrelic_rpm-3.12.1.298 test/multiverse/suites/httpclient/httpclient_test.rb
newrelic_rpm-3.12.0.288 test/multiverse/suites/httpclient/httpclient_test.rb