Class: Kronk::Player::Suite
- Inherits:
-
Kronk::Player
- Object
- QueueRunner
- Kronk::Player
- Kronk::Player::Suite
- Defined in:
- lib/kronk/player/suite.rb
Overview
Outputs Player requests and results in a test-suite like format.
Instance Attribute Summary
Attributes inherited from Kronk::Player
#concurrency, #input, #mutex, #qps
Attributes inherited from QueueRunner
#count, #number, #queue, #reader_thread, #threads
Instance Method Summary collapse
- #complete ⇒ Object
- #error(err, kronk = nil) ⇒ Object
- #render ⇒ Object
- #result(kronk) ⇒ Object
- #start ⇒ Object
Methods inherited from Kronk::Player
#compare, #from_io, #initialize, new_type, #request, #run, #trigger_result
Methods inherited from QueueRunner
#concurrently, #finish, #finished?, #initialize, #kill, #on, #periodically, #start_input!, #stop_input!, #trigger, #until_finished, #yield_queue_item
Constructor Details
This class inherits a constructor from Kronk::Player
Instance Method Details
#complete ⇒ Object
84 85 86 87 88 |
# File 'lib/kronk/player/suite.rb', line 84 def complete trap 29, @old_info_trap $stdout.puts "\nFinished in #{Time.now - @start_time} seconds.\n" render end |
#error(err, kronk = nil) ⇒ Object
74 75 76 77 78 79 80 81 |
# File 'lib/kronk/player/suite.rb', line 74 def error err, kronk=nil status = "E" result = [status, 0, 0, error_text(err, kronk)] @mutex.synchronize{ @results << result } $stdout << status $stdout.flush end |
#render ⇒ Object
91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 |
# File 'lib/kronk/player/suite.rb', line 91 def render player_time = @stop_time - @start_time total_time = 0 total_ctime = 0 bad_count = 0 failure_count = 0 error_count = 0 err_buffer = "" @results.each do |(status, time, ctime, text)| case status when "F" total_time += time.to_f total_ctime += ctime.to_f bad_count += 1 failure_count += 1 err_buffer << "\n #{bad_count}) Failure:\n#{text}" when "E" bad_count += 1 error_count += 1 err_buffer << "\n #{bad_count}) Error:\n#{text}" else total_time += time.to_f total_ctime += ctime.to_f end end non_error_count = @results.length - error_count avg_time = non_error_count > 0 ? ((total_time / non_error_count)* 1000).round(3) : "n/a " avg_ctime = non_error_count > 0 ? ((total_ctime / non_error_count)* 1000).round(3) : "n/a " avg_qps = non_error_count > 0 ? (non_error_count / player_time).round(3) : "n/a" $stderr.puts err_buffer unless err_buffer.empty? $stdout.puts "\n#{@results.length} cases, " + "#{failure_count} failures, #{error_count} errors" $stdout.puts "Total Conns: #{Kronk::HTTP.total_conn}" $stdout.puts "Avg Conn Time: #{avg_ctime}ms" $stdout.puts "Avg Time: #{avg_time}ms" $stdout.puts "Avg QPS: #{avg_qps}" return bad_count == 0 end |
#result(kronk) ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/kronk/player/suite.rb', line 35 def result kronk status = "." result = if kronk.diff status = "F" if kronk.diff.any? text = diff_text kronk if status == "F" time = (kronk.responses[0].time.to_f + kronk.responses[1].time.to_f) / 2 ctime = (kronk.responses[0].conn_time.to_f + kronk.responses[1].conn_time.to_f) / 2 [status, time, ctime, text] elsif kronk.response begin # Make sure response is parsable kronk.response.parsed_body if kronk.response.parser rescue => e error e, kronk return end if kronk.response.success? status = "F" if !kronk.response.success? text = resp_text kronk if status == "F" [status, kronk.response.time, kronk.response.conn_time, text] end @mutex.synchronize do @current = kronk @results << result end $stdout << status $stdout.flush end |
#start ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/kronk/player/suite.rb', line 8 def start @results = [] @current = nil $stdout.puts "Started" @old_info_trap = trap 29 do @stop_time = Time.now @mutex.synchronize do render $stdout.puts "Elapsed: #{(Time.now - @start_time).round 3}s" req = @current.responses[-1].request || @current.responses[0].request if @current if req meth = req.http_method path = req.uri.request_uri time = req.response.time.round 3 $stdout.puts "Current Conns: #{Kronk::HTTP.conn_count}" $stdout.puts "Current Req: #{meth} #{path} (#{time}s)" end end end end |