Skip to content

Commit

Permalink
Add test to check if request_id is the same at request and response time
Browse files Browse the repository at this point in the history
  • Loading branch information
funkyboy committed Apr 20, 2018
1 parent f5cfc0f commit f99e186
Showing 1 changed file with 40 additions and 7 deletions.
47 changes: 40 additions & 7 deletions spec/acceptance/rest/client_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -962,15 +962,48 @@ def encode64(text)

context 'request_id generation' do
context 'Timeout error' do
context 'with request_id' do
let(:client_options) { default_options.merge(key: api_key, http_request_timeout: 0, add_request_ids: true) }
it 'includes request_id in ConnectionTimeout error' do
begin
client.stats
rescue Ably::Exceptions::ConnectionTimeout => err
expect(err.request_id).to_not eql(nil)
context 'with request_id', :webmock do
let(:custom_logger) do
Class.new do
def initialize
@messages = []
end

[:fatal, :error, :warn, :info, :debug].each do |severity|
define_method severity do |message, &block|
message_val = [message]
message_val << block.call if block

@messages << [severity, message_val.compact.join(' ')]
end
end

def logs
@messages
end

def level
1
end

def level=(new_level)
end
end
end
let(:custom_logger_object) { custom_logger.new }
let(:client_options) { default_options.merge(key: api_key, logger: custom_logger_object, add_request_ids: true) }
before do
@request_id = nil
stub_request(:get, Addressable::Template.new("#{client.endpoint}/time{?request_id}")).with do |request|
@request_id = request.uri.query_values['request_id']
end.to_return do
raise Faraday::TimeoutError.new('timeout error message')
end
end
it 'has an error with the same request_id of the request' do
expect{ client.time }.to raise_error(Ably::Exceptions::ConnectionTimeout, /#{@request_id}/)
expect(custom_logger_object.logs.find { |severity, message| message.match(/#{@request_id}/i)} ).to_not be_nil
end
end

context 'without request_id' do
Expand Down

0 comments on commit f99e186

Please sign in to comment.