Class: GasLoadTester::Test
- Inherits:
-
Object
- Object
- GasLoadTester::Test
- Defined in:
- lib/gas_load_tester/test.rb
Constant Summary collapse
- DEFAULT =
{ client: 1000, time: 300 }
Instance Attribute Summary collapse
-
#client ⇒ Object
Returns the value of attribute client.
-
#results ⇒ Object
Returns the value of attribute results.
-
#time ⇒ Object
Returns the value of attribute time.
Instance Method Summary collapse
- #export_file(args = {}) ⇒ Object
-
#initialize(args = {}) ⇒ Test
constructor
A new instance of Test.
- #is_run? ⇒ Boolean
- #request_per_second ⇒ Object
- #run(args = {}, &block) ⇒ Object
- #summary_avg_time ⇒ Object
- #summary_error ⇒ Object
- #summary_max_time ⇒ Object
- #summary_min_time ⇒ Object
- #summary_success ⇒ Object
Constructor Details
#initialize(args = {}) ⇒ Test
Returns a new instance of Test.
13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/gas_load_tester/test.rb', line 13 def initialize(args = {}) args ||= {} args[:client] ||= args['client'] args[:time] ||= args['time'] args.reject!{|key, value| value.nil? } args = DEFAULT.merge(args) self.client = args[:client] self.time = args[:time] self.results = {} @run = false end |
Instance Attribute Details
#client ⇒ Object
Returns the value of attribute client.
6 7 8 |
# File 'lib/gas_load_tester/test.rb', line 6 def client @client end |
#results ⇒ Object
Returns the value of attribute results.
6 7 8 |
# File 'lib/gas_load_tester/test.rb', line 6 def results @results end |
#time ⇒ Object
Returns the value of attribute time.
6 7 8 |
# File 'lib/gas_load_tester/test.rb', line 6 def time @time end |
Instance Method Details
#export_file(args = {}) ⇒ Object
55 56 57 58 59 60 61 |
# File 'lib/gas_load_tester/test.rb', line 55 def export_file(args = {}) args ||= {} file = args[:file_name] || '' chart_builder = GasLoadTester::ChartBuilder.new(file_name: file) chart_builder.build_body(self) chart_builder.save end |
#is_run? ⇒ Boolean
47 48 49 |
# File 'lib/gas_load_tester/test.rb', line 47 def is_run? @run end |
#request_per_second ⇒ Object
51 52 53 |
# File 'lib/gas_load_tester/test.rb', line 51 def request_per_second self.client/self.time.to_f end |
#run(args = {}, &block) ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/gas_load_tester/test.rb', line 26 def run(args = {}, &block) args ||= {} args[:output] ||= args['output'] args[:file_name] ||= args['file_name'] puts "Running test (client: #{self.client}, time: #{self.time})" @progressbar = ProgressBar.create( :title => "Load test", :starting_at => 0, :total => self.time+10, :format => "%a %b\u{15E7}%i %p%% %t", :progress_mark => ' ', :remainder_mark => "\u{FF65}" ) load_test(block) if args[:output] export_file({file_name: args[:file_name]}) end ensure @run = true end |
#summary_avg_time ⇒ Object
71 72 73 |
# File 'lib/gas_load_tester/test.rb', line 71 def summary_avg_time all_result_time.sum.fdiv(all_result_time.size)*1000 end |
#summary_error ⇒ Object
79 80 81 |
# File 'lib/gas_load_tester/test.rb', line 79 def summary_error self.results.collect{|key, values| values.select{|val| !val.pass }.count }.flatten.sum end |
#summary_max_time ⇒ Object
67 68 69 |
# File 'lib/gas_load_tester/test.rb', line 67 def summary_max_time all_result_time.sort.last*1000 end |
#summary_min_time ⇒ Object
63 64 65 |
# File 'lib/gas_load_tester/test.rb', line 63 def summary_min_time all_result_time.sort.first*1000 end |
#summary_success ⇒ Object
75 76 77 |
# File 'lib/gas_load_tester/test.rb', line 75 def summary_success self.results.collect{|key, values| values.select{|val| val.pass }.count }.flatten.sum end |