minitest-distributed 0.2.0 → 0.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 076d9467680eff44b28d42436648c5f4878fb5689bca7ddd9365bd05991a5352
4
- data.tar.gz: '0068262916e339e61d4997eb478df915be5943d3a6b39e70fb02def9ba0d0dbb'
3
+ metadata.gz: 829613fe27e895208e49a116fd8f72e3685e1e91eb95209db170ad51707d2115
4
+ data.tar.gz: 1e0932553fe7d007e40392f53f80dd49eb6dafd533077d8234d4feb86629e8d4
5
5
  SHA512:
6
- metadata.gz: 5d71ead8d7f352d9d628ec6682d2367804c63362e1e02e658ae3899b55486e1ff1bedd1cc10e23796a3373a0a3d0580b874646c4f7e3ec472675b8b85d88b001
7
- data.tar.gz: cafd308bdad9ee0332323e0e826810fee2be91cbb5bdafa74ec8037891e9a6031ffa6f4f1e4777527e0f21784a48502848893661120145749629240164c3c077
6
+ metadata.gz: 71dbe335df12886c11af8f438dec954678ad9d5841847e44521e492dfc641eddc76da66e73c0f5d96840f75746e027f3304d08ed46171817a0541d773495b32f
7
+ data.tar.gz: fb5a8f6f781c71944df6228e4da980b29f2bd01fd9733aebe10437ac8eaa867d7d55b49397ad2d4f1acca9d503e8b2a8191fcfc8f935675a78f9d75208e0a39f
@@ -27,9 +27,10 @@ module Minitest
27
27
  )
28
28
  end
29
29
 
30
- sig { params(opts: OptionParser).returns(T.attached_class) }
31
- def from_command_line_options(opts)
30
+ sig { params(opts: OptionParser, options: T::Hash[Symbol, T.untyped]).returns(T.attached_class) }
31
+ def from_command_line_options(opts, options)
32
32
  configuration = from_env
33
+ configuration.progress = options[:io].tty?
33
34
 
34
35
  opts.on('--coordinator=URI', "The URI pointing to the coordinator") do |uri|
35
36
  configuration.coordinator_uri = URI.parse(uri)
@@ -66,6 +67,10 @@ module Minitest
66
67
  configuration.retry_failures = enabled
67
68
  end
68
69
 
70
+ opts.on('--[no-]progress', "Show progress during the test run") do |enabled|
71
+ configuration.progress = enabled
72
+ end
73
+
69
74
  configuration
70
75
  end
71
76
  end
@@ -80,6 +85,7 @@ module Minitest
80
85
  prop :max_attempts, Integer, default: DEFAULT_MAX_ATTEMPTS
81
86
  prop :max_failures, T.nilable(Integer)
82
87
  prop :retry_failures, T::Boolean, default: true
88
+ prop :progress, T::Boolean, default: false
83
89
 
84
90
  sig { returns(Coordinators::CoordinatorInterface) }
85
91
  def coordinator
@@ -66,8 +66,9 @@ module Minitest
66
66
 
67
67
  reporter.prerecord(enqueued_runnable.runnable_class, enqueued_runnable.method_name)
68
68
 
69
- enqueued_result = enqueued_runnable.run do |initial_result|
70
- if ResultType.of(initial_result) == ResultType::Requeued
69
+ initial_result = enqueued_runnable.run
70
+ enqueued_result = enqueued_runnable.commit_result(initial_result) do |result_to_commit|
71
+ if ResultType.of(result_to_commit) == ResultType::Requeued
71
72
  queue << enqueued_runnable.next_attempt
72
73
  end
73
74
  EnqueuedRunnable::Result::Commit.success
@@ -440,15 +440,18 @@ module Minitest
440
440
 
441
441
  local_results.size += batch.size
442
442
 
443
- runnable_results = T.let([], T::Array[EnqueuedRunnable::Result])
444
- redis.multi do
445
- batch.each do |enqueued_runnable|
446
- # Fulfill the reporter contract by calling `prerecord` before we run the test.
447
- reporter.prerecord(enqueued_runnable.runnable_class, enqueued_runnable.method_name)
443
+ # Call `prerecord` on the recorder for all tests in the batch, and run them.
444
+ results = batch.map do |enqueued_runnable|
445
+ reporter.prerecord(enqueued_runnable.runnable_class, enqueued_runnable.method_name)
446
+ [enqueued_runnable, enqueued_runnable.run]
447
+ end
448
448
 
449
- # Actually run the test!
450
- runnable_results << enqueued_runnable.run do |initial_result|
451
- if ResultType.of(initial_result) == ResultType::Requeued
449
+ # Try to commit all the results of this batch to Redis
450
+ runnable_results = []
451
+ redis.multi do
452
+ results.each do |enqueued_runnable, initial_result|
453
+ runnable_results << enqueued_runnable.commit_result(initial_result) do |result_to_commit|
454
+ if ResultType.of(result_to_commit) == ResultType::Requeued
452
455
  sadd_future = redis.sadd(key('retry_set'), enqueued_runnable.attempt_id)
