Class: Moto::Runner::ThreadContext
- Inherits:
-
Object
- Object
- Moto::Runner::ThreadContext
- Defined in:
- lib/runner/thread_context.rb
Instance Attribute Summary collapse
-
#test ⇒ Object
readonly
Returns the value of attribute test.
Instance Method Summary collapse
-
#initialize(test, test_reporter) ⇒ ThreadContext
constructor
A new instance of ThreadContext.
- #run ⇒ Object
Constructor Details
#initialize(test, test_reporter) ⇒ ThreadContext
Returns a new instance of ThreadContext.
11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/runner/thread_context.rb', line 11 def initialize(test, test_reporter) @test = test @test_reporter = test_reporter log_directory = File.dirname(@test.log_path) if !File.directory?(log_directory) FileUtils.mkdir_p(log_directory) end Thread.current['logger'] = Logger.new(File.open(@test.log_path, File::WRONLY | File::TRUNC | File::CREAT)) Thread.current['logger'].level = config[:test_log_level] || Logger::DEBUG end |
Instance Attribute Details
#test ⇒ Object (readonly)
Returns the value of attribute test.
9 10 11 |
# File 'lib/runner/thread_context.rb', line 9 def test @test end |
Instance Method Details
#run ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 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 |
# File 'lib/runner/thread_context.rb', line 24 def run max_attempts = config[:test_attempt_max] || 1 sleep_time = config[:test_attempt_sleep] || 0 # Reporting: start_test @test_reporter.report_start_test(@test.status, @test.) (1..max_attempts).each do |attempt| @test.before Thread.current['logger'].info("Start: #{@test.name} attempt #{attempt}/#{max_attempts}") begin @test.run_test rescue Exceptions::TestForcedPassed, Exceptions::TestForcedFailure, Exceptions::TestSkipped => e Thread.current['logger'].info(e.) rescue Exception => e Thread.current['logger'].error("#{e.class.name}: #{e.message}") Thread.current['logger'].error(e.backtrace.join("\n")) end @test.after Thread.current['logger'].info("Result: #{@test.status.results.last.code}") # test should have another attempt in case of an error / failure / none at all unless (@test.status.results.last.code == Moto::Test::Result::ERROR && config[:test_reattempt_on_error]) || (@test.status.results.last.code == Moto::Test::Result::FAILURE && config[:test_reattempt_on_fail] ) break end # don't go to sleep in the last attempt if attempt < max_attempts sleep sleep_time end end # Make another attempt # Close and flush stream to file Thread.current['logger'].close # Reporting: end_test @test_reporter.report_end_test(@test.status) end |