lib/right_develop/testing/clients/rest/requests/playback.rb in right_develop-3.1.8 vs lib/right_develop/testing/clients/rest/requests/playback.rb in right_develop-3.1.9
- old
+ new
@@ -38,13 +38,14 @@
class PeerResetConnectionError < PLAYBACK_ERROR; end
# fake Net::HTTPResponse
class FakeNetHttpResponse
- attr_reader :code, :body, :elapsed_seconds, :call_count
+ attr_reader :code, :body, :delay_seconds, :elapsed_seconds, :call_count
def initialize(response_hash, response_metadata)
+ @delay_seconds = response_metadata.delay_seconds
@elapsed_seconds = Integer(response_hash[:elapsed_seconds] || 0)
@code = response_metadata.http_status.to_s
@headers = response_metadata.headers.inject({}) do |h, (k, v)|
h[k] = Array(v) # expected to be an array
h
@@ -138,10 +139,19 @@
if @throttle > 0 && response.elapsed_seconds > 0
delay = (Float(response.elapsed_seconds) * @throttle) / 100.0
logger.debug("throttle delay = #{delay}")
sleep delay
end
+
+ # there may be a configured response delay (in addition to throttling)
+ # which allows for other responses to complete before the current
+ # response thread is unblocked. the response delay is absolute and not
+ # subject to the throttle factor.
+ if (delay = response.delay_seconds) > 0
+ logger.debug("configured response delay = #{delay}")
+ sleep delay
+ end
log_response(response)
process_result(response, &block)
else
raise PLAYBACK_ERROR,
'Unexpected RestClient::Request#transmit returned without calling RestClient::Request#log_request'
@@ -168,15 +178,19 @@
# been made. the current epoch is always preferred over past.
logger.debug("BEGIN playback state = #{state.inspect}") if logger.debug?
file_path = nil
past_epochs = state[:past_epochs] ||= []
try_epochs = [state[:epoch]] + past_epochs
- tried_paths = []
+ first_tried_path = nil
+ first_tried_epoch = nil
+ last_tried_epoch = nil
try_epochs.each do |epoch|
file_path = response_file_path(epoch)
break if ::File.file?(file_path)
- tried_paths << file_path
+ first_tried_path = file_path unless first_tried_path
+ first_tried_epoch = epoch unless first_tried_epoch
+ last_tried_epoch = epoch
file_path = nil
end
if file_path
response_hash = RightSupport::Data::Mash.new(::YAML.load_file(file_path))
if response_hash[:peer_reset_connection]
@@ -187,11 +201,13 @@
response_hash[:http_status],
response_hash[:headers],
response_hash[:body])
result = FakeNetHttpResponse.new(response_hash, response_metadata)
else
- raise PLAYBACK_ERROR,
- "Unable to locate response file(s): \"#{tried_paths.join("\", \"")}\""
+ msg = 'Unable to locate response file(s) in epoch range ' +
+ "[#{first_tried_epoch} - #{last_tried_epoch}]:\n " +
+ first_tried_path.inspect
+ raise PLAYBACK_ERROR, msg
end
logger.debug("Played back response from #{file_path.inspect}.")
# determine if epoch is done, which it is if every known request has been
# responded to for the current epoch. there is a steady state at the end