Class: Moto::Modes::Run::TestRunner

Inherits:
Object
  • Object
show all
Defined in:
lib/modes/run/test_runner.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(tests_metadata, test_reporter, stop_conditions) ⇒ TestRunner



18
19
20
21
22
# File 'lib/modes/run/test_runner.rb', line 18

def initialize(, test_reporter, stop_conditions)
   = 
  @test_reporter = test_reporter
  @stop_conditions = stop_conditions
end

Instance Attribute Details

#test_reporterObject (readonly)

Returns the value of attribute test_reporter.



10
11
12
# File 'lib/modes/run/test_runner.rb', line 10

def test_reporter
  @test_reporter
end

Instance Method Details

#runObject



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
68
69
70
71
72
73
74
75
# File 'lib/modes/run/test_runner.rb', line 24

def run
  test_provider = TestProvider.new()
  threads_max = Moto::Config::Manager.config_moto[:test_runner][:thread_count] || 1

  # remove log/screenshot files from previous execution
  .each do ||
    FileUtils.rm_rf("#{File.dirname(metadata.test_path)}/logs")
  end

  @test_reporter.report_start_run

  # Create as many threads as we're allowed by the config file.
  # test_provider.get_test - will invoke Queue.pop thus putting the thread to sleep
  # once there is no more work.

  Thread.abort_on_exception = true

  threads_max.times do
    Thread.new do

      loop do
        tc = ThreadContext.new(test_provider.get_test, @test_reporter)
        tc.run

        # unset all leftover variables stored 'globally' in Thread
        Thread.current.keys.each do |k|
          Thread.current[k] = nil
        end

      end
    end
  end

  # Waiting for all threads to run out of work so we can end the application
  # or abnormal termination to be triggered based on options provided by the user
  loop do
    run_status = @test_reporter.run_status
    if (test_provider.num_waiting == threads_max) ||
        (@stop_conditions[:error] && run_status.tests_error.length > 0) ||
        (@stop_conditions[:fail] && run_status.tests_failed.length > 0) ||
        (@stop_conditions[:skip] && run_status.tests_skipped.length > 0)
      break
    end

    sleep 2
  end

  @test_reporter.report_end_run

  # Exit application with code that represents status of test run
  Kernel.exit(@test_reporter.run_status.bitmap)
end