Permalink
Browse files

record the response time

  • Loading branch information...
1 parent 148294e commit d24194a7396e069ff25ad6e98bfa448a4f14035d @jamesgolick committed Apr 30, 2009
Showing with 29 additions and 10 deletions.
  1. +9 −4 lib/trample/session.rb
  2. +20 −6 test/session_test.rb
@@ -1,11 +1,13 @@
module Trample
class Session
include Logging
+ include Timer
- attr_reader :config
+ attr_reader :config, :response_times
def initialize(config)
- @config = config
+ @config = config
+ @response_times = []
end
def trample
@@ -18,8 +20,11 @@ def trample
protected
def request(page)
- logger.info "#{page.request_method.to_s.upcase} #{page.url}"
- RestClient.send(page.request_method, page.url)
+ length = time do
+ RestClient.send(page.request_method, page.url)
+ end
+ response_times << length
+ logger.info "#{page.request_method.to_s.upcase} #{page.url} #{length}s"
end
end
end
View
@@ -1,14 +1,17 @@
require 'test_helper'
class SessionTest < Test::Unit::TestCase
+ def setup
+ @config = Trample::Configuration.new do |t|
+ t.iterations 2
+ t.get("http://google.com/")
+ t.get("http://amazon.com/")
+ end
+ @session = Trample::Session.new(@config)
+ end
+
context "Starting a trample session" do
setup do
- @config = Trample::Configuration.new do |t|
- t.iterations 2
- t.get("http://google.com/")
- t.get("http://amazon.com/")
- end
- @session = Trample::Session.new(@config)
@session.trample
end
@@ -17,5 +20,16 @@ class SessionTest < Test::Unit::TestCase
mock(RestClient).get("http://amazon.com/").times(2)
end
end
+
+ context "Visiting a page" do
+ setup do
+ stub(@session).time { 1.4 }
+ @session.trample
+ end
+
+ should "record the length of tiem it took to visit that page" do
+ assert_equal [1.4, 1.4, 1.4, 1.4], @session.response_times
+ end
+ end
end

0 comments on commit d24194a

Please sign in to comment.