Class: RightDevelop::Testing::Client::Rest::Request::Record

Inherits:
Base
  • Object
show all
Defined in:
lib/right_develop/testing/clients/rest/requests/record.rb

Overview

Provides a middle-ware layer that intercepts response by overriding the logging mechanism built into rest-client Request. Request supports ‘before’ hooks (for request) but not ‘after’ hooks (for response) so logging is all we have.

Defined Under Namespace

Classes: TimeoutNetHttpResponse

Constant Summary

Constants inherited from Base

Base::METADATA_CLASS, Base::MUTEX

Instance Attribute Summary

Attributes inherited from Base

#fixtures_dir, #logger, #request_metadata, #request_timestamp, #response_metadata, #response_timestamp, #route_data, #route_path, #state_file_path

Instance Method Summary collapse

Methods inherited from Base

#forget_outstanding_request, #initialize

Constructor Details

This class inherits a constructor from RightDevelop::Testing::Client::Rest::Request::Base

Instance Method Details

#handle_timeoutObject

See Also:

  • Base.handle_timeout


105
106
107
108
109
110
# File 'lib/right_develop/testing/clients/rest/requests/record.rb', line 105

def handle_timeout
  super
  response = TimeoutNetHttpResponse.new
  with_state_lock { |state| record_response(state, response) }
  response
end

#log_requestObject

Overrides log_request for basic logging.

Parameters:

  • to (RestClient::Response)

    capture

Returns:

  • (Object)

    undefined



88
89
90
91
# File 'lib/right_develop/testing/clients/rest/requests/record.rb', line 88

def log_request
  logger.debug("proxied_url = #{@url.inspect}")
  super
end

#log_response(response) ⇒ Object

Overrides log_response to capture both request and response.

Parameters:

  • to (RestClient::Response)

    capture

Returns:

  • (Object)

    undefined



98
99
100
101
102
# File 'lib/right_develop/testing/clients/rest/requests/record.rb', line 98

def log_response(response)
  result = super
  with_state_lock { |state| record_response(state, response) }
  result
end

#transmit(uri, req, payload, &block) ⇒ Object

Overrides transmit to catch halt thrown by log_request.

Parameters:

  • URI[ (URI[ uri of some kind)

    uri of some kind

  • req (Net::HTTP)

    of some kind

  • of (RestClient::Payload)

    some kind

Returns:



73
74
75
76
77
78
79
80
81
# File 'lib/right_develop/testing/clients/rest/requests/record.rb', line 73

def transmit(uri, req, payload, &block)
  super
rescue ::Interrupt
  if @request_timestamp
    logger.warn('Interrupted with at least one request outstanding; will record a timeout response.')
    handle_timeout
  end
  raise
end