Class: Session

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

Overview

Simulation of a user that browses a site

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Session

requests is an array of requests that will be run



5
6
7
8
# File 'lib/session.rb', line 5

def initialize(options = {})
  @requests = []
  @options = options
end

Instance Method Details

#add_request(*args) ⇒ Object



10
11
12
13
14
# File 'lib/session.rb', line 10

def add_request(*args)
  args[1] ||= {}
  args[1].merge!(@options[:request_options] || {})
  @requests << Request.new(*args)
end

#runObject



16
17
18
19
20
21
22
23
24
25
# File 'lib/session.rb', line 16

def run
  puts "Started session."
  run_times = []
  @requests.each do |r|
    puts "Doing request to %s with a time on page of %0.02f..." % [r.url, r.time_on_page]
    run_times << { :request => r, :time => VisitBench.benchmark { r.do_request! } }
    sleep r.time_on_page
  end
  return run_times
end