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.



70
71
72
73
74
75
76
77
78
79
80
81
# 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

Instance Attribute Details

#idObject (readonly)

Returns the value of attribute id.



68
69
70
# File 'lib/grntest/worker.rb', line 68

def id
  @id
end

#reporterObject (readonly)

Returns the value of attribute reporter.



68
69
70
# File 'lib/grntest/worker.rb', line 68

def reporter
  @reporter
end

#resultObject (readonly)

Returns the value of attribute result.



69
70
71
# File 'lib/grntest/worker.rb', line 69

def result
  @result
end

#statusObject (readonly)

Returns the value of attribute status.



69
70
71
# File 'lib/grntest/worker.rb', line 69

def status
  @status
end

#suite_nameObject (readonly)

Returns the value of attribute suite_name.



69
70
71
# File 'lib/grntest/worker.rb', line 69

def suite_name
  @suite_name
end

#test_nameObject (readonly)

Returns the value of attribute test_name.



69
70
71
# File 'lib/grntest/worker.rb', line 69

def test_name
  @test_name
end

#test_script_pathObject (readonly)

Returns the value of attribute test_script_path.



69
70
71
# File 'lib/grntest/worker.rb', line 69

def test_script_path
  @test_script_path
end

#testerObject (readonly)

Returns the value of attribute tester.



68
69
70
# File 'lib/grntest/worker.rb', line 68

def tester
  @tester
end

Instance Method Details

#interruptObject



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

def interrupt
  @interruptted = true
end

#interruptted?Boolean

Returns:

  • (Boolean)


87
88
89
# File 'lib/grntest/worker.rb', line 87

def interruptted?
  @interruptted
end

#on_test_failure(result) ⇒ Object



137
138
139
140
141
# 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) ⇒ Object



165
166
167
168
# 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) ⇒ Object



143
144
145
146
147
# 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) ⇒ Object



159
160
161
162
163
# 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) ⇒ Object



149
150
151
152
153
154
155
156
157
# 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_startObject



125
126
127
128
129
# 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) ⇒ Object



131
132
133
134
135
# 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) ⇒ Object



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
121
122
123
# 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