wgibbs-trample 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,5 @@
1
+ *.sw?
2
+ .DS_Store
3
+ coverage
4
+ rdoc
5
+ pkg
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2009 James Golick
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.rdoc ADDED
@@ -0,0 +1,42 @@
1
+ = trample
2
+
3
+ Trample is a flexible load simulation tool.
4
+
5
+ Most load sim tools make requests to a static list of urls. They spawn n threads and make requests to the urls on the list in succession, in each thread. Unfortunately, though, if your applicaition makes use of any kind of caching (including your database's internal caching facilities), this kind of load simulation is unrealistic.
6
+
7
+ The data required to serve a single set of urls is likely to fit nicely in the database server's cache (even on a small server). So, having a single user hammer a finite set of pages will make your application look much faster than it really is.
8
+
9
+ Trample allows you to provide parameter values inside of a block (a lambda function, for non-rubyists). The block is executed each time the parameters are needed. So, if you use randomization in the block, you should (theoretically) get different values every time.
10
+
11
+ That way, you can have trample log in as several different users and request different data in each session.
12
+
13
+ = How To
14
+
15
+ Trample uses a ruby DSL for configuration.
16
+
17
+ Trample.configure do
18
+ concurrency 5
19
+ iterations 10
20
+ login do
21
+ post "http://yoursite.com/login" do
22
+ {:username => User.random.username, :password => "swordfish"}
23
+ end
24
+ end
25
+ get "http://yoursite.com/somewhere"
26
+ post "http://yoursite.com/something" do
27
+ {:a_parameter => "a value"}
28
+ end
29
+ get "http://yoursite.com/someresources/:id" do
30
+ {:id => SomeResource.random.id}
31
+ end
32
+ end
33
+
34
+ The above configuration will start 5 (concurrency) sessions by logging in as a random user at the url in the login block. Then, it'll hit the two urls underneath it 10 (iterations) times during each session.
35
+
36
+ To run trample, save your configuration somewhere and run:
37
+
38
+ trample start /path/to/your/trample/config.rb
39
+
40
+ == Copyright
41
+
42
+ Copyright (c) 2009 James Golick. See LICENSE for details.
data/Rakefile ADDED
@@ -0,0 +1,48 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+
4
+ begin
5
+ require 'jeweler'
6
+ Jeweler::Tasks.new do |gem|
7
+ gem.name = "trample"
8
+ gem.summary = %Q{TODO}
9
+ gem.email = "james@giraffesoft.ca"
10
+ gem.homepage = "http://github.com/giraffesoft/trample"
11
+ gem.authors = ["James Golick"]
12
+ # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
13
+ end
14
+ rescue LoadError
15
+ puts "Jeweler not available. Install it with: sudo gem install technicalpickles-jeweler -s http://gems.github.com"
16
+ end
17
+
18
+ require 'rake/rdoctask'
19
+ Rake::RDocTask.new do |rdoc|
20
+ rdoc.rdoc_dir = 'rdoc'
21
+ rdoc.title = 'trample'
22
+ rdoc.options << '--line-numbers' << '--inline-source'
23
+ rdoc.rdoc_files.include('README*')
24
+ rdoc.rdoc_files.include('lib/**/*.rb')
25
+ end
26
+
27
+ require 'rake/testtask'
28
+ Rake::TestTask.new(:test) do |test|
29
+ test.libs << 'lib' << 'test'
30
+ test.pattern = 'test/**/*_test.rb'
31
+ test.verbose = false
32
+ end
33
+
34
+ begin
35
+ require 'rcov/rcovtask'
36
+ Rcov::RcovTask.new do |test|
37
+ test.libs << 'test'
38
+ test.pattern = 'test/**/*_test.rb'
39
+ test.verbose = true
40
+ end
41
+ rescue LoadError
42
+ task :rcov do
43
+ abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
44
+ end
45
+ end
46
+
47
+
48
+ task :default => :test
data/VERSION.yml ADDED
@@ -0,0 +1,4 @@
1
+ ---
2
+ :minor: 1
3
+ :patch: 0
4
+ :major: 0
data/bin/trample ADDED
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'rubygems'
4
+ require File.dirname(__FILE__) + '/../lib/trample'
5
+
6
+ Trample::Cli.start
7
+
data/lib/trample.rb ADDED
@@ -0,0 +1,23 @@
1
+ gem 'sevenwire-rest-client'
2
+ require 'log4r'
3
+ require 'rest_client'
4
+ require 'hpricot'
5
+
6
+ module Trample
7
+ autoload :Configuration, File.dirname(__FILE__) + "/trample/configuration"
8
+ autoload :Page, File.dirname(__FILE__) + "/trample/page"
9
+ autoload :Session, File.dirname(__FILE__) + "/trample/session"
10
+ autoload :Runner, File.dirname(__FILE__) + "/trample/runner"
11
+ autoload :Cli, File.dirname(__FILE__) + "/trample/cli"
12
+ autoload :Logging, File.dirname(__FILE__) + "/trample/logging"
13
+ autoload :Timer, File.dirname(__FILE__) + "/trample/timer"
14
+
15
+ class << self
16
+ attr_reader :current_configuration
17
+
18
+ def configure(&block)
19
+ @current_configuration = Configuration.new(&block)
20
+ end
21
+ end
22
+ end
23
+
@@ -0,0 +1,12 @@
1
+ require 'thor'
2
+
3
+ module Trample
4
+ class Cli < Thor
5
+ desc "start path/to/config/file", "Start trampling"
6
+ def start(config)
7
+ load(config)
8
+ Runner.new(Trample.current_configuration).trample
9
+ end
10
+ end
11
+ end
12
+
@@ -0,0 +1,46 @@
1
+ module Trample
2
+ class Configuration
3
+ attr_reader :pages
4
+
5
+ def initialize(&block)
6
+ @pages = []
7
+ instance_eval(&block)
8
+ end
9
+
10
+ def concurrency(*value)
11
+ @concurrency = value.first unless value.empty?
12
+ @concurrency
13
+ end
14
+
15
+ def iterations(*value)
16
+ @iterations = value.first unless value.empty?
17
+ @iterations
18
+ end
19
+
20
+ def get(url, &block)
21
+ @pages << Page.new(:get, url, block || {})
22
+ end
23
+
24
+ def post(url, params = nil, &block)
25
+ @pages << Page.new(:post, url, params || block)
26
+ end
27
+
28
+ def login
29
+ pages_before = @pages.size
30
+ if block_given?
31
+ yield
32
+ pages_added = @pages.size - pages_before
33
+ @login = pages.slice! pages_before, pages_added
34
+ end
35
+
36
+ @login ||= []
37
+ end
38
+
39
+ def ==(other)
40
+ other.is_a?(Configuration) &&
41
+ other.pages == pages &&
42
+ other.concurrency == concurrency &&
43
+ other.iterations == iterations
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,14 @@
1
+ module Trample
2
+ module Logging
3
+ def logger
4
+ init_logger if Log4r::Logger['main'].nil?
5
+ Log4r::Logger['main']
6
+ end
7
+
8
+ protected
9
+ def init_logger
10
+ logger = Log4r::Logger.new('main')
11
+ logger.outputters = Log4r::Outputter.stdout
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,39 @@
1
+ module Trample
2
+ class Page
3
+ attr_reader :request_method
4
+
5
+ def initialize(request_method, url, parameters = {})
6
+ @request_method = request_method
7
+ @url = url
8
+ @parameters = parameters
9
+ end
10
+
11
+ def parameters
12
+ proc_params? ? @parameters.call : @parameters
13
+ end
14
+
15
+ def ==(other)
16
+ other.is_a?(Page) &&
17
+ other.request_method == request_method &&
18
+ other.url == url
19
+ end
20
+
21
+ def url
22
+ proc_params? ? interpolated_url : @url
23
+ end
24
+
25
+ protected
26
+ def proc_params?
27
+ @parameters.is_a?(Proc)
28
+ end
29
+
30
+ def interpolated_url
31
+ params = parameters # cache called proc
32
+ url = @url.dup
33
+ url.scan(/\:[A-Za-z_]\w+/).each do |m|
34
+ url.gsub!(m, params[m.gsub(/:/, '').to_sym].to_s)
35
+ end
36
+ url
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,28 @@
1
+ module Trample
2
+ class Runner
3
+ include Logging
4
+
5
+ attr_reader :config, :threads
6
+
7
+ def initialize(config)
8
+ @config = config
9
+ @threads = []
10
+ end
11
+
12
+ def trample
13
+ logger.info "Starting trample..."
14
+
15
+ config.concurrency.times do
16
+ thread = Thread.new(@config) do |c|
17
+ Session.new(c).trample
18
+ end
19
+ threads << thread
20
+ end
21
+
22
+ threads.each { |t| t.join }
23
+
24
+ logger.info "Trample completed..."
25
+ end
26
+ end
27
+ end
28
+
@@ -0,0 +1,56 @@
1
+ module Trample
2
+ class Session
3
+ include Logging
4
+ include Timer
5
+
6
+ attr_reader :config, :response_times, :cookies, :last_response
7
+
8
+ def initialize(config)
9
+ @config = config
10
+ @response_times = []
11
+ @cookies = {}
12
+ end
13
+
14
+ def trample
15
+ @config.login.each {|page| hit page} unless @config.login.empty?
16
+ @config.iterations.times do
17
+ @config.pages.each do |p|
18
+ hit p
19
+ end
20
+ end
21
+ end
22
+
23
+ protected
24
+ def hit(page)
25
+ response_times << request(page)
26
+ # this is ugly, but it's the only way that I could get the test to pass
27
+ # because rr keeps a reference to the arguments, not a copy. ah well.
28
+ @cookies = cookies.merge(last_response.cookies)
29
+ logger.info "#{page.request_method.to_s.upcase} #{page.url} #{response_times.last}s #{last_response.code}"
30
+ end
31
+
32
+ def request(page)
33
+ time do
34
+ @last_response = send(page.request_method, page)
35
+ end
36
+ end
37
+
38
+ def get(page)
39
+ RestClient.get(page.url, :cookies => cookies)
40
+ end
41
+
42
+ def post(page)
43
+ params = page.parameters
44
+ if authenticity_token = parse_authenticity_token(@last_response)
45
+ params.merge!(:authenticity_token => authenticity_token)
46
+ end
47
+ RestClient.post(page.url, params, :cookies => cookies)
48
+ end
49
+
50
+ def parse_authenticity_token(html)
51
+ return nil if html.nil?
52
+ input = Hpricot(html).at("input[@name='authenticity_token']")
53
+ input.nil? ? nil : input['value']
54
+ end
55
+ end
56
+ end
@@ -0,0 +1,9 @@
1
+ module Trample
2
+ module Timer
3
+ def time
4
+ start = Time.now
5
+ yield
6
+ Time.now.to_f - start.to_f
7
+ end
8
+ end
9
+ end
data/test/cli_test.rb ADDED
@@ -0,0 +1,17 @@
1
+ require 'test_helper'
2
+
3
+ class CliTest < Test::Unit::TestCase
4
+ context "Running the CLI" do
5
+ setup do
6
+ Trample::Cli.new.start('test/fixtures/basic_config.rb')
7
+ end
8
+
9
+ before_should "start a trample with the current_config" do
10
+ load('test/fixtures/basic_config.rb')
11
+ stub.proxy(Trample::Runner).new(Trample.current_configuration) do |r|
12
+ mock(r).trample
13
+ r
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,79 @@
1
+ require 'test_helper'
2
+
3
+ class ConfigurationTest < Test::Unit::TestCase
4
+ context "Configuring trample" do
5
+ setup do
6
+ @params_proc = lambda { { :q => "the meaning of life" } }
7
+ @config = Trample::Configuration.new do
8
+ concurrency 2
9
+ iterations 1
10
+ get "http://google.com/" do
11
+ {:a => 'b'}
12
+ end
13
+ post "http://google.com/", {:q => "something"}
14
+ post "http://google.com/", &@params_proc
15
+ login do
16
+ get "http://google.com"
17
+ post "http://google.com/login" do
18
+ { :q => "whatever" }
19
+ end
20
+ end
21
+ end
22
+ end
23
+
24
+ should "set concurrency" do
25
+ assert_equal 2, @config.concurrency
26
+ end
27
+
28
+ should "set iterations" do
29
+ assert_equal 1, @config.iterations
30
+ end
31
+
32
+ should "add get requests to an array of pages" do
33
+ assert_equal Trample::Page.new(:get, "http://google.com/"), @config.pages.first
34
+ end
35
+
36
+ should "add get params to the array of pages" do
37
+ assert_equal({:a => "b"}, @config.pages.first.parameters)
38
+ end
39
+
40
+ should "add post requests to the array of pages, including their params" do
41
+ expected = Trample::Page.new(:post, "http://google.com/", {:q => "something"})
42
+ assert_equal expected, @config.pages[1]
43
+ end
44
+
45
+ should "add post requests to the array of pages, including their block-based params" do
46
+ expected = Trample::Page.new(:post, "http://google.com/", @params_proc)
47
+ assert_equal expected, @config.pages[2]
48
+ end
49
+
50
+ should "support a login parameter which contains pages to hit for authentication" do
51
+ assert_equal ["http://google.com", "http://google.com/login"], @config.login.map{|page| page.url}
52
+ end
53
+
54
+ should "support a login parameter which contains a page to hit with params" do
55
+ assert_equal({:q => "whatever"}, @config.login.last.parameters)
56
+ end
57
+
58
+ should "be equal if all the objects are the same" do
59
+ identical_config = Trample::Configuration.new do
60
+ concurrency 2
61
+ iterations 1
62
+ get "http://google.com/"
63
+ post "http://google.com/", {:q => "something"}
64
+ post "http://google.com/", &@params_proc
65
+ end
66
+ assert_equal identical_config, @config
67
+ end
68
+
69
+ should "not be equal if any of the objects are different" do
70
+ non_identical_config = Trample::Configuration.new do
71
+ concurrency 3
72
+ iterations 1
73
+ get "http://google.com/"
74
+ end
75
+ assert_not_equal non_identical_config, @config
76
+ end
77
+ end
78
+ end
79
+
@@ -0,0 +1,5 @@
1
+ Trample.configure do |t|
2
+ concurrency 2
3
+ iterations 1
4
+ get "http://google.com"
5
+ end
@@ -0,0 +1,9 @@
1
+ require 'test_helper'
2
+
3
+ class TrampleASingleUrlTest < Test::Unit::TestCase
4
+ def test_trampling_a_single_url
5
+ mock_get("http://google.com", :times => 2)
6
+ trample "test/fixtures/basic_config.rb"
7
+ end
8
+ end
9
+
@@ -0,0 +1,16 @@
1
+ require 'test_helper'
2
+
3
+ class LoggingTest < Test::Unit::TestCase
4
+ context "The logging module" do
5
+ setup do
6
+ @object = Class.new do
7
+ include Trample::Logging
8
+ end.new
9
+ @object.send(:init_logger)
10
+ end
11
+
12
+ should "return Log4r::Logger['main'] for #logger" do
13
+ assert_equal Log4r::Logger['main'], @object.logger
14
+ end
15
+ end
16
+ end
data/test/page_test.rb ADDED
@@ -0,0 +1,69 @@
1
+ require 'test_helper'
2
+
3
+ class PageTest < Test::Unit::TestCase
4
+ context "A page" do
5
+ setup do
6
+ @page = Trample::Page.new(:get, "http://google.com/", :username => "joetheuser")
7
+ end
8
+
9
+ should "have a request_method" do
10
+ assert_equal :get, @page.request_method
11
+ end
12
+
13
+ should "have a url" do
14
+ assert_equal "http://google.com/", @page.url
15
+ end
16
+
17
+ should "have request parameters" do
18
+ assert_equal({:username => "joetheuser"}, @page.parameters)
19
+ end
20
+
21
+ should "be equal with the same request_method and url" do
22
+ assert_equal Trample::Page.new(:get, "http://google.com"), Trample::Page.new(:get, "http://google.com")
23
+ end
24
+
25
+ should "not be equal with a different request_method or url" do
26
+ assert_not_equal Trample::Page.new(:get, "http://google.com"), Trample::Page.new(:get, "http://google.com/asdf")
27
+ end
28
+ end
29
+
30
+ context "Block-based request parameters for POST requests" do
31
+ setup do
32
+ @page = Trample::Page.new(:post, "http://google.com/:id", lambda { { :id => 1, :username => "joetheuser" } })
33
+ end
34
+
35
+ should "be resolved at call time" do
36
+ assert_equal({:username => "joetheuser", :id => 1}, @page.parameters)
37
+ end
38
+
39
+ should "interpolate parameters into the url" do
40
+ assert_equal "http://google.com/1", @page.url
41
+ end
42
+
43
+ should "not interpolate the port number if there is one" do
44
+ page = Trample::Page.new(:post, "http://localhost:3000/:id", lambda { { :id => 1, :username => "joetheuser" } })
45
+ assert_equal "http://localhost:3000/1", page.url
46
+ end
47
+ end
48
+
49
+ context "Block based parameters for GET requests" do
50
+ setup do
51
+ @page = Trample::Page.new(:get, "http://mysite.com/somethings/:id", lambda { {:id => 5} })
52
+ end
53
+
54
+ should "interpolate those parameters with the url string" do
55
+ assert_equal "http://mysite.com/somethings/5", @page.url
56
+ end
57
+
58
+ should "interpolate a different parameter each time" do
59
+ page = Trample::Page.new(:get, "http://mysite.com/somethings/:id", lambda { {:id => rand(10)} })
60
+ assert_not_equal page.url, page.url
61
+ end
62
+
63
+ should "not interpolate the port number if there is one" do
64
+ page = Trample::Page.new(:get, "http://mysite.com:8080/somethings/:id", lambda { {:id => 5} })
65
+ assert_equal "http://mysite.com:8080/somethings/5", page.url
66
+ end
67
+ end
68
+ end
69
+
@@ -0,0 +1,35 @@
1
+ require 'test_helper'
2
+
3
+ class RunnerTest < Test::Unit::TestCase
4
+ def setup
5
+ @config = Trample::Configuration.new do |t|
6
+ t.concurrency 2
7
+ t.iterations 5
8
+ end
9
+ end
10
+
11
+ context "Running a trample" do
12
+ setup do
13
+ @runner = Trample::Runner.new(@config)
14
+ @runner.trample
15
+ end
16
+
17
+ before_should "spawn <concurrency> threads" do
18
+ mock.proxy(Thread).new(@config).times(2)
19
+ end
20
+
21
+ before_should "start <concurrency> sessions trampling" do
22
+ stub.proxy(Trample::Session).new(@config).times(2) do |s|
23
+ mock(s).trample
24
+ s
25
+ end
26
+ end
27
+
28
+ before_should "block until all the threads terminate" do
29
+ stub.proxy(Thread).new(@config) do |t|
30
+ mock(t).join
31
+ t
32
+ end
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,102 @@
1
+ require 'test_helper'
2
+
3
+ class SessionTest < Test::Unit::TestCase
4
+ def setup
5
+ @config = Trample::Configuration.new do
6
+ iterations 2
7
+ get "http://google.com/"
8
+ get "http://amazon.com/"
9
+ post "http://google.com/"
10
+ end
11
+ @session = Trample::Session.new(@config)
12
+ end
13
+
14
+ context "Starting a trample session" do
15
+ setup do
16
+ @session.trample
17
+ end
18
+
19
+ before_should "visit the pages iterations times each" do
20
+ mock_get("http://google.com/", :times => 2)
21
+ mock_get("http://amazon.com/", :times => 2)
22
+ mock_post("http://google.com/", :times => 2)
23
+ end
24
+ end
25
+
26
+ context "Visiting a page" do
27
+ setup do
28
+ stub(@session).time { 1.4 }
29
+ stub(@session).last_response do
30
+ response = RestClient::Response.new("", stub!)
31
+ stub(response).cookies { {} }
32
+ stub(response).code { 200 }
33
+ end
34
+ @session.trample
35
+ end
36
+
37
+ should "record the length of time it took to visit that page" do
38
+ assert_equal [1.4, 1.4, 1.4, 1.4, 1.4, 1.4], @session.response_times
39
+ end
40
+ end
41
+
42
+ context "If a page responds with a cookie" do
43
+ should "pass that cookie on to the next page" do
44
+ stub(RestClient).get(anything, anything) do
45
+ response = RestClient::Response.new("", stub!)
46
+ stub(response).cookies { {"xyz" => "abc"} }
47
+ stub(response).code { 200 }
48
+ end
49
+
50
+ @config = Trample::Configuration.new do
51
+ iterations 2
52
+ get "http://amazon.com/"
53
+ end
54
+
55
+ @session = Trample::Session.new(@config)
56
+ @session.trample
57
+
58
+ assert_received(RestClient) { |c| c.get("http://amazon.com/", :cookies => {"xyz" => "abc"}) }
59
+ end
60
+ end
61
+
62
+ context "A session with login" do
63
+ # TODO: the order of the requests isn't being tested here. not
64
+ # sure if it's possible with rr
65
+ should "hit the login once at the beginning of the session" do
66
+ @config = Trample::Configuration.new do
67
+ iterations 2
68
+ login do
69
+ post "http://google.com/login" do
70
+ {:user => "xyz", :password => "swordfish"}
71
+ end
72
+ end
73
+ get "http://google.com/"
74
+ end
75
+ stub_get(anything, :times => 2)
76
+ mock_post("http://google.com/login", :payload => {:user => "xyz", :password => "swordfish"}, :times => 1)
77
+ Trample::Session.new(@config).trample
78
+ end
79
+ end
80
+
81
+ context "Testing a site with forgery protection enabled" do
82
+ should "pass the authenticity token in the login POST params" do
83
+ @config = Trample::Configuration.new do
84
+ iterations 1
85
+ login do
86
+ get "http://google.com"
87
+ post "http://google.com/login" do
88
+ {:user => "xyz", :password => "swordfish"}
89
+ end
90
+ end
91
+ end
92
+ stub(RestClient).get(anything, anything) do
93
+ response = "<input type='hidden' value='abc' name='authenticity_token'/>"
94
+ stub(response).cookies { {} }
95
+ stub(response).code { 200 }
96
+ end
97
+ mock_post("http://google.com/login", :payload => {:user => "xyz", :password => "swordfish", :authenticity_token => 'abc'}, :times => 1)
98
+ Trample::Session.new(@config).trample
99
+ end
100
+ end
101
+ end
102
+
@@ -0,0 +1,43 @@
1
+ require 'rubygems'
2
+ require 'test/unit'
3
+ require 'shoulda'
4
+ require 'rr'
5
+
6
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
7
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
8
+ require 'trample'
9
+
10
+ class Test::Unit::TestCase
11
+ include RR::Adapters::TestUnit unless include?(RR::Adapters::TestUnit)
12
+
13
+ protected
14
+ def trample(config)
15
+ Trample::Cli.new.start(config)
16
+ end
17
+
18
+ def mock_get(url, opts={})
19
+ mock(RestClient).get(url, :cookies => opts[:cookies] || {}).times(opts[:times]) do
20
+ response = RestClient::Response.new("", stub!)
21
+ stub(response).cookies { opts[:return_cookies] || {} }
22
+ stub(response).code { 200 }
23
+ end
24
+ end
25
+
26
+ def mock_post(url, opts={})
27
+ mock(RestClient).post(url, opts[:payload],
28
+ :cookies => opts[:cookies] || {}).times(opts[:times]) do
29
+ response = RestClient::Response.new("", stub!)
30
+ stub(response).cookies { opts[:return_cookies] || {} }
31
+ stub(response).code { 200 }
32
+ end
33
+ end
34
+
35
+ def stub_get(url, opts = {})
36
+ stub(RestClient).get(url, :cookies => opts[:cookies] || {}).times(opts[:times]) do
37
+ response = RestClient::Response.new("", stub!)
38
+ stub(response).cookies { opts[:return_cookies] || {} }
39
+ stub(response).code { 200 }
40
+ end
41
+ end
42
+ end
43
+
@@ -0,0 +1,23 @@
1
+ require 'test_helper'
2
+
3
+ class TimerTest < Test::Unit::TestCase
4
+ context "Timing the execution of a block" do
5
+ setup do
6
+ now = Time.now
7
+ invocations = 0
8
+ stub(Time).now do
9
+ invocations += 1
10
+ # not sure why we have to start at 1,
11
+ # but this seems to get called somewhere
12
+ invocations == 2 ? now : (now + 1.5)
13
+ end
14
+
15
+ @obj = Class.new { include Trample::Timer }.new
16
+ end
17
+
18
+ should "return the amount of time elapsed while the block was run" do
19
+ assert_equal(1.5, @obj.time {})
20
+ end
21
+ end
22
+ end
23
+
@@ -0,0 +1,16 @@
1
+ require 'test_helper'
2
+
3
+ class TrampleTest < Test::Unit::TestCase
4
+ context "Configuring Trample" do
5
+ setup do
6
+ Trample.configure do |t|
7
+ t.concurrency 5
8
+ t.iterations 1
9
+ end
10
+ end
11
+
12
+ should "assign the configuration to Trample.current_configuration" do
13
+ assert_equal 5, Trample.current_configuration.concurrency
14
+ end
15
+ end
16
+ end
data/trample.gemspec ADDED
@@ -0,0 +1,75 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ Gem::Specification.new do |s|
4
+ s.name = %q{wgibbs-trample}
5
+ s.version = "0.1.1"
6
+
7
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
8
+ s.authors = ["Wes Gibbs", "James Golick"]
9
+ s.date = %q{2009-10-11}
10
+ s.default_executable = %q{trample}
11
+ s.description = %q{A fork of a better load simulator}
12
+ s.email = %q{wes.gibbs@gmail.com}
13
+ s.executables = ["trample"]
14
+ s.extra_rdoc_files = [
15
+ "LICENSE",
16
+ "README.rdoc"
17
+ ]
18
+ s.files = [
19
+ ".gitignore",
20
+ "LICENSE",
21
+ "README.rdoc",
22
+ "Rakefile",
23
+ "VERSION.yml",
24
+ "bin/trample",
25
+ "lib/trample.rb",
26
+ "lib/trample/cli.rb",
27
+ "lib/trample/configuration.rb",
28
+ "lib/trample/logging.rb",
29
+ "lib/trample/page.rb",
30
+ "lib/trample/runner.rb",
31
+ "lib/trample/session.rb",
32
+ "lib/trample/timer.rb",
33
+ "test/cli_test.rb",
34
+ "test/configuration_test.rb",
35
+ "test/fixtures/basic_config.rb",
36
+ "test/integration/trample_a_single_url_test.rb",
37
+ "test/logging_test.rb",
38
+ "test/page_test.rb",
39
+ "test/runner_test.rb",
40
+ "test/session_test.rb",
41
+ "test/test_helper.rb",
42
+ "test/timer_test.rb",
43
+ "test/trample_test.rb",
44
+ "trample.gemspec"
45
+ ]
46
+ s.has_rdoc = true
47
+ s.homepage = %q{http://wgibbs.github.com/2009/10/15/trample-fork.html}
48
+ s.rdoc_options = ["--charset=UTF-8"]
49
+ s.require_paths = ["lib"]
50
+ s.rubygems_version = %q{1.3.1}
51
+ s.summary = %q{A fork of a better load simulator}
52
+ s.test_files = [
53
+ "test/cli_test.rb",
54
+ "test/configuration_test.rb",
55
+ "test/fixtures/basic_config.rb",
56
+ "test/integration/trample_a_single_url_test.rb",
57
+ "test/logging_test.rb",
58
+ "test/page_test.rb",
59
+ "test/runner_test.rb",
60
+ "test/session_test.rb",
61
+ "test/test_helper.rb",
62
+ "test/timer_test.rb",
63
+ "test/trample_test.rb"
64
+ ]
65
+
66
+ if s.respond_to? :specification_version then
67
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
68
+ s.specification_version = 2
69
+
70
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
71
+ else
72
+ end
73
+ else
74
+ end
75
+ end
metadata ADDED
@@ -0,0 +1,92 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: wgibbs-trample
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.1
5
+ platform: ruby
6
+ authors:
7
+ - Wes Gibbs
8
+ - James Golick
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+
13
+ date: 2009-10-11 00:00:00 -04:00
14
+ default_executable: trample
15
+ dependencies: []
16
+
17
+ description: A fork of a better load simulator
18
+ email: wes.gibbs@gmail.com
19
+ executables:
20
+ - trample
21
+ extensions: []
22
+
23
+ extra_rdoc_files:
24
+ - LICENSE
25
+ - README.rdoc
26
+ files:
27
+ - .gitignore
28
+ - LICENSE
29
+ - README.rdoc
30
+ - Rakefile
31
+ - VERSION.yml
32
+ - bin/trample
33
+ - lib/trample.rb
34
+ - lib/trample/cli.rb
35
+ - lib/trample/configuration.rb
36
+ - lib/trample/logging.rb
37
+ - lib/trample/page.rb
38
+ - lib/trample/runner.rb
39
+ - lib/trample/session.rb
40
+ - lib/trample/timer.rb
41
+ - test/cli_test.rb
42
+ - test/configuration_test.rb
43
+ - test/fixtures/basic_config.rb
44
+ - test/integration/trample_a_single_url_test.rb
45
+ - test/logging_test.rb
46
+ - test/page_test.rb
47
+ - test/runner_test.rb
48
+ - test/session_test.rb
49
+ - test/test_helper.rb
50
+ - test/timer_test.rb
51
+ - test/trample_test.rb
52
+ - trample.gemspec
53
+ has_rdoc: true
54
+ homepage: http://wgibbs.github.com/2009/10/15/trample-fork.html
55
+ licenses: []
56
+
57
+ post_install_message:
58
+ rdoc_options:
59
+ - --charset=UTF-8
60
+ require_paths:
61
+ - lib
62
+ required_ruby_version: !ruby/object:Gem::Requirement
63
+ requirements:
64
+ - - ">="
65
+ - !ruby/object:Gem::Version
66
+ version: "0"
67
+ version:
68
+ required_rubygems_version: !ruby/object:Gem::Requirement
69
+ requirements:
70
+ - - ">="
71
+ - !ruby/object:Gem::Version
72
+ version: "0"
73
+ version:
74
+ requirements: []
75
+
76
+ rubyforge_project:
77
+ rubygems_version: 1.3.5
78
+ signing_key:
79
+ specification_version: 2
80
+ summary: A fork of a better load simulator
81
+ test_files:
82
+ - test/cli_test.rb
83
+ - test/configuration_test.rb
84
+ - test/fixtures/basic_config.rb
85
+ - test/integration/trample_a_single_url_test.rb
86
+ - test/logging_test.rb
87
+ - test/page_test.rb
88
+ - test/runner_test.rb
89
+ - test/session_test.rb
90
+ - test/test_helper.rb
91
+ - test/timer_test.rb
92
+ - test/trample_test.rb