Skip to content

Commit 620a2ba

Browse files
author
David Brady
committedSep 2, 2010
***** Version 2.0 Work Begins HERE ****
- Renamed Tour -> Tourist - Renamed test_ methods to tour_ methods - Bumped gemfile version to 0.9.00
1 parent c09e896 commit 620a2ba

File tree

10 files changed

+155
-151
lines changed

10 files changed

+155
-151
lines changed
 

‎TODO

+2
Original file line numberDiff line numberDiff line change
@@ -34,4 +34,6 @@ Tourbus 2.0 Todo
3434
- Make sure this plays well with latest JRuby
3535

3636

37+
runners -> tourist_names
38+
3739

‎bin/tourbus

+9-9
Original file line numberDiff line numberDiff line change
@@ -18,29 +18,29 @@ config[:rand] ||= nil
1818

1919
opts = Trollop.options do
2020
opt :host, "Remote hostname to test", :default => config[:host]
21-
opt :concurrency, "Number of simultaneous runs to perform", :type => :integer, :default => config[:concurrency]
22-
opt :number, "Number of times to run the tour (in each concurrent step, so -c 10 -n 10 will run the tour 100 times)", :type => :integer, :default => config[:number]
23-
opt :list, "List tours and runs available. If tours or runs are included, filters the list", :type => :boolean, :default => nil
21+
opt :concurrency, "Number of simultaneous tourists to run", :type => :integer, :default => config[:concurrency]
22+
opt :number, "Number of times to run the tourist (in each concurrent step, so -c 10 -n 10 will run the tourist 100 times)", :type => :integer, :default => config[:number]
23+
opt :list, "List tourists and tours available. If tourists or tours are included, filters the list", :type => :boolean, :default => nil
2424
opt :rand, "Random seed", :type => :integer, :default => config[:rand]
2525
opt :tests, "Test name(s) filter. The name of the test to run (use --list to see the test names). Use commas, no spaces, for mulitple names", :type => :string, :default => nil
2626
end
2727

28-
tours = if ARGV.empty?
29-
Tour.tours
28+
tourists = if ARGV.empty?
29+
Tourist.tourists
3030
else
3131
ARGV
3232
end
3333

3434
srand opts[:rand] || Time.now.to_i
3535

3636
if opts[:list]
37-
Tour.tours(ARGV).each do |tour|
38-
puts tour
39-
puts Tour.tests(tour).map {|test| " #{test}"}
37+
Tourist.tourists(ARGV).each do |tourist|
38+
puts tourist
39+
puts Tourist.tests(tourist).map {|test| " #{test}"}
4040
end
4141
else
4242
opts[:tests] = opts[:tests].split(',') if opts[:tests]
4343

44-
TourBus.new(opts[:host], opts[:concurrency], opts[:number], tours, opts[:tests]).run
44+
TourBus.new(opts[:host], opts[:concurrency], opts[:number], tourists, opts[:tests]).run
4545
end
4646

‎examples/contact_app/.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
webrat.log

‎examples/contact_app/tours/simple.rb

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1-
class Simple < Tour
2-
def test_home
1+
class Simple < Tourist
2+
def tour_home
33
visit "#{@host}/"
44
assert_contain "If you click this"
55

66
click_link "Enter Contact"
77
assert_match /\/contacts/, current_url
88
end
99

10-
def test_contacts
10+
def tour_contacts
1111
visit "/contacts"
1212

1313
fill_in "first_name", :with => "Joe"

‎lib/common.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
require 'faker'
2020
require 'tour_bus'
2121
require 'runner'
22-
require 'tour'
22+
require 'tourist'
2323

2424
class TourBusException < Exception; end
2525

‎lib/runner.rb

+24-24
Original file line numberDiff line numberDiff line change
@@ -5,36 +5,36 @@
55
class WebratError < StandardError ; end
66

77
class Runner
8-
attr_reader :host, :tours, :number, :runner_type, :runner_id
8+
attr_reader :host, :tourists, :number, :runner_type, :runner_id
99

10-
def initialize(host, tours, number, runner_id, test_list)
11-
@host, @tours, @number, @runner_id, @test_list = host, tours, number, runner_id, test_list
10+
def initialize(host, tourists, number, runner_id, tour_list)
11+
@host, @tourists, @number, @runner_id, @tour_list = host, tourists, number, runner_id, tour_list
1212
@runner_type = self.send(:class).to_s
1313
log("Ready to run #{@runner_type}")
1414
end
1515

1616
# Dispatches to subclass run method
17-
def run_tours
18-
log "Filtering on tests #{@test_list.join(', ')}" unless @test_list.to_a.empty?
19-
tours,tests,passes,fails,errors = 0,0,0,0,0
17+
def run_tourists
18+
log "Filtering on tours #{@tour_list.join(', ')}" unless @tour_list.to_a.empty?
19+
tourists,tours,passes,fails,errors = 0,0,0,0,0
2020
1.upto(number) do |num|
2121
log("Starting #{@runner_type} run #{num}/#{number}")
22-
@tours.each do |tour_name|
22+
@tourists.each do |tourist_name|
2323

