flatware 2.3.1 → 2.3.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f3dfa03a78403cf9d0b10b97ac354baba9353a6847bcbbc9b150b7deaa8a4f68
4
- data.tar.gz: e2181f1f91b2b313ab42d39c93ce209efc432b29192737f7b9d5e06d13f637ce
3
+ metadata.gz: e4e66ab27a1e76fc9ca919c9b9de35006f88317cb6b5bf6f1b136b1b7eabc368
4
+ data.tar.gz: d16310a202a40d0e1a4147d31e1c97c8cc590f5d1b009b2576cefb9e79e47735
5
5
  SHA512:
6
- metadata.gz: 63b9c6f997e89382276b56797cf0e0b53155c30e11a5e22157c03a93da7cd616bffde249283a6ed7a29affc1b9da5baa211c2963e98402998068c7a9f856ed33
7
- data.tar.gz: dba4525f41243955e2f0f3db5a8685031a38eb66192de319c110eae41450fcd55ad995d56c3025e01cb8ad61a50dce04dec4dcc1e45ed54f36dfe011554f5339
6
+ metadata.gz: 3e1b6e794216a3724966e1465990d89a6d8d33f2ef2d58248b7ccb35e16451ad3f675c9b4f630135b9d4fbc61a75e4be32b844ee8758f1e9975dc80ffd13b32a
7
+ data.tar.gz: 341abe2ae2e05e2105f3de801fb8e8bd044028bc75a21529d4f5b2d1aab20b943d0b4d860cfff432e1f234d91dbd662db23c664543e3dd2ad2b8b2b95d315738
data/README.md CHANGED
@@ -40,13 +40,13 @@ $ flatware rspec
40
40
 
41
41
  The rspec runner can balance worker loads, making your suite even faster.
42
42
 
43
- It forms balaced groups of spec files according to their last run times, if you've set `example_status_persistence_file_path` [in your RSpec config](https://relishapp.com/rspec/rspec-core/v/3-8/docs/command-line/only-failures).
43
+ It forms balanced groups of spec files according to their last run times, if you've set `example_status_persistence_file_path` [in your RSpec config](https://relishapp.com/rspec/rspec-core/v/3-8/docs/command-line/only-failures).
44
44
 
45
- For this to work the configuration option must be loaded before any specs are run. The `.rspec` file is one way to achive this:
45
+ For this to work the configuration option must be loaded before any specs are run. The `.rspec` file is one way to achieve this:
46
46
 
47
47
  --require spec_helper
48
48
 
49
- But beware, if you're using ActiveRecord in your suite you'll need to avoid doing things that cause it to establish a database connection in `spec_helper.rb`. If ActiveRecord connects before flatware forks off workers, each will die messily. All of this will just work if you're following [the recomended pattern of splitting your helpers into `spec_helper` and `rails_helper`](https://github.com/rspec/rspec-rails/blob/v3.8.2/lib/generators/rspec/install/templates/spec/rails_helper.rb). Another option is to use [the configurable hooks](
49
+ But beware, if you're using ActiveRecord in your suite you'll need to avoid doing things that cause it to establish a database connection in `spec_helper.rb`. If ActiveRecord connects before flatware forks off workers, each will die messily. All of this will just work if you're following [the recommended pattern of splitting your helpers into `spec_helper` and `rails_helper`](https://github.com/rspec/rspec-rails/blob/v3.8.2/lib/generators/rspec/install/templates/spec/rails_helper.rb). Another option is to use [the configurable hooks](
50
50
  #faster-startup-with-activerecord
51
51
  ).
52
52
 
data/lib/flatware/cli.rb CHANGED
@@ -17,7 +17,7 @@ module Flatware
17
17
  aliases: '-w',
18
18
  type: :numeric,
19
19
  default: processors,
20
- desc: 'Number of concurent processes to run'
20
+ desc: 'Number of concurrent processes to run'
21
21
  )
22
22
  end
23
23
 
@@ -90,6 +90,6 @@ if loaded_flatware_gem_count.zero?
90
90
  warn(
91
91
  format(<<~MESSAGE, gem_list: flatware_gems.join(' or ')))
92
92
  The flatware gem is a dependency of flatware runners for rspec and cucumber.
93
- Install %<gem_list>s for more usefull commands.
93
+ Install %<gem_list>s for more useful commands.
94
94
  MESSAGE
95
95
  end
@@ -1,46 +1,77 @@
1
1
  module Flatware
