rspec-conductor 1.0.10 → 1.0.12

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: 9de36557f5b670ac37493d920d186e4dcbcaca0c958d59914448b91aa5e6e488
4
- data.tar.gz: 9d2371b5598a12adbc6ac907d80dfc4fbbe5f9c7d1c2b0f75cb17337345f51e4
3
+ metadata.gz: 2adf2982f4c0054337c9cc8b405231af7584e34d424286dea68099592a467618
4
+ data.tar.gz: e583031bf5ce03f04e462f1b74037cdf6ea7b495c3c0cbe15a0eb1cec4d0e699
5
5
  SHA512:
6
- metadata.gz: cb67874bb0e5f84176ac601588d7931c97d70e3f8f6caff111e7cc1607b15007fcbc17f0053ff2c92f8e438cdad343530c91667de4d99f4fc7b95ac504f868fd
7
- data.tar.gz: 4cb10a52cf0a0a6f9948c36287f2b6c5d35183df0ce6370196f9342e67c29ce5332780d8da8172d585be264170958fcbb317d77f03f3c23cb4ff70394b6e4cbe
6
+ metadata.gz: 4308277ebb07fb4aa16a67a833d518c7f2d8a0479aa3a13050fcb067f91222def4a206ba7b23a147a2f17f7c76df7ca42d7b04b0a19193f5bc875f1196a44d95
7
+ data.tar.gz: bb41bf5812b8d7b5dcf7691de809035e3ce444854b7d6290f4e7bae705887d99d3cbd982c7bc82b6f4b6b2e66ebd7de7840859c0c2d62737bd4e520b1a249f30
data/CHANGELOG.md CHANGED
@@ -1,3 +1,14 @@
1
+ ## [1.0.12] - 2026-09-12
2
+
3
+ - Add --example-status-persistence option to mimic rspec example status persistence runner config and to support --only-failures on repeat runs
4
+
5
+ ## [1.0.11] - 2026-08-03
6
+
7
+ - Fix a bug in 2.x that would cause an exception because of the 3.x syntax usage (`_1`) in the formatter base
8
+ - Remove a potential bottleneck when spec files run under 10ms on average
9
+ - Fix performance issue with recalculating the file/location list over and over (which would coincidentally also take around 10ms for large directories)
10
+ - In other words, if you had a lot of super fast spec files, it will run them fast as well
11
+
1
12
  ## [1.0.10] - 2026-03-08
2
13
 
3
14
  - Add --print-slowest cli param to display the slowest specs in the suite
@@ -16,6 +16,7 @@ module RSpec
16
16
  prefork_require: 'config/application.rb',
17
17
  postfork_require: :spec_helper,
18
18
  print_slowest_count: nil,
19
+ example_status_persistence_path: Conductor.default_example_status_persistence_path,
19
20
  }.freeze
20
21
 
21
22
  def self.run(argv)
@@ -102,6 +103,10 @@ module RSpec
102
103
  @conductor_options[:print_slowest_count] = n
103
104
  end
104
105
 
106
+ opts.on("--example-status-persistence-path FILENAME", String, "Persist example statuses to a given file (same as rspec config.example_status_persistence_file_path)") do |filename|
107
+ @conductor_options[:example_status_persistence_path] = filename
108
+ end
109
+
105
110
  opts.on("--verbose", "Enable debug output") do
106
111
  @conductor_options[:verbose] = true
107
112
  end
@@ -126,6 +131,7 @@ module RSpec
126
131
  formatter: @conductor_options[:formatter],
127
132
  display_retry_backtraces: @conductor_options[:display_retry_backtraces],
128
133
  print_slowest_count: @conductor_options[:print_slowest_count],
134
+ example_status_persistence_path: @conductor_options[:example_status_persistence_path],
129
135
  verbose: @conductor_options[:verbose],
130
136
  ).run
131
137
  end
@@ -0,0 +1,20 @@
1
+ module RSpec
2
+ module Conductor
3
+ module ExampleStatusPersister
4
+ # RSpec::Core::ExampleStatusPersister is a private api, but it's been fairly stable over the versions
5
+ # we want to support, so I don't expect issues using these stubs.
6
+ ExampleStub = Struct.new(:id, :execution_result)
7
+ ExampleExecutionResultStub = Struct.new(:status, :run_time)
8
+
9
+ def self.persist(example_stats, filename)
10
+ examples = example_stats.map do |stat|
11
+ ExampleStub.new(
12
+ stat[:id],
13
+ ExampleExecutionResultStub.new(stat[:status], stat[:run_time])
14
+ )
15
+ end
16
+ RSpec::Core::ExampleStatusPersister.persist(examples, filename)
17
+ end
18
+ end
19
+ end
20
+ end
@@ -74,7 +74,7 @@ module RSpec
74
74
  #{message[:location]}
