Class: Minitest::Distributed::EnqueuedRunnable
- Inherits:
-
T::Struct
- Object
- T::Struct
- Minitest::Distributed::EnqueuedRunnable
- Extended by:
- T::Sig
- Defined in:
- lib/minitest/distributed/enqueued_runnable.rb
Defined Under Namespace
Classes: Result
Class Method Summary collapse
Instance Method Summary collapse
- #attempt_id ⇒ Object
- #attempts_exhausted? ⇒ Boolean
- #attempts_exhausted_result ⇒ Object
- #commit_result(initial_result, &block) ⇒ Object
- #final_attempt? ⇒ Boolean
- #identifier ⇒ Object
- #instantiate_runnable ⇒ Object
- #next_attempt ⇒ Object
- #run ⇒ Object
- #runnable_class ⇒ Object
Class Method Details
.from_redis_stream_claim(claims, pending_messages = {}, configuration:) ⇒ Object
131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 |
# File 'lib/minitest/distributed/enqueued_runnable.rb', line 131 def from_redis_stream_claim(claims, = {}, configuration:) claims.map do |entry_id, runnable_method_info| # `attempt` will be set to the current attempt of a different worker that has timed out. # The attempt we are going to try will be the next one, so add one. attempt = .key?(entry_id) ? .fetch(entry_id).attempt + 1 : 1 new( class_name: runnable_method_info.fetch("class_name"), method_name: runnable_method_info.fetch("method_name"), entry_id: entry_id, attempt: attempt, max_attempts: configuration.max_attempts, test_timeout_seconds: configuration.test_timeout_seconds, ) end end |
Instance Method Details
#attempt_id ⇒ Object
164 165 166 |
# File 'lib/minitest/distributed/enqueued_runnable.rb', line 164 def attempt_id "#{entry_id}/#{attempt}" end |
#attempts_exhausted? ⇒ Boolean
179 180 181 |
# File 'lib/minitest/distributed/enqueued_runnable.rb', line 179 def attempts_exhausted? attempt > max_attempts end |
#attempts_exhausted_result ⇒ Object
189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 |
# File 'lib/minitest/distributed/enqueued_runnable.rb', line 189 def attempts_exhausted_result assertion = Minitest::AttemptsExhausted.new(<<~EOM.chomp) This test takes too long to run (> #{test_timeout_seconds}s). We have tried running this test #{max_attempts} on different workers, but every time the worker has not reported back a result within #{test_timeout_seconds}s. Try to make the test faster, or increase the test timeout. EOM assertion.set_backtrace(caller) runnable = instantiate_runnable runnable.time = 0.0 runnable.failures = [assertion] Minitest::Result.from(runnable) end |
#commit_result(initial_result, &block) ⇒ Object
211 212 213 214 215 216 217 |
# File 'lib/minitest/distributed/enqueued_runnable.rb', line 211 def commit_result(initial_result, &block) EnqueuedRunnable::Result.new( enqueued_runnable: self, initial_result: initial_result, commit: block.call(initial_result), ) end |
#final_attempt? ⇒ Boolean
184 185 186 |
# File 'lib/minitest/distributed/enqueued_runnable.rb', line 184 def final_attempt? attempt == max_attempts end |
#identifier ⇒ Object
159 160 161 |
# File 'lib/minitest/distributed/enqueued_runnable.rb', line 159 def identifier "#{class_name}##{method_name}" end |
#instantiate_runnable ⇒ Object
174 175 176 |
# File 'lib/minitest/distributed/enqueued_runnable.rb', line 174 def instantiate_runnable runnable_class.new(method_name) end |
#next_attempt ⇒ Object
235 236 237 238 239 240 241 242 243 244 |
# File 'lib/minitest/distributed/enqueued_runnable.rb', line 235 def next_attempt self.class.new( class_name: class_name, method_name: method_name, entry_id: entry_id, attempt: attempt + 1, max_attempts: max_attempts, test_timeout_seconds: test_timeout_seconds, ) end |
#run ⇒ Object
220 221 222 223 224 225 226 227 228 229 230 231 232 |
# File 'lib/minitest/distributed/enqueued_runnable.rb', line 220 def run if attempts_exhausted? attempts_exhausted_result else result = Minitest.run_one_method(runnable_class, method_name) result_type = ResultType.of(result) if (result_type == ResultType::Error || result_type == ResultType::Failed) && !final_attempt? Minitest::Requeue.wrap(result, attempt: attempt, max_attempts: max_attempts) else result end end end |
#runnable_class ⇒ Object
169 170 171 |
# File 'lib/minitest/distributed/enqueued_runnable.rb', line 169 def runnable_class DefinedRunnable.find_class(class_name) end |