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



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

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

#build_contextObject



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

def build_context
  Context.new(params, hosts)
end

#clockObject



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

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

#create_outcome(period, context) ⇒ Object



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

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

#driverObject



100
101
102
# File 'lib/performance_tester/runner.rb', line 100

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

#hostsObject



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

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

#initialize_browserObject



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# 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,
      :timeout => timeout,
      :phantomjs_options => phantomjs_options
    }
    driver.new(app, driver_options)
  end
end

#load_images?Boolean

Returns:

  • (Boolean)


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

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

#log_outcome(outcome) ⇒ Object



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

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



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

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

#outcomeObject



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

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

#paramsObject



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

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



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

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

#time_nowObject



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

def time_now
  clock.now
end

#timeoutObject



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

def timeout
  options.fetch(:timeout) { 30 }
end