24-
log("Starting run #{num}/#{number} of Tour #{tour_name}")
25-
tours += 1
26-
tour = Tour.make_tour(tour_name,@host,@tours,@number,@runner_id)
27-
tour.before_tour
24+
log("Starting run #{num}/#{number} of Tourist #{tourist_name}")
25+
tourists += 1
26+
tourist = Tourist.make_tourist(tourist_name,@host,@tourists,@number,@runner_id)
27+
tourist.before_tours
2828

29-
tour.tests.each do |test|
29+
tourist.tours.each do |tour|
3030
times = Hash.new {|h,k| h[k] = {}}
3131

32-
next if test_limited_to(test) # test_list && !test_list.empty? && !test_list.include?(test.to_s)
32+
next if tour_limited_to(tour)
3333

3434
begin
35-
tests += 1
36-
times[test][:started] = Time.now
37-
tour.run_test test
35+
tours += 1
36+
times[tour][:started] = Time.now
37+
tourist.run_tour tour
3838
passes += 1
3939
rescue TourBusException, WebratError => e
4040
log("********** FAILURE IN RUN! **********")
@@ -53,18 +53,18 @@ def run_tours
5353
end
5454
errors += 1
5555
ensure
56-
times[test][:finished] = Time.now
57-
times[test][:elapsed] = times[test][:finished] - times[test][:started]
56+
times[tour][:finished] = Time.now
57+
times[tour][:elapsed] = times[tour][:finished] - times[tour][:started]
5858
end
59-
log("Finished run #{num}/#{number} of Tour #{tour_name}")
59+
log("Finished run #{num}/#{number} of Tourist #{tourist_name}")
6060
end
6161

62-
tour.after_tour
62+
tourist.after_tours
6363
end
6464
log("Finished #{@runner_type} run #{num}/#{number}")
6565
end
66-
log("Finished all #{@runner_type} tours.")
67-
[tours,tests,passes,fails,errors]
66+
log("Finished all #{@runner_type} tourists.")
67+
[tourists,tours,passes,fails,errors]
6868
end
6969

7070
protected
@@ -73,8 +73,8 @@ def log(message)
7373
puts "#{Time.now.strftime('%F %H:%M:%S')} Runner ##{@runner_id}: #{message}"
7474
end
7575

76-
def test_limited_to(test_name)
77-
@test_list && !@test_list.empty? && !@test_list.include?(test_name.to_s)
76+
def tour_limited_to(tour_name)
77+
@tour_list && !@tour_list.empty? && !@tour_list.include?(tour_name.to_s)
7878
end
7979
end
8080

‎lib/tour.rb

-100
This file was deleted.

‎lib/tour_bus.rb

+10-10
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
require 'benchmark'
22

33
class TourBus < Monitor
4-
attr_reader :host, :concurrency, :number, :tours, :runs, :tests, :passes, :fails, :errors, :benchmarks
4+
attr_reader :host, :concurrency, :number, :tourists, :runs, :tests, :passes, :fails, :errors, :benchmarks
55

6-
def initialize(host="localhost", concurrency=1, number=1, tours=[], test_list=nil)
7-
@host, @concurrency, @number, @tours, @test_list = host, concurrency, number, tours, test_list
6+
def initialize(host="localhost", concurrency=1, number=1, tourists=[], test_list=nil)
7+
@host, @concurrency, @number, @tourists, @test_list = host, concurrency, number, tourists, test_list
88
@runner_id = 0
99
@runs, @tests, @passes, @fails, @errors = 0,0,0,0,0
1010
super()
@@ -38,18 +38,18 @@ def runners(filter=[])
3838
end
3939

4040
def total_runs
41-
tours.size * concurrency * number
41+
tourists.size * concurrency * number
4242
end
4343

4444
def run
4545
threads = []
4646
threads_ready = 0
4747
start_running = false
4848
mutex = Mutex.new
49-
tour_name = "#{total_runs} runs: #{concurrency}x#{number} of #{tours * ','}"
49+
tourist_name = "#{total_runs} runs: #{concurrency}x#{number} of #{tourists * ','}"
5050
started = Time.now.to_f
5151
concurrency.times do |conc|
52-
log "Starting #{tour_name}"
52+
log "Starting #{tourist_name}"
5353
threads << Thread.new do
5454
runner_id = next_runner_id
5555
mutex.lock
@@ -62,8 +62,8 @@ def run
6262
sleep 0.05 until start_running
6363
runs,tests,passes,fails,errors,start = 0,0,0,0,0,Time.now.to_f
6464
bm = Benchmark.measure do
65-
runner = Runner.new(@host, @tours, @number, runner_id, @test_list)
66-
runs,tests,passes,fails,errors = runner.run_tours
65+
runner = Runner.new(@host, @tourists, @number, runner_id, @test_list)
66+
runs,tests,passes,fails,errors = runner.run_tourists
6767
update_stats runs, tests, passes, fails, errors
6868
end
6969
log "Runner Finished!"
@@ -76,9 +76,9 @@ def run
7676
threads.each {|t| t.join }
7777
finished = Time.now.to_f
7878
log '-' * 80
79-
log tour_name
79+
log tourist_name
8080
log "All Runners finished."
81-
log "Total Tours: #{@runs}"
81+
log "Total Tourists: #{@runs}"
8282
log "Total Tests: #{@tests}"
8383
log "Total Passes: #{@passes}"
8484
log "Total Fails: #{@fails}"

0 commit comments

Comments
 (0)
Please sign in to comment.