forking_test_runner 1.9.0 → 1.13.0

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: 33abc47d33141843b1d89ce17adee27897c64bc3445d9567845194aaa9f07224
4
- data.tar.gz: a61958472117f965f21e354ce7f874f7ea920a76503589b5dd36e0a6f21eb7c7
3
+ metadata.gz: 6d802108391cd0edbb4c9a9628ca56d447dbc07992f07cf8c1ffc1e61d770d5a
4
+ data.tar.gz: cabbf4e263465b03e1bc47435b15ce5186c3478f409095f57d2197e49ca5e0e5
5
5
  SHA512:
6
- metadata.gz: 59f31396b4c6ccdce8cb625aebdea2b3f2a49c6e91983990f2b93e386c19f8e6ef94100d8ca0482a0e82cec2450fb1a5db1a47c42566749b69d7324543676c87
7
- data.tar.gz: 32bbc0a83affacf06da8943e9a592152841ead2d7180aabe201031934d68705ac9e769c9c75b33b13b0a4b1587f6795fb38bbdb44c145f4e5c3de74bd698dab3
6
+ metadata.gz: 921396a5eec38e183f71ab4ba42340dad7c34f81d622af12ad9df156c639ce0c41d53ba0bcaff9c3e5efa6e52d5416a1676a018f6cacb1e4aa01fb820d338781
7
+ data.tar.gz: c79fcf65d60af55227c194baf05c86275a1d6d2b1132fa14bd311480d982b490b40d991c02f8a14ad9a95f7578fbd92ee1b6f7a7e32108dc9a853c4d92594f90
@@ -7,7 +7,7 @@ module ForkingTestRunner
7
7
  [:quiet, "--quiet", "Quiet"],
8
8
  [:no_fixtures, "--no-fixtures", "Do not load fixtures"],
9
9
  [:no_ar, "--no-ar", "Disable ActiveRecord logic"],
10
- [:merge_coverage, "--merge-coverage", "Merge base code coverage into indvidual files coverage, great for SingleCov"],
10
+ [:merge_coverage, "--merge-coverage", "Merge base code coverage into individual files coverage and summarize coverage report"],
11
11
  [
12
12
  :record_runtime,
13
13
  "--record-runtime=MODE",
@@ -1,3 +1,3 @@
1
1
  module ForkingTestRunner
2
- VERSION = "1.9.0"
2
+ VERSION = "1.13.0"
3
3
  end
@@ -11,6 +11,9 @@ module ForkingTestRunner
11
11
  CONVERAGE_REPORT_PREFIX = "coverage/fork-"
12
12
 
13
13
  class << self
14
+
15
+ attr_accessor :before_fork_callbacks, :after_fork_callbacks
16
+
14
17
  def cli(argv)
15
18
  @options, tests = CLI.parse_options(argv)
16
19
 
@@ -34,6 +37,9 @@ module ForkingTestRunner
34
37
  puts "Running tests #{all_tests.map(&:first).join(" ")}"
35
38
  end
36
39
 
40
+ @before_fork_callbacks = []
41
+ @after_fork_callbacks = []
42
+
37
43
  # run all the tests
38
44
  results = with_lock do |lock|
39
45
  Parallel.map_with_index(test_groups, in_processes: parallel || 0) do |tests, env_index|
@@ -195,6 +201,7 @@ module ForkingTestRunner
195
201
  preload_fixtures
196
202
  ActiveRecord::Base.connection.disconnect!
197
203
  end
204
+ @before_fork_callbacks.each(&:call)
198
205
 
199
206
  CoverageCapture.capture! if @options.fetch(:merge_coverage)
200
207
  end
@@ -253,7 +260,7 @@ module ForkingTestRunner
253
260
  def fork_with_captured_stdout
254
261
  rpipe, wpipe = IO.pipe
255
262
 
256
- child = fork do
263
+ child = Process.fork do
257
264
  rpipe.close
258
265
  preserve_tty { $stdout.reopen(wpipe) }
259
266
  yield
@@ -282,10 +289,16 @@ module ForkingTestRunner
282
289
  def run_test(file)
283
290
  stdout = change_program_name_to file do
284
291
  fork_with_captured_stdout do
285
- SimpleCov.pid = Process.pid if defined?(SimpleCov) && SimpleCov.respond_to?(:pid=) # make simplecov report in this fork
292
+ if defined?(SimpleCov)
293
+ SimpleCov.pid = Process.pid
294
+ SimpleCov.command_name file
295
+ end
286
296
  if partial_reports_for_single_cov?
287
297
  SingleCov.coverage_report = "#{CONVERAGE_REPORT_PREFIX}#{Process.pid}.json"
288
298
  end
299
+
300
+ @after_fork_callbacks.each(&:call)
301
+
289
302
  if active_record?
290
303
  key = (ActiveRecord::VERSION::STRING >= "4.1.0" ? :test : "test")
291
304
  ActiveRecord::Base.establish_connection key
@@ -365,17 +378,20 @@ module ForkingTestRunner
365
378
  def summarize_partial_reports
366
379
  reports = Dir.glob("#{CONVERAGE_REPORT_PREFIX}*")
367
380
  return if reports.empty?
381
+ key = nil
368
382
 
369
383
  require "json" # not a global dependency
370
384
  coverage = reports.each_with_object({}) do |report, all|
371
- suites = JSON.parse(File.read(report), symbolize_names: true).values
385
+ data = JSON.parse(File.read(report), symbolize_names: true)
386
+ key ||= data.keys.first
387
+ suites = data.values
372
388
  raise "Unsupported number of suites #{suites.size}" if suites.size != 1
373
389
  all.replace CoverageCapture.merge_coverage(all, suites.first.fetch(:coverage))
374
390
  ensure
375
391
  File.unlink(report) # do not leave junk behind
376
392
  end
377
393
 
378
- data = JSON.pretty_generate("Unit Tests" => {"coverage" => coverage, "timestamp" => Time.now.to_i })
394
+ data = JSON.pretty_generate(key => {"coverage" => coverage, "timestamp" => Time.now.to_i })
379
395
  File.write(SingleCov.coverage_report, data)
380
396
 
381
397
  # make it not override our report when it finishes for main process
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: forking_test_runner
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.9.0
4
+ version: 1.13.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Michael Grosser
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-10-24 00:00:00.000000000 Z
11
+ date: 2021-11-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: parallel_tests
@@ -24,20 +24,6 @@ dependencies:
24
24
  - - ">="
25
25
  - !ruby/object:Gem::Version
26
26
  version: 1.3.7
27
- - !ruby/object:Gem::Dependency
28
- name: wwtd
29
- requirement: !ruby/object:Gem::Requirement
30
- requirements:
31
- - - ">="
32
- - !ruby/object:Gem::Version
33
- version: '0'
34
- type: :development
35
- prerelease: false
36
- version_requirements: !ruby/object:Gem::Requirement
37
- requirements:
38
- - - ">="
39
- - !ruby/object:Gem::Version
40
- version: '0'
41
27
  - !ruby/object:Gem::Dependency
42
28
  name: bump
43
29
  requirement: !ruby/object:Gem::Requirement
@@ -140,7 +126,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
140
126
  - !ruby/object:Gem::Version
141
127
  version: '0'
142
128
  requirements: []
143
- rubygems_version: 3.1.3
129
+ rubygems_version: 3.2.16
144
130
  signing_key:
145
131
  specification_version: 4
146
132
  summary: Run every test in a fork to avoid pollution and get clean output per test