moto 0.9.11 → 0.9.17

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,77 +0,0 @@
1
- require 'erb'
2
- require 'fileutils'
3
- require_relative '../../lib/config'
4
-
5
- module Moto
6
- module Runner
7
- class ThreadContext
8
-
9
- attr_reader :test
10
-
11
- def initialize(test, test_reporter)
12
- @test = test
13
- @test_reporter = test_reporter
14
-
15
- log_directory = File.dirname(@test.log_path)
16
- if !File.directory?(log_directory)
17
- FileUtils.mkdir_p(log_directory)
18
- end
19
-
20
- Thread.current['logger'] = Logger.new(File.open(@test.log_path, File::WRONLY | File::TRUNC | File::CREAT))
21
- Thread.current['logger'].level = config[:test_log_level] || Logger::DEBUG
22
- end
23
-
24
- def run
25
- max_attempts = config[:test_attempt_max] || 1
26
- sleep_time = config[:test_attempt_sleep] || 0
27
-
28
- # Reporting: start_test
29
- @test_reporter.report_start_test(@test.status, @test.metadata)
30
-
31
- (1..max_attempts).each do |attempt|
32
-
33
- @test.before
34
- Thread.current['logger'].info("Start: #{@test.name} attempt #{attempt}/#{max_attempts}")
35
-
36
- begin
37
- @test.run_test
38
- rescue Exceptions::TestForcedPassed, Exceptions::TestForcedFailure, Exceptions::TestSkipped => e
39
- Thread.current['logger'].info(e.message)
40
- rescue Exception => e
41
- Thread.current['logger'].error("#{e.class.name}: #{e.message}")
42
- Thread.current['logger'].error(e.backtrace.join("\n"))
43
- end
44
-
45
- @test.after
46
-
47
- Thread.current['logger'].info("Result: #{@test.status.results.last.code}")
48
-
49
- # test should have another attempt in case of an error / failure / none at all
50
- unless (@test.status.results.last.code == Moto::Test::Result::ERROR && config[:test_reattempt_on_error]) ||
51
- (@test.status.results.last.code == Moto::Test::Result::FAILURE && config[:test_reattempt_on_fail] )
52
- break
53
- end
54
-
55
- # don't go to sleep in the last attempt
56
- if attempt < max_attempts
57
- sleep sleep_time
58
- end
59
-
60
- end # Make another attempt
61
-
62
- # Close and flush stream to file
63
- Thread.current['logger'].close
64
-
65
- # Reporting: end_test
66
- @test_reporter.report_end_test(@test.status)
67
- end
68
-
69
- # @return [Hash] Hash with config for ThreadContext
70
- def config
71
- Moto::Lib::Config.moto[:test_runner]
72
- end
73
- private :config
74
-
75
- end
76
- end
77
- end