Class: LoadTest
- Inherits:
-
Object
- Object
- LoadTest
- Defined in:
- lib/load/load_test.rb
Constant Summary collapse
- PASSED =
"passed"- FAILED =
"failed"
Instance Attribute Summary collapse
-
#schedule ⇒ Object
Returns the value of attribute schedule.
-
#start_time ⇒ Object
readonly
Returns the value of attribute start_time.
-
#test ⇒ Object
readonly
Returns the value of attribute test.
-
#wasp_id ⇒ Object
readonly
Returns the value of attribute wasp_id.
Instance Method Summary collapse
- #assert(value) ⇒ Object
- #create_logger ⇒ Object
- #current_action ⇒ Object
- #current_action_for_time(millis) ⇒ Object
- #duration_millis ⇒ Object
-
#initialize(owner, run_id, node_id, wasp_id, test, schedule_events, messenger = nil) ⇒ LoadTest
constructor
A new instance of LoadTest.
- #log ⇒ Object
- #perform_test ⇒ Object
- #report_block_result(test_code, wasp_id, ellapsed_millis, benchmark_time, result, target_code = "unknown") ⇒ Object
- #run ⇒ Object
- #run_if_time_right(current_time_millis) ⇒ Object
- #test_code ⇒ Object
- #time_ellapsed_millis ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(owner, run_id, node_id, wasp_id, test, schedule_events, messenger = nil) ⇒ LoadTest
Returns a new instance of LoadTest.
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/load/load_test.rb', line 16 def initialize(owner, run_id, node_id, wasp_id, test, schedule_events, messenger = nil) @owner = owner test.owner = self @schedule = LoadTestSchedule.new @schedule.load_json(schedule_events) @messenger = messenger @node_id = node_id @wasp_id = wasp_id @time_of_last_status_check = 0 @test = test if (run_id == nil) || (run_id == 0) raise "No run_id specified for load test" end test_code = self.class.name @run_id = run_id @name = "Test for #{test.test_code}" end |
Instance Attribute Details
#schedule ⇒ Object
Returns the value of attribute schedule.
14 15 16 |
# File 'lib/load/load_test.rb', line 14 def schedule @schedule end |
#start_time ⇒ Object (readonly)
Returns the value of attribute start_time.
13 14 15 |
# File 'lib/load/load_test.rb', line 13 def start_time @start_time end |
#test ⇒ Object (readonly)
Returns the value of attribute test.
13 14 15 |
# File 'lib/load/load_test.rb', line 13 def test @test end |
#wasp_id ⇒ Object (readonly)
Returns the value of attribute wasp_id.
13 14 15 |
# File 'lib/load/load_test.rb', line 13 def wasp_id @wasp_id end |
Instance Method Details
#assert(value) ⇒ Object
179 180 181 182 183 |
# File 'lib/load/load_test.rb', line 179 def assert(value) if (value == false) raise "Assertion failed" end end |
#create_logger ⇒ Object
39 40 41 42 43 44 45 46 |
# File 'lib/load/load_test.rb', line 39 def create_logger FileUtils.mkdir_p('./log/load') unless File.directory?('./log/load') FileUtils.mkdir_p("./log/load/run_#{@run_id}") unless File.directory?("./log/load/run_#{@run_id}") log_file = "./log/load/run_#{@run_id}/#{@test.class.name}_#{@wasp_id}.log" @logger = Logger.new(log_file) @logger.level = Logger::DEBUG @test.logger = @logger end |
#current_action ⇒ Object
162 163 164 |
# File 'lib/load/load_test.rb', line 162 def current_action return current_action_for_time(time_ellapsed_millis) end |
#current_action_for_time(millis) ⇒ Object
166 167 168 169 |
# File 'lib/load/load_test.rb', line 166 def current_action_for_time(millis) current_action = schedule.current_action(millis / 1000) return current_action end |
#duration_millis ⇒ Object
136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 |
# File 'lib/load/load_test.rb', line 136 def duration_millis last_run_time = nil @schedule.events.each do |event| if (event[:action] == :run) last_run_time = nil else last_run_time = event[:time] end end if (last_run_time == nil) raise "This test never finishes on it's own" end return (last_run_time * 1000) end |
#log ⇒ Object
35 36 37 |
# File 'lib/load/load_test.rb', line 35 def log return @logger end |
#perform_test ⇒ Object
185 186 187 188 189 190 191 |
# File 'lib/load/load_test.rb', line 185 def perform_test @test.owner = self @test.set_up @test.run @test.pause_after_run @test.tear_down end |
#report_block_result(test_code, wasp_id, ellapsed_millis, benchmark_time, result, target_code = "unknown") ⇒ Object
158 159 160 |
# File 'lib/load/load_test.rb', line 158 def report_block_result(test_code, wasp_id, ellapsed_millis, benchmark_time, result, target_code = "unknown") @owner.report_block_result(test_code, wasp_id, ellapsed_millis, benchmark_time, result) end |
#run ⇒ Object
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/load/load_test.rb', line 48 def run create_logger() trap('INT') do puts "Wasp asked to die: #{test_code}:#{@wasp_id} Pid: #{Process.pid}" #log.info "Wasp asked to die: #{test_code}:#{@wasp_id} Pid: #{Process.pid}" exit 0 end begin @start_time = Time.now @exit = false while (!@exit) result = FAILED run_if_time_right(time_ellapsed_millis) end puts "End of run for wasp: #{@wasp_id}. Duration: #{duration_millis}" log.info "End of run. Duration: #{duration_millis}" rescue Interrupt => e log.warn "WASP KILL: #{test_code}:#{@wasp_id} Interrupt signal received, quitting. [#{e.class.name}] #{e.}" puts "WASP KILL: #{test_code}:#{@wasp_id} Interrupt signal received, quitting. [#{e.class.name}] #{e.}" @exit = true rescue Exception => exc log.warn "Exception in wasp: #{@wasp_id} . [#{exc.class.name}] #{exc.}" puts "Exception in wasp: #{@wasp_id} . [#{exc.class.name}] #{exc.}" ensure log.info "Wasp process exiting: #{test_code}:#{@wasp_id} Pid: #{Process.pid}" puts "Wasp process exiting: #{test_code}:#{@wasp_id} Pid: #{Process.pid}" exit 0 end end |
#run_if_time_right(current_time_millis) ⇒ Object
80 81 82 83 84 85 86 87 88 89 90 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 |
# File 'lib/load/load_test.rb', line 80 def run_if_time_right(current_time_millis) benchmark_time = 0 if (current_time_millis >= duration_millis) @exit = true puts "Time for LoadTest instance to die. Ellapsed: #{current_time_millis} Test duration: #{duration_millis}" else current_action = current_action_for_time(current_time_millis) if (current_action == :run) #puts "Time is right. Test being performed" result = PASSED begin benchmark_time = Benchmark.realtime { perform_test } log.info "Test completed normally in #{benchmark_time} seconds" rescue SystemExit => se log.warn "Caught system exit signal. Exiting..." @exit = true rescue Exception => e result = FAILED log.error("Test (#{@test.class}) produced exception: #{e.class} #{e.}") e.backtrace.each do |back| log.error(back) end puts "Test (#{@test.class}) produced exception: #{e.class} #{e.} #{e.backtrace}" end custom_timing = @test.timing if (custom_timing != nil) benchmark_time = custom_timing end @messenger.report_result(@run_id, @node_id, @test.test_code, @wasp_id, current_time_millis, benchmark_time, result) else #puts "Not running test. current_action = #{current_action}" sleep 0.2 end if (@exit == false) time_since_last_status_check = current_time_millis - @time_of_last_status_check if (time_since_last_status_check > 20*1000) @time_of_last_status_check = current_time_millis status = @messenger.status_for_test(@run_id, @wasp_id) if (status['run_status'] == "killed") log.warn "XXXXX RUN HAS BEEN KILLED - KILLING WASP: #{@wasp_id} XXXXXXX" @exit = true elsif (status['run_status'] == "finished") log.warn "XXXXX RUN IS FINISHED - KILLING WASP: #{@wasp_id} XXXXXXX" @exit = true end end end end end |
#test_code ⇒ Object
171 172 173 |
# File 'lib/load/load_test.rb', line 171 def test_code return @test.test_code end |
#time_ellapsed_millis ⇒ Object
153 154 155 156 |
# File 'lib/load/load_test.rb', line 153 def time_ellapsed_millis time_ellapsed = (Time.now - @start_time) * 1000.0 return time_ellapsed end |
#to_s ⇒ Object
175 176 177 |
# File 'lib/load/load_test.rb', line 175 def to_s return "I am only one wasp of a swarm. ##{@wasp_id}" end |