Class: PerformanceTester::Runner

Inherits:
Object
  • Object
show all
Defined in:
lib/performance_tester/runner.rb

Overview

Executes a scenario, then creates and logs outcomes

Defined Under Namespace

Classes: Context

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Runner

Returns a new instance of Runner.



12
13
14
15
# File 'lib/performance_tester/runner.rb', line 12

def initialize(options = {})
  @options = options
  initialize_browser
end

Instance Attribute Details

#optionsObject (readonly)

Returns the value of attribute options.



10
11
12
# File 'lib/performance_tester/runner.rb', line 10

def options
  @options
end

Instance Method Details

#browserObject



91
92
93
# File 'lib/performance_tester/runner.rb', line 91

def browser
  options.fetch(:browser) { Capybara }
end

#build_contextObject



55
56
57
# File 'lib/performance_tester/runner.rb', line 55

def build_context
  Context.new(params, hosts)
end

#clockObject



87
88
89
# File 'lib/performance_tester/runner.rb', line 87

def clock
  options.fetch(:clock) { Time }
end

#create_outcome(period, context) ⇒ Object



44
45
46
# File 'lib/performance_tester/runner.rb', line 44

def create_outcome(period, context)
  outcome.new(context.network_traffic, period, hosts, context.error)
end

#driverObject



95
96
97
# File 'lib/performance_tester/runner.rb', line 95

def driver
  options.fetch(:driver) { Capybara::Poltergeist::Driver }
end

#hostsObject



71
72
73
# File 'lib/performance_tester/runner.rb', line 71

def hosts
  options.fetch(:hosts) { {} }
end

#initialize_browserObject



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/performance_tester/runner.rb', line 28

def initialize_browser
  browser.run_server = false
  browser.current_driver = :poltergeist
  browser.register_driver :poltergeist do |app|
    phantomjs_options = []
    unless load_images?
      phantomjs_options << "--load-images=no"
    end
    driver_options = {
      :debug => false,
      :phantomjs_options => phantomjs_options
    }
    driver.new(app, driver_options)
  end
end

#load_images?Boolean

Returns:

  • (Boolean)


79
80
81
# File 'lib/performance_tester/runner.rb', line 79

def load_images?
  options.fetch(:load_images) { true }
end

#log_outcome(outcome) ⇒ Object



48
49
50
51
52
53
# File 'lib/performance_tester/runner.rb', line 48

def log_outcome(outcome)
  loggers.each do |logger_name, logger_options|
    logger = PerformanceTester.registered_logger(logger_name)
    logger.new(run_name, outcome, logger_options).log
  end
end

#loggersObject



75
76
77
# File 'lib/performance_tester/runner.rb', line 75

def loggers
  options.fetch(:loggers) { {} }
end

#outcomeObject



83
84
85
# File 'lib/performance_tester/runner.rb', line 83

def outcome
  options.fetch(:outcome) { Outcome }
end

#paramsObject



67
68
69
# File 'lib/performance_tester/runner.rb', line 67

def params
  options.fetch(:params) { {} }
end

#run(scenario) ⇒ Object



17
18
19
20
21
22
23
24
25
26
# File 'lib/performance_tester/runner.rb', line 17

def run(scenario)
  context = build_context
  start = time_now
  context.execute(scenario)
  stop = time_now
  period = (start .. stop)
  outcome = create_outcome(period, context)
  log_outcome(outcome)
  outcome
end

#run_nameObject



63
64
65
# File 'lib/performance_tester/runner.rb', line 63

def run_name
  options.fetch(:name) { '' }
end

#time_nowObject



59
60
61
# File 'lib/performance_tester/runner.rb', line 59

def time_now
  clock.now
end