Module: Outpost::Expectations::ResponseTime

Included in:
Scouts::Http, Scouts::Ping, Scouts::Tcp
Defined in:
lib/outpost/expectations/response_time.rb

Overview

Module containing response_time matching expectations. Extend your Scout with ResponseTime and it will evaluate timely expressions, all in milisseconds.

It respond to the following rules:

  • less_than => If the response time is less than the associated number

  • more_than => If the response time is below than the associated number

Constant Summary collapse

RESPONSE_TIME_MAPPING =
{
  :less_than => "<",
  :more_than => ">",
}.freeze

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.extended(base) ⇒ Object

Installs the response time expectation



17
18
19
# File 'lib/outpost/expectations/response_time.rb', line 17

def self.extended(base)
  base.expect :response_time, base.method(:evaluate_response_time)
end

Instance Method Details

#evaluate_response_time(scout, rules) ⇒ Object

Method that will be used as an expectation to evaluate response time



22
23
24
25
26
# File 'lib/outpost/expectations/response_time.rb', line 22

def evaluate_response_time(scout, rules)
  rules.all? do |rule, comparison|
    scout.response_time.nil? ? false : scout.response_time.send(RESPONSE_TIME_MAPPING[rule], comparison)
  end
end