75
75
  #{message[:exception_class]}: #{message[:message]}
76
76
  Backtrace:
77
- #{message[:backtrace].map { " #{_1}" }.join("\n")}
77
+ #{message[:backtrace].map { |line| " #{line}" }.join("\n")}
78
78
  EOM
79
79
  end
80
80
 
@@ -17,12 +17,14 @@ module RSpec
17
17
  end
18
18
 
19
19
  def example_passed(notification)
20
+ ex = notification.example
20
21
  @socket.send_message(
21
22
  type: :example_passed,
23
+ id: ex.id,
22
24
  file: @file,
23
- description: notification.example.full_description,
24
- location: notification.example.location,
25
- run_time: notification.example.execution_result.run_time
25
+ description: ex.full_description,
26
+ location: ex.location,
27
+ run_time: ex.execution_result.run_time
26
28
  )
27
29
  @shutdown_check.call
28
30
  end
@@ -31,6 +33,7 @@ module RSpec
31
33
  ex = notification.example
32
34
  @socket.send_message(
33
35
  type: :example_failed,
36
+ id: ex.id,
34
37
  file: @file,
35
38
  description: ex.full_description,
36
39
  location: ex.location,
@@ -46,6 +49,7 @@ module RSpec
46
49
  ex = notification.example
47
50
  @socket.send_message(
48
51
  type: :example_pending,
52
+ id: ex.id,
49
53
  file: @file,
50
54
  description: ex.full_description,
51
55
  location: ex.location,
@@ -4,7 +4,6 @@ module RSpec
4
4
  module Conductor
5
5
  class Server
6
6
  MAX_SEED = 2**16
7
- WORKER_POLL_INTERVAL = 0.01
8
7
 
9
8
  # @option worker_count [Integer] How many workers to spin
10
9
  # @option rspec_args [Array<String>] A list of rspec options
@@ -25,9 +24,10 @@ module RSpec
25
24
  @postfork_require = opts.fetch(:postfork_require, nil)
26
25
  @first_is_1 = opts.fetch(:first_is_1, Conductor.default_first_is_1?)
27
26
  @seed = opts[:seed] || (Random.new_seed % MAX_SEED)
28
- @fail_fast_after = opts[:fail_fast_after]
27
+ @fail_fast_after = opts.fetch(:fail_fast_after, nil)
29
28
  @display_retry_backtraces = opts.fetch(:display_retry_backtraces, false)
30
29
  @print_slowest_count = opts.fetch(:print_slowest_count, nil)
30
+ @example_status_persistence_path = opts.fetch(:example_status_persistence_path, nil)
31
31
  @verbose = opts.fetch(:verbose, false)
32
32
 
33
33
  @rspec_args = rspec_args
@@ -66,6 +66,7 @@ module RSpec
66
66
 
67
67
  @formatter.print_summary(@suite_run, seed: @seed, success: success?)
68
68
  @formatter.print_slowest(@suite_run, @print_slowest_count) if @print_slowest_count
69
+ Conductor::ExampleStatusPersister.persist(@suite_run.example_stats, @example_status_persistence_path) if @example_status_persistence_path
69
70
  exit_with_status
70
71
  end
71
72
 
@@ -170,7 +171,9 @@ module RSpec
170
171
  initiate_shutdown
171
172
  end
172
173
  when :example_pending
173
- @suite_run.example_pending
174
+ @suite_run.example_pending(message)
175
+ when :example_filtered
176
+ @suite_run.example_filtered(message)
174
177
  when :example_retried
175
178
  @formatter.print_retry_message(message) if @display_retry_backtraces
176
179
  when :spec_complete
@@ -24,20 +24,25 @@ module RSpec
24
24
  end
25
25
 
26
26
  def example_passed(message)
27
- @example_stats << message.slice(:location, :run_time, :description)
27
+ @example_stats << message.slice(:id, :location, :run_time, :description).merge(status: "passed")
28
28
  @examples_passed += 1
29
29
  end
30
30
 
31
31
  def example_failed(message)
32
- @example_stats << message.slice(:location, :run_time, :description)
32
+ @example_stats << message.slice(:id, :location, :run_time, :description).merge(status: "failed")
33
33
  @examples_failed += 1
34
34
  @errors << message
35
35
  end
36
36
 
37
- def example_pending
37
+ def example_pending(message)
38
+ @example_stats << message.slice(:id, :location).merge(status: "pending")
38
39
  @examples_pending += 1
39
40
  end
40
41
 
42
+ def example_filtered(message)
43
+ @example_stats << message.slice(:id, :location).merge(status: nil)
44
+ end
45
+
41
46
  def spec_file_assigned
42
47
  @specs_started_at ||= Time.now
43
48
  end
@@ -1,12 +1,14 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require "socket"
4
+
3
5
  module RSpec
4
6
  module Conductor
5
7
  module Util
6
8
  class ChildProcess
7
9
  POLL_INTERVAL = 0.01
8
10
 
9
- attr_reader :pid, :exit_status
11
+ attr_reader :pid, :message_socket, :exit_status, :ios
10
12
 
11
13
  def self.fork(**args, &block)
12
14
  new(**args).fork(&block)
@@ -22,44 +24,47 @@ module RSpec
22
24
 
23
25
  def self.tick_all(processes, poll_interval: POLL_INTERVAL)
24
26
  processes_by_io = processes.each_with_object({}) do |process, memo|
25
- process.pipes.reject(&:closed?).each { |pipe| memo[pipe] = process }
27
+ process.ios.reject(&:closed?).each { |io| memo[io] = process }
26
28
  end
27
29
  return false if processes_by_io.empty?
28
30
 
29
31
  ready, = IO.select(processes_by_io.keys, nil, nil, poll_interval)
30
- ready&.each { |pipe| processes_by_io[pipe].read_available(pipe) }
32
+ ready&.each { |io| processes_by_io[io].handle_available(io) }
31
33
 
32
34
  true
33
35
  end
34
36
 
35
- def initialize(on_stdout: nil, on_stderr: nil)
37
+ def initialize(on_stdout: nil, on_stderr: nil, on_message: nil)
36
38
  @on_stdout = on_stdout
37
39
  @on_stderr = on_stderr
40
+ @on_message = on_message
38
41
  @pid = nil
39
42
  @exit_status = nil
40
43
  @stdout_pipe = nil
41
44
  @stderr_pipe = nil
42
45
  @stdout_buffer = +""
43
46
  @stderr_buffer = +""
47
+ @message_socket = nil
48
+ @ios = []
44
49
  @done = false
45
50
  end
46
51
 
47
- def pipes
48
- [@stdout_pipe, @stderr_pipe].compact
49
- end
50
-
51
52
  def fork(&block)
52
53
  raise ArgumentError, '.fork should be called with a block' unless block_given?
53
54
 
54
55
  stdout_read, stdout_write = IO.pipe
55
56
  stderr_read, stderr_write = IO.pipe
57
+ parent_socket, child_socket = Socket.pair(:UNIX, :STREAM, 0) if @on_message
56
58
 
57
59
  @stdout_pipe = stdout_read
58
60
  @stderr_pipe = stderr_read
61
+ @message_socket = parent_socket
62
+ @ios = [@stdout_pipe, @stderr_pipe, @message_socket].compact
59
63
 
60
64
  @pid = Kernel.fork do
61
65
  stdout_read.close
62
66
  stderr_read.close
67
+ parent_socket&.close
63
68
 
64
69
  $stdout = stdout_write
65
70
  $stderr = stderr_write
@@ -69,13 +74,14 @@ module RSpec
69
74
  STDIN.reopen($stdin)
70
75
 
71
76
  begin
72
- yield self
77
+ yield self, child_socket
73
78
  rescue => e
74
79
  stderr_write.puts "#{e.class}: #{e.message}\n#{e.backtrace.join("\n")}"
75
80
  exit 1
76
81
  ensure
77
82
  stdout_write.close
78
83
  stderr_write.close
84
+ child_socket&.close
79
85
  end
80
86
 
81
87
  exit 0
@@ -83,6 +89,7 @@ module RSpec
83
89
 
84
90
  stdout_write.close
85
91
  stderr_write.close
92
+ child_socket&.close
86
93
 
87
94
  self
88
95
  end
@@ -91,17 +98,27 @@ module RSpec
91
98
  @done
92
99
  end
93
100
 
94
- def read_available(pipe)
101
+ def handle_available(io)
95
102
  return if done?
96
- return if pipe.closed?
97
-
98
- buffer, callback = if pipe == @stdout_pipe
99
- [@stdout_buffer, @on_stdout]
100
- elsif pipe == @stderr_pipe
101
- [@stderr_buffer, @on_stderr]
102
- else
103
- return
103
+ return if io.closed?
104
+
105
+ case io
106
+ when @stdout_pipe, @stderr_pipe
107
+ read_pipe(io)
108
+ when @message_socket
109
+ @on_message&.call
104
110
  end
111
+ end
112
+
113
+ def read_pipe(pipe)
114
+ buffer, callback = case pipe
115
+ when @stdout_pipe
116
+ [@stdout_buffer, @on_stdout]
117
+ when @stderr_pipe
118
+ [@stderr_buffer, @on_stderr]
119
+ else
120
+ return
121
+ end
105
122
 
106
123
  begin
107
124
  data = pipe.read_nonblock(4096, exception: false)
@@ -132,6 +149,8 @@ module RSpec
132
149
  rescue Errno::ECHILD
133
150
  end
134
151
 
152
+ @message_socket&.close
153
+
135
154
  self
136
155
  end
137
156
 
@@ -2,6 +2,6 @@
2
2
 
3
3
  module RSpec
4
4
  module Conductor
5
- VERSION = "1.0.10"
5
+ VERSION = "1.0.12"
6
6
  end
7
7
  end
@@ -48,8 +48,6 @@ module RSpec
48
48
  debug "Worker crashed: #{e.class}: #{e.message}"
49
49
  debug e.backtrace.join("\n")
50
50
  raise
51
- ensure
52
- @socket.close
53
51
  end
54
52
 
55
53
  private
@@ -109,12 +107,12 @@ module RSpec
109
107
  def run_spec(file)
110
108
  RSpec.world.reset
111
109
  RSpec.configuration.reset
112
- RSpec.configuration.files_or_directories_to_run = [file]
113
110
  RSpec.configuration.output_stream = null_io_out
114
111
  RSpec.configuration.error_stream = null_io_out
115
112
  RSpec.configuration.formatter_loader.formatters.clear
116
113
  RSpec.configuration.add_formatter(RSpecSubscriber.new(@socket, file, -> { check_for_shutdown }))
117
114
  parsed_options.configure(RSpec.configuration)
115
+ RSpec.configuration.files_or_directories_to_run = location_entries_for(file)
118
116
  RSpec.configuration.files_to_run # this seemingly random line is necessary for rspec to set up the inclusion filters (e.g. hello_spec.rb:123 -> the :123 part is an inclusion filter)
119
117
 
120
118
  begin
@@ -131,9 +129,19 @@ module RSpec
131
129
  example_groups.each { |g| g.run(reporter) }
132
130
  end
133
131
 
132
+ RSpec.world.all_examples.reject { |e| e.execution_result.status }.each do |e|
133
+ @socket.send_message(
134
+ type: :example_filtered,
135
+ id: e.id,
136
+ file: file,
137
+ description: e.full_description,
138
+ location: e.location
139
+ )
140
+ end
141
+
134
142
  @socket.send_message(
135
143
  type: :spec_complete,
136
- file: file
144
+ file: file,
137
145
  )
138
146
  rescue StandardError => e
139
147
  debug "Spec error: #{e.class}: #{e.message}"
@@ -167,6 +175,21 @@ module RSpec
167
175
  @parsed_options ||= RSpec::Core::ConfigurationOptions.new(@rspec_args).tap { |co| co.options.delete(:requires) }
168
176
  end
169
177
 
178
+ # Returns all the location entries for a filename
179
+ # RSpec syntax for locations:
180
+ # * ./a_spec.rb - run whole file
181
+ # * ./a_spec.rb:18 - run specific spec
182
+ # * ./a_spec.rb[1:2:1] - run specific spec group
183
+ # You can specify locations more than once for a single file, so you need to find all relevant entries in the runner
184
+ def location_entries_for(filename)
185
+ filename = File.expand_path(filename)
186
+ entries = Array(parsed_options.options[:files_or_directories_to_run]).select do |entry|
187
+ entry_filename = File.expand_path(entry.sub(/(\[\d+(:\d+)*\])+\z/, "").sub(/(:\d+)+\z/, ""))
188
+ entry_filename == filename
189
+ end
190
+ entries.empty? ? filename : entries
191
+ end
192
+
170
193
  def debug(message)
171
194
  @debug_io.puts message if @debug_io
172
195
  end
@@ -1,38 +1,25 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "socket"
4
-
5
3
  module RSpec
6
4
  module Conductor
7
- WorkerProcess = Struct.new(:pid, :child_process, :number, :on_message, :status, :socket, :current_spec, keyword_init: true) do
5
+ class WorkerProcess
8
6
  def self.spawn(number:, test_env_number:, on_message:, on_stdout: nil, on_stderr: nil, **worker_init_args)
9
- parent_socket, child_socket = Socket.pair(:UNIX, :STREAM, 0)
10
- child_process = Util::ChildProcess.fork(on_stdout: on_stdout, on_stderr: on_stderr) do
7
+ worker_process = new(number: number, on_message: on_message)
8
+
9
+ child_process = Util::ChildProcess.fork(on_stdout: on_stdout, on_stderr: on_stderr, on_message: proc { worker_process.handle_message }) do |_, child_socket|
11
10
  ENV["TEST_ENV_NUMBER"] = test_env_number
12
- parent_socket.close
13
11
  Worker.new(
14
12
  worker_number: number,
15
13
  socket: Protocol::Socket.new(child_socket),
16
14
  **worker_init_args
17
15
  ).run
18
16
  end
19
- child_socket.close
20
-
21
- new(
22
- pid: child_process.pid,
23
- child_process: child_process,
24
- on_message: on_message,
25
- number: number,
26
- status: :running,
27
- socket: Protocol::Socket.new(parent_socket),
28
- current_spec: nil
29
- )
17
+
18
+ worker_process.child_process = child_process
19
+ worker_process
30
20
  end
31
21
 
32
22
  def self.tick_all(worker_processes)
33
- worker_processes_by_io = worker_processes.select(&:running?).to_h { |w| [w.socket.io, w] }
34
- readable_ios, = IO.select(worker_processes_by_io.keys, nil, nil, 0)
35
- readable_ios&.each { |io| worker_processes_by_io.fetch(io).handle_message }
36
23
  Util::ChildProcess.tick_all(worker_processes.map(&:child_process))
37
24
  end
38
25
 
@@ -40,11 +27,23 @@ module RSpec
40
27
  Util::ChildProcess.wait_all(worker_processes.map(&:child_process))
41
28
  end
42
29
 
30
+ attr_reader :number
31
+ attr_accessor :current_spec, :child_process, :status
32
+
33
+ def initialize(number:, on_message: nil)
34
+ @number = number
35
+ @on_message = on_message
36
+ @status = :running
37
+ end
38
+
43
39
  def handle_message
44
40
  message = receive_message
45
- return unless message && on_message
41
+ unless message
42
+ socket.close
43
+ return
44
+ end
46
45
 
47
- on_message.call(self, message)
46
+ @on_message&.call(self, message)
48
47
  end
49
48
 
50
49
  def send_message(message)
@@ -55,11 +54,18 @@ module RSpec
55
54
  socket.receive_message
56
55
  end
57
56
 
57
+ def socket
58
+ @socket ||= Protocol::Socket.new(child_process.message_socket)
59
+ end
60
+
61
+ def pid
62
+ child_process.pid
63
+ end
64
+
58
65
  def shut_down(status)
59
66
  return unless running?
60
67
 
61
- self.status = status
62
- socket.close
68
+ @status = status
63
69
  end
64
70
 
65
71
  def running?
@@ -24,6 +24,10 @@ module RSpec
24
24
  def self.default_first_is_1?
25
25
  ENV["RSPEC_CONDUCTOR_FIRST_IS_1"] == "1"
26
26
  end
27
+
28
+ def self.default_example_status_persistence_path
29
+ ENV["RSPEC_CONDUCTOR_EXAMPLE_STATUS_PERSISTENCE_PATH"]
30
+ end
27
31
  end
28
32
  end
29
33
 
@@ -43,6 +47,7 @@ require_relative "conductor/formatters/base"
43
47
  require_relative "conductor/formatters/plain"
44
48
  require_relative "conductor/formatters/ci"
45
49
  require_relative "conductor/formatters/fancy"
50
+ require_relative "conductor/example_status_persister"
46
51
 
47
52
  require_relative "conductor/ext/rspec"
48
53
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rspec-conductor
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.10
4
+ version: 1.0.12
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mark Abramov
@@ -41,6 +41,7 @@ files:
41
41
  - exe/rspec-conductor
42
42
  - lib/rspec/conductor.rb
43
43
  - lib/rspec/conductor/cli.rb
44
+ - lib/rspec/conductor/example_status_persister.rb
44
45
  - lib/rspec/conductor/ext/rspec.rb
45
46
  - lib/rspec/conductor/formatters/base.rb
46
47
  - lib/rspec/conductor/formatters/ci.rb