2
2
  module Sink
3
3
  class Signal
4
- def initialize(&on_interrupt)
4
+ Message = Struct.new(:message)
5
+
6
+ attr_reader :formatter
7
+
8
+ def initialize(formatter, &on_interrupt)
9
+ @formatter = formatter
5
10
  Thread.main[:signals] = Queue.new
6
11
 
7
12
  @on_interrupt = on_interrupt
8
13
  end
9
14
 
10
- def interruped?
11
- !signals.empty?
12
- end
13
-
14
15
  def listen
15
16
  Thread.new(&method(:handle_signals))
16
17
 
17
18
  ::Signal.trap('INT') { signals << :int }
18
- ::Signal.trap('CLD') { signals << :cld }
19
+ ::Signal.trap('CLD') do
20
+ signals << :cld if child_failed?
21
+ end
19
22
 
20
23
  self
21
24
  end
22
25
 
23
- def self.listen(&block)
24
- new(&block).listen
26
+ def self.listen(formatter, &block)
27
+ new(formatter, &block).listen
25
28
  end
26
29
 
27
30
  private
28
31
 
32
+ def child_status
33
+ _worker_pid, status = begin
34
+ Process.wait2(-1, Process::WNOHANG)
35
+ rescue Errno::ECHILD
36
+ []
37
+ end
38
+ status
39
+ end
40
+
41
+ def child_statuses
42
+ statuses = []
43
+ loop do
44
+ status = child_status
45
+ return statuses unless status
46
+
47
+ statuses << status
48
+ end
49
+ end
50
+
51
+ def child_failed?
52
+ child_statuses.any? { |status| !status.success? }
53
+ end
54
+
29
55
  def handle_signals
30
- puts signal_message(signals.pop)
31
- Process.waitall
32
- @on_interrupt.call
33
- puts 'done.'
56
+ signal_message(signals.pop) do
57
+ Process.waitall
58
+ @on_interrupt.call
59
+ end
60
+
34
61
  abort
35
62
  end
36
63
 
37
64
  def signal_message(signal)
38
- format(<<~MESSAGE, { cld: 'A worker died', int: 'Interrupted' }.fetch(signal))
65
+ formatter.message(Message.new(format(<<~MESSAGE, { cld: 'A worker died', int: 'Interrupted' }.fetch(signal))))
39
66
 
40
67
  %s!
41
68
 
42
- Cleaning up. Please wait...
69
+ Waiting for workers to finish their current jobs...
43
70
  MESSAGE
71
+
72
+ yield
73
+
74
+ formatter.message(Message.new('done.'))
44
75
  end
45
76
 
46
77
  def signals
data/lib/flatware/sink.rb CHANGED
@@ -25,6 +25,7 @@ module Flatware
25
25
  @checkpoints = []
26
26
  @completed_jobs = []
27
27
  @formatter = formatter
28
+ @interrupted = false
28
29
  @jobs = group_jobs(jobs, worker_count).freeze
29
30
  @queue = @jobs.dup
30
31
  @sink = sink
@@ -32,16 +33,16 @@ module Flatware
32
33
  end
33
34
 
34
35
  def start
35
- @signal = Signal.listen(&method(:summarize_remaining))
36
+ Signal.listen(formatter, &method(:on_interrupt))
36
37
  formatter.jobs jobs
37
38
  DRb.start_service(sink, self, verbose: Flatware.verbose?)
38
39
  DRb.thread.join
39
- !failures?
40
+ !(failures? || interrupted?)
40
41
  end
41
42
 
42
43
  def ready(worker)
43
44
  job = queue.shift
44
- if job && !(remaining_work.empty? || interruped?)
45
+ if job && !(remaining_work.empty? || interrupted?)
45
46
  workers << worker
46
47
  job
47
48
  else
@@ -73,8 +74,13 @@ module Flatware
73
74
 
74
75
  private
75
76
 
76
- def interruped?
77
- @signal&.interruped?
77
+ def on_interrupt
78
+ @interrupted = true
79
+ summarize_remaining
80
+ end
81
+
82
+ def interrupted?
83
+ @interrupted
78
84
  end
79
85
 
80
86
  def check_finished!
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Flatware
4
- VERSION = '2.3.1'
4
+ VERSION = '2.3.2'
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: flatware
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.3.1
4
+ version: 2.3.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brian Dunn
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-03-20 00:00:00.000000000 Z
11
+ date: 2024-05-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: thor