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 |
# 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 @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
177 178 179 180 181 |
# File 'lib/load/load_test.rb', line 177 def assert(value) if (value == false) raise "Assertion failed" end end |
#create_logger ⇒ Object
38 39 40 41 42 43 44 45 |
# File 'lib/load/load_test.rb', line 38 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
160 161 162 |
# File 'lib/load/load_test.rb', line 160 def current_action return current_action_for_time(time_ellapsed_millis) end |
#current_action_for_time(millis) ⇒ Object
164 165 166 167 |
# File 'lib/load/load_test.rb', line 164 def current_action_for_time(millis) current_action = schedule.current_action(millis / 1000) return current_action end |
#duration_millis ⇒ Object
134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 |
# File 'lib/load/load_test.rb', line 134 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
34 35 36 |
# File 'lib/load/load_test.rb', line 34 def log return @logger end |
#perform_test ⇒ Object
183 184 185 186 187 188 189 |
# File 'lib/load/load_test.rb', line 183 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
156 157 158 |
# File 'lib/load/load_test.rb', line 156 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
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 72 73 74 75 |
# File 'lib/load/load_test.rb', line 47 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) 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
78 79 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 |
# File 'lib/load/load_test.rb', line 78 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 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
169 170 171 |
# File 'lib/load/load_test.rb', line 169 def test_code return @test.test_code end |
#time_ellapsed_millis ⇒ Object
151 152 153 154 |
# File 'lib/load/load_test.rb', line 151 def time_ellapsed_millis time_ellapsed = (Time.now - @start_time) * 1000.0 return time_ellapsed end |
#to_s ⇒ Object
173 174 175 |
# File 'lib/load/load_test.rb', line 173 def to_s return "I am only one wasp of a swarm. ##{@wasp_id}" end |