Class: Grntest::Worker

Inherits:
Object
  • Object
show all
Defined in:
lib/grntest/worker.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(id, tester, test_suites_result, reporter) ⇒ Worker

Returns a new instance of Worker.



66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/grntest/worker.rb', line 66

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

Instance Attribute Details

#idObject (readonly)

Returns the value of attribute id.



64
65
66
# File 'lib/grntest/worker.rb', line 64

def id
  @id
end

#reporterObject (readonly)

Returns the value of attribute reporter.



64
65
66
# File 'lib/grntest/worker.rb', line 64

def reporter
  @reporter
end

#resultObject (readonly)

Returns the value of attribute result.



65
66
67
# File 'lib/grntest/worker.rb', line 65

def result
  @result
end

#statusObject (readonly)

Returns the value of attribute status.



65
66
67
# File 'lib/grntest/worker.rb', line 65

def status
  @status
end

#suite_nameObject (readonly)

Returns the value of attribute suite_name.



65
66
67
# File 'lib/grntest/worker.rb', line 65

def suite_name
  @suite_name
end

#test_nameObject (readonly)

Returns the value of attribute test_name.



65
66
67
# File 'lib/grntest/worker.rb', line 65

def test_name
  @test_name
end

#test_script_pathObject (readonly)

Returns the value of attribute test_script_path.



65
66
67
# File 'lib/grntest/worker.rb', line 65

def test_script_path
  @test_script_path
end

#testerObject (readonly)

Returns the value of attribute tester.



64
65
66
# File 'lib/grntest/worker.rb', line 64

def tester
  @tester
end

Instance Method Details

#interruptObject



79
80
81
# File 'lib/grntest/worker.rb', line 79

def interrupt
  @interruptted = true
end

#interruptted?Boolean

Returns:

  • (Boolean)


83
84
85
# File 'lib/grntest/worker.rb', line 83

def interruptted?
  @interruptted
end

#on_test_failure(result) ⇒ Object



134
135
136
137
138
# File 'lib/grntest/worker.rb', line 134

def on_test_failure(result)
  @status = "failed"
  @result.on_test_failure(test_name)
  @reporter.on_test_failure(self, result)
end

#on_test_finish(result) ⇒ Object



162
163
164
165
166
167
# File 'lib/grntest/worker.rb', line 162

def on_test_finish(result)
  @result.on_test_finish
  @reporter.on_test_finish(self, result)
  @test_script_path = nil
  @test_name = nil
end

#on_test_leak(result) ⇒ Object



140
141
142
143
144
# File 'lib/grntest/worker.rb', line 140

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) ⇒ Object



156
157
158
159
160
# File 'lib/grntest/worker.rb', line 156

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) ⇒ Object



146
147
148
149
150
151
152
153
154
# File 'lib/grntest/worker.rb', line 146

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_startObject



122
123
124
125
126
# File 'lib/grntest/worker.rb', line 122

def on_test_start
  @status = "running"
  @test_result = nil
  @reporter.on_test_start(self)
end

#on_test_success(result) ⇒ Object



128
129
130
131
132
# File 'lib/grntest/worker.rb', line 128

def on_test_success(result)
  @status = "passed"
  @result.on_test_success
  @reporter.on_test_success(self, result)
end

#run(queue) ⇒ Object



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
# File 'lib/grntest/worker.rb', line 87

def run(queue)
  succeeded = true

  @result.measure do
    @reporter.on_worker_start(self)
    catch do |tag|
      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
        @test_script_path = test_script_path
        @test_name = test_name
        runner = TestRunner.new(@tester, self)
        succeeded = false unless runner.run

        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
  end
  @reporter.on_worker_finish(self)

  succeeded
end