453
456
  EnqueuedRunnable::Result::Commit.new { sadd_future.value }
454
457
  else
@@ -202,26 +202,31 @@ module Minitest
202
202
 
203
203
  sig do
204
204
  params(
205
+ initial_result: Minitest::Result,
205
206
  block: T.proc.params(arg0: Minitest::Result).returns(EnqueuedRunnable::Result::Commit)
206
207
  ).returns(EnqueuedRunnable::Result)
207
208
  end
208
- def run(&block)
209
- initial_result = if attempts_exhausted?
209
+ def commit_result(initial_result, &block)
210
+ EnqueuedRunnable::Result.new(
211
+ enqueued_runnable: self,
212
+ initial_result: initial_result,
213
+ commit: block.call(initial_result),
214
+ )
215
+ end
216
+
217
+ sig { returns(Minitest::Result) }
218
+ def run
219
+ if attempts_exhausted?
210
220
  attempts_exhausted_result
211
221
  else
212
222
  result = Minitest.run_one_method(runnable_class, method_name)
213
223
  result_type = ResultType.of(result)
214
224
  if (result_type == ResultType::Error || result_type == ResultType::Failed) && !final_attempt?
215
- result = Minitest::Requeue.wrap(result, attempt: attempt, max_attempts: max_attempts)
225
+ Minitest::Requeue.wrap(result, attempt: attempt, max_attempts: max_attempts)
226
+ else
227
+ result
216
228
  end
217
- result
218
229
  end
219
-
220
- EnqueuedRunnable::Result.new(
221
- enqueued_runnable: self,
222
- initial_result: initial_result,
223
- commit: block.call(initial_result),
224
- )
225
230
  end
226
231
 
227
232
  sig { returns(T.self_type) }
@@ -20,6 +20,7 @@ module Minitest
20
20
  end
21
21
  @coordinator = T.let(options[:distributed].coordinator, Coordinators::CoordinatorInterface)
22
22
  @window_line_width = T.let(nil, T.nilable(Integer))
23
+ @show_progress = T.let(options[:distributed].progress, T::Boolean)
23
24
  end
24
25
 
25
26
  sig { override.void }
@@ -37,7 +38,7 @@ module Minitest
37
38
 
38
39
  sig { override.params(klass: T.class_of(Runnable), name: String).void }
39
40
  def prerecord(klass, name)
40
- if io.tty?
41
+ if show_progress?
41
42
  clear_current_line
42
43
  io.print("[#{results.acks}/#{results.size}] #{klass}##{name}".slice(0...window_line_width))
43
44
  end
@@ -45,7 +46,7 @@ module Minitest
45
46
 
46
47
  sig { override.params(result: Minitest::Result).void }
47
48
  def record(result)
48
- clear_current_line if io.tty?
49
+ clear_current_line if show_progress?
49
50
 
50
51
  case (result_type = ResultType.of(result))
51
52
  when ResultType::Passed
@@ -61,11 +62,16 @@ module Minitest
61
62
 
62
63
  sig { override.void }
63
64
  def report
64
- clear_current_line if io.tty?
65
+ clear_current_line if show_progress?
65
66
  end
66
67
 
67
68
  private
68
69
 
70
+ sig { returns(T::Boolean) }
71
+ def show_progress?
72
+ @show_progress
73
+ end
74
+
69
75
  sig { void }
70
76
  def clear_current_line
71
77
  io.print("\r" + (' ' * window_line_width) + "\r")
@@ -76,6 +82,8 @@ module Minitest
76
82
  @window_line_width ||= begin
77
83
  _height, width = io.winsize
78
84
  width > 0 ? width : 80
85
+ rescue Errno::ENOTTY
86
+ 80
79
87
  end
80
88
  end
81
89
 
@@ -3,6 +3,6 @@
3
3
 
4
4
  module Minitest
5
5
  module Distributed
6
- VERSION = "0.2.0"
6
+ VERSION = "0.2.1"
7
7
  end
8
8
  end
@@ -12,7 +12,7 @@ module Minitest
12
12
  options[:disable_distributed] = true
13
13
  end
14
14
 
15
- options[:distributed] = Minitest::Distributed::Configuration.from_command_line_options(opts)
15
+ options[:distributed] = Minitest::Distributed::Configuration.from_command_line_options(opts, options)
16
16
  end
17
17
 
18
18
  def plugin_distributed_init(options)
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: minitest-distributed
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Willem van Bergen
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-07-21 00:00:00.000000000 Z
11
+ date: 2020-07-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: minitest