Class: Stella::Testplan
- Inherits:
-
Object
- Object
- Stella::Testplan
- Includes:
- Gibbler::Complex
- Defined in:
- lib/stella/testplan.rb,
lib/stella/testplan/stats.rb,
lib/stella/testplan/usecase.rb
Defined Under Namespace
Classes: Stats, Usecase, WackyRatio
Instance Attribute Summary collapse
-
#base_path ⇒ Object
Returns the value of attribute base_path.
-
#desc(*args) ⇒ Object
Returns the value of attribute desc.
-
#stats ⇒ Object
readonly
Returns the value of attribute stats.
-
#usecases ⇒ Object
Returns the value of attribute usecases.
Class Method Summary collapse
Instance Method Summary collapse
- #add_usecase(uc) ⇒ Object
- #check! ⇒ Object
-
#errors? ⇒ Boolean
Were there any errors in any of the usecases?.
-
#initialize(uris = [], opts = {}) ⇒ Testplan
constructor
A new instance of Testplan.
- #pretty ⇒ Object
- #usecase(*args, &blk) ⇒ Object
- #xusecase(*args, &blk) ⇒ Object
Constructor Details
#initialize(uris = [], opts = {}) ⇒ Testplan
Returns a new instance of Testplan.
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/stella/testplan.rb', line 16 def initialize(uris=[], opts={}) @desc, @usecases = "Stella's plan", [] @testplan_current_ratio = 0 @stats = Stella::Testplan::Stats.new unless uris.empty? usecase = Stella::Testplan::Usecase.new usecase.ratio = 1.0 uris.each do |uri| uri = URI.parse uri uri.path = '/' if uri.path.empty? req = usecase.add_request :get, uri.path req.wait = opts[:delay] if opts[:delay] end self.add_usecase usecase end end |
Instance Attribute Details
#base_path ⇒ Object
Returns the value of attribute base_path.
12 13 14 |
# File 'lib/stella/testplan.rb', line 12 def base_path @base_path end |
#desc(*args) ⇒ Object
Returns the value of attribute desc.
13 14 15 |
# File 'lib/stella/testplan.rb', line 13 def desc @desc end |
#stats ⇒ Object (readonly)
Returns the value of attribute stats.
14 15 16 |
# File 'lib/stella/testplan.rb', line 14 def stats @stats end |
#usecases ⇒ Object
Returns the value of attribute usecases.
11 12 13 |
# File 'lib/stella/testplan.rb', line 11 def usecases @usecases end |
Class Method Details
Instance Method Details
#add_usecase(uc) ⇒ Object
78 79 80 81 82 |
# File 'lib/stella/testplan.rb', line 78 def add_usecase(uc) Stella.ld "Usecase: #{uc.desc}" @usecases << uc uc end |
#check! ⇒ Object
49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/stella/testplan.rb', line 49 def check! # Adjust ratios if necessary needy = @usecases.select { |u| u.ratio == -1 } needy.each do |u| u.ratio = (remaining_ratio / needy.size).to_f end # Give usecases a name if necessary @usecases.each_with_index { |uc,i| uc.desc ||= "Usecase ##{i+1}" } if @testplan_current_ratio > 1.0 msg = "Usecase ratio cannot be higher than 1.0" msg << " (#{@testplan_current_ratio})" raise WackyRatio, msg end end |
#errors? ⇒ Boolean
Were there any errors in any of the usecases?
44 45 46 47 |
# File 'lib/stella/testplan.rb', line 44 def errors? Stella.ld "TODO: tally use case errors" false end |
#pretty ⇒ Object
89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 |
# File 'lib/stella/testplan.rb', line 89 def pretty str = [] str << " %-66s ".att(:reverse) % [@desc] @usecases.each_with_index do |uc,i| description = uc.desc || "Usecase ##{i+1}" str << " %s (%s%%)".bright % [description, uc.ratio_pretty] requests = uc.requests.each do |r| str << " %-35s %s" % ["#{r.desc}:", r] if Stella.loglev > 2 [:wait].each { |i| str << " %s: %s" % [i, r.send(i)] } end end end str.join($/) end |
#usecase(*args, &blk) ⇒ Object
64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/stella/testplan.rb', line 64 def usecase(*args, &blk) return @usecases if args.empty? ratio, name = nil,nil ratio, name = args[0], args[1] if args[0].is_a?(Numeric) ratio, name = args[1], args[0] if args[0].is_a?(String) uc = Stella::Testplan::Usecase.new uc.base_path = @base_path uc.instance_eval &blk uc.ratio, uc.desc = (ratio || -1).to_f, name @testplan_current_ratio += uc.ratio if uc.ratio > 0 add_usecase uc end |