class Grntest::Worker

Attributes

id[R]
reporter[R]
result[R]
status[R]
suite_name[R]
test_name[R]
test_script_path[R]
tester[R]

Public Class Methods

new(id, tester, test_suites_result, reporter) click to toggle source
# File lib/grntest/worker.rb, line 70
def initialize(id, tester, test_suites_result, reporter)
  @id = id
  @tester = tester
  @test_suites_result = test_suites_result
  @reporter = reporter
  @suite_name = nil
  @test_script_path = nil
  @test_name = nil
  @interruptted = false
  @status = "not running"
  @result = WorkerResult.new
end

Public Instance Methods

interrupt() click to toggle source
# File lib/grntest/worker.rb, line 83
def interrupt
  @interruptted = true
end
interruptted?() click to toggle source
# File lib/grntest/worker.rb, line 87
def interruptted?
  @interruptted
end
on_test_failure(result) click to toggle source
# File lib/grntest/worker.rb, line 137
def on_test_failure(result)
  @status = "failed"
  @result.on_test_failure(test_name)
  @reporter.on_test_failure(self, result)
end
on_test_finish(result) click to toggle source
# File lib/grntest/worker.rb, line 165
def on_test_finish(result)
  @result.on_test_finish
  @reporter.on_test_finish(self, result)
end
on_test_leak(result) click to toggle source
# File lib/grntest/worker.rb, line 143
def on_test_leak(result)
  @status = "leaked(#{result.n_leaked_objects})"
  @result.on_test_leak(test_name)
  @reporter.on_test_leak(self, result)
end
on_test_no_check(result) click to toggle source
# File lib/grntest/worker.rb, line 159
def on_test_no_check(result)
  @status = "not checked"
  @result.on_test_no_check
  @reporter.on_test_no_check(self, result)
end
on_test_omission(result) click to toggle source
# File lib/grntest/worker.rb, line 149
def on_test_omission(result)
  @status = "omitted"
  @result.on_test_omission
  if @tester.suppress_omit_log?
    @reporter.on_test_omission_suppressed(self, result)
  else
    @reporter.on_test_omission(self, result)
  end
end
on_test_start() click to toggle source
# File lib/grntest/worker.rb, line 125
def on_test_start
  @status = "running"
  @test_result = nil
  @reporter.on_test_start(self)
end
on_test_success(result) click to toggle source
# File lib/grntest/worker.rb, line 131
def on_test_success(result)
  @status = "passed"
  @result.on_test_success
  @reporter.on_test_success(self, result)
end
run(queue) click to toggle source
# File lib/grntest/worker.rb, line 91
def run(queue)
  succeeded = true

  @result.measure do
    @reporter.on_worker_start(self)
    loop do
      suite_name, test_script_path, test_name = queue.pop
      break if test_script_path.nil?

      unless @suite_name == suite_name
        @reporter.on_suite_finish(self) if @suite_name
        @suite_name = suite_name
        @reporter.on_suite_start(self)
      end

      unless run_test(test_script_path, test_name)
        succeeded = false
      end

      break if interruptted?

      if @tester.stop_on_failure? and @test_suites_result.have_failure?
        break
      end
    end
    @status = "finished"
    @reporter.on_suite_finish(@suite_name) if @suite_name
    @suite_name = nil
  end
  @reporter.on_worker_finish(self)

  succeeded
end

Private Instance Methods

run_test(test_script_path, test_name) click to toggle source
# File lib/grntest/worker.rb, line 171
def run_test(test_script_path, test_name)
  begin
    @test_script_path = test_script_path
    @test_name = test_name

    n = -1
    loop do
      n += 1

      runner = TestRunner.new(@tester, self)
      return true if runner.run

      if n < @tester.n_retries and not interruptted?
        @result.cancel_test_failure(test_name)
        @test_suites_result.n_total_tests += 1
        next
      end

      return false
    end
  ensure
    @test_script_path = nil
    @test_name = nil
  end
end