forking_test_runner 1.12.0 → 1.14.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: be87df3e12024204491610717130bc0b71a3b7fc02d6a60c82da34ebedbf74c6
4
- data.tar.gz: 4e6fb9c449dc7e00c46e39fdbc7686bcfe0bf1df439c800e78767950a517f6c4
3
+ metadata.gz: e38d2bbf3dd185f3f8c912537be54a0068c98db3c45b17edda9a53a01ccd63d8
4
+ data.tar.gz: 63393812f02d8841d6ee56c000d9400e0062f405d7eb95eccbd766a93877e7d8
5
5
  SHA512:
6
- metadata.gz: 323f765b32f2ed37f62a82dfff10b6bdc7c0c8670a441f340f2a910d8dfb17a9660726698b8c34dfb89522246003e8c7fde4a205d17b8511c3ec432027604a65
7
- data.tar.gz: ad243eb959c09b3bac8d58da961adec4c34b92844b239da2e541d599e2f1b78d738bdc3cc5db7b44c4817e18aa99be86d5adb74bac2e5614c01b57c027a0b562
6
+ metadata.gz: 1cf9450f7cf1fc7259bf5ec9a51f88141ce7e937aca94152577919117ff1fbec3311591f045b01864cd644b6ada45e71265656c91c067242da7c4195e987df27
7
+ data.tar.gz: ac79e34dab39a08445773c394b1912f7119605187cf2a09af670e94f54b2c2d786dc43a09968e50443881220d7d62f7bfcebf167521569b497d96603714962d5
@@ -1,7 +1,8 @@
1
1
  #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
2
3
 
3
4
  # enable local usage from cloned repo
4
- root = File.expand_path("../..", __FILE__)
5
+ root = File.expand_path('..', __dir__)
5
6
  $LOAD_PATH << "#{root}/lib" if File.exist?("#{root}/Gemfile")
6
7
 
7
8
  require 'forking_test_runner'
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  module ForkingTestRunner
2
3
  # read and delete options we support and pass the rest through to the underlying test runner (-v / --seed etc)
3
4
  module CLI
@@ -11,9 +12,9 @@ module ForkingTestRunner
11
12
  [
12
13
  :record_runtime,
13
14
  "--record-runtime=MODE",
14
- "\n Record test runtime:\n" <<
15
- " simple = write to disk at --runtime-log)\n" <<
16
- " amend = write from multiple remote workers via http://github.com/grosser/amend, needs TRAVIS_REPO_SLUG & TRAVIS_BUILD_NUMBER",
15
+ "\n Record test runtime:\n " \
16
+ "simple = write to disk at --runtime-log)\n " \
17
+ "amend = write from multiple remote workers via http://github.com/grosser/amend, needs TRAVIS_REPO_SLUG & TRAVIS_BUILD_NUMBER",
17
18
  String
18
19
  ],
19
20
  [:runtime_log, "--runtime-log=FILE", "File to store runtime log in or runtime.log", String],
@@ -22,7 +23,7 @@ module ForkingTestRunner
22
23
  [:groups, "--groups=NUM", "How many groups there are in total (use with --group)", Integer],
23
24
  [:version, "--version", "Show version"],
24
25
  [:help, "--help", "Show help"]
25
- ]
26
+ ].freeze
26
27
 
27
28
  class << self
28
29
  def parse_options(argv)
@@ -43,8 +44,8 @@ module ForkingTestRunner
43
44
  end
44
45
 
45
46
  # check if we can use merge_coverage
46
- if options.fetch(:merge_coverage)
47
- abort "merge_coverage does not work on ruby prior to 2.3" if RUBY_VERSION < "2.3.0"
47
+ if options.fetch(:merge_coverage) && "2.3.0" > RUBY_VERSION
48
+ abort "merge_coverage does not work on ruby prior to 2.3"
48
49
  end
49
50
 
50
51
  if !!options.fetch(:group) ^ !!options.fetch(:groups)
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  module ForkingTestRunner
2
3
  module CoverageCapture
3
4
  # override Coverage.result to add pre-fork captured coverage
@@ -7,8 +8,7 @@ module ForkingTestRunner
7
8
  end
8
9
 
9
10
  # deprecated, single_cov checks for this, so leave it here
10
- def capture_coverage!
11
- end
11
+ def capture_coverage!; end
12
12
 
13
13
  class << self
14
14
  attr_accessor :coverage
@@ -49,7 +49,7 @@ module ForkingTestRunner
49
49
  def merge_lines_coverage(a, b)
50
50
  b.each_with_index.map do |b_count, i|
51
51
  a_count = a[i]
52
- (a_count.nil? && b_count.nil?) ? nil : a_count.to_i + b_count.to_i
52
+ a_count.nil? && b_count.nil? ? nil : a_count.to_i + b_count.to_i
53
53
  end
54
54
  end
55
55
 
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  module ForkingTestRunner
2
- VERSION = "1.12.0"
3
+ VERSION = "1.14.0"
3
4
  end
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  require 'benchmark'
2
3
  require 'optparse'
3
4
  require 'forking_test_runner/version'
@@ -11,6 +12,8 @@ module ForkingTestRunner
11
12
  CONVERAGE_REPORT_PREFIX = "coverage/fork-"
12
13
 
13
14
  class << self
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,21 +37,24 @@ 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
- Parallel.map_with_index(test_groups, in_processes: parallel || 0) do |tests, env_index|
45
+ Parallel.map_with_index(test_groups, in_processes: parallel || 0) do |tests_group, env_index|
40
46
  if parallel
41
47
  ENV["TEST_ENV_NUMBER"] = (env_index == 0 ? '' : (env_index + 1).to_s) # NOTE: does not support first_is_1 option
42
48
  end
43
49
 
44
50
  reraise_clean_ar_error { load_test_env }
45
51
 
46
- tests.map do |file, expected|
52
+ tests_group.map do |file, expected|
47
53
  print_started file unless parallel
48
54
  result = [file, expected, *benchmark { run_test(file) }]
49
55
  sync_stdout lock do
50
56
  print_started file if parallel
51
- print_finished *result
57
+ print_finished(*result)
52
58
  end
53
59
  result
54
60
  end
@@ -58,9 +64,11 @@ module ForkingTestRunner
58
64
  unless @options.fetch(:quiet)
59
65
  # pretty print the results
60
66
  puts "\nResults:"
61
- puts results.
62
- sort_by { |_,_,_,r,_| r ? 0 : 1 }. # failures should be last so they are easy to find
63
- map { |f,_,_,r,_| "#{f}: #{r ? "OK" : "Fail"}"}
67
+ puts(
68
+ results
69
+ .sort_by { |_, _, _, r, _| r ? 0 : 1 } # failures should be last so they are easy to find
70
+ .map { |f, _, _, r, _| "#{f}: #{r ? "OK" : "Fail"}" }
71
+ )
64
72
  puts
65
73
  end
66
74
 
@@ -90,7 +98,7 @@ module ForkingTestRunner
90
98
 
91
99
  def with_lock(&block)
92
100
  return yield unless @options.fetch(:parallel)
93
- Tempfile.open"forking-test-runner-lock", &block
101
+ Tempfile.open "forking-test-runner-lock", &block
94
102
  end
95
103
 
96
104
  def sync_stdout(lock)
@@ -155,7 +163,7 @@ module ForkingTestRunner
155
163
  File.write(log, data)
156
164
  when 'amend'
157
165
  if id = ENV["BUILDKITE_JOB_ID"]
158
- slug = ENV.fetch("BUILDKITE_ORG_SLUG") + "-" + ENV.fetch("BUILDKITE_PIPELINE_SLUG")
166
+ slug = "#{ENV.fetch("BUILDKITE_ORG_SLUG")}-#{ENV.fetch("BUILDKITE_PIPELINE_SLUG")}"
159
167
  else
160
168
  slug = ENV.fetch("TRAVIS_REPO_SLUG").sub("/", "-")
161
169
  id = ENV.fetch("TRAVIS_BUILD_NUMBER")
@@ -195,6 +203,7 @@ module ForkingTestRunner
195
203
  preload_fixtures
196
204
  ActiveRecord::Base.connection.disconnect!
197
205
  end
206
+ @before_fork_callbacks.each(&:call)
198
207
 
199
208
  CoverageCapture.capture! if @options.fetch(:merge_coverage)
200
209
  end
@@ -205,7 +214,7 @@ module ForkingTestRunner
205
214
  e = begin
206
215
  yield
207
216
  nil
208
- rescue
217
+ rescue StandardError
209
218
  $!
210
219
  end
211
220
 
@@ -216,7 +225,7 @@ module ForkingTestRunner
216
225
  def load_test_helper
217
226
  disable_test_autorun
218
227
  require 'rspec/core' if @options.fetch(:rspec)
219
- helper = @options.fetch(:helper) || (@options.fetch(:rspec) ? "spec/spec_helper" : "test/test_helper")
228
+ helper = @options.fetch(:helper) || (@options.fetch(:rspec) ? "spec/spec_helper" : "test/test_helper")
220
229
  require "./#{helper}"
221
230
  end
222
231
 
@@ -261,7 +270,7 @@ module ForkingTestRunner
261
270
 
262
271
  wpipe.close
263
272
 
264
- buffer = ""
273
+ buffer = +""
265
274
 
266
275
  while ch = rpipe.read(1)
267
276
  buffer << ch
@@ -276,7 +285,11 @@ module ForkingTestRunner
276
285
  def preserve_tty
277
286
  was_tty = $stdout.tty?
278
287
  yield
279
- def $stdout.tty?; true; end if was_tty
288
+ if was_tty
289
+ def $stdout.tty?;
290
+ true;
291
+ end
292
+ end
280
293
  end
281
294
 
282
295
  def run_test(file)
@@ -289,6 +302,9 @@ module ForkingTestRunner
289
302
  if partial_reports_for_single_cov?
290
303
  SingleCov.coverage_report = "#{CONVERAGE_REPORT_PREFIX}#{Process.pid}.json"
291
304
  end
305
+
306
+ @after_fork_callbacks.each(&:call)
307
+
292
308
  if active_record?
293
309
  key = (ActiveRecord::VERSION::STRING >= "4.1.0" ? :test : "test")
294
310
  ActiveRecord::Base.establish_connection key
@@ -307,7 +323,8 @@ module ForkingTestRunner
307
323
  def change_program_name_to(name)
308
324
  return yield if @options.fetch(:parallel)
309
325
  begin
310
- old, $0 = $0, name
326
+ old = $0
327
+ $0 = name
311
328
  yield
312
329
  ensure
313
330
  $0 = old
@@ -328,7 +345,7 @@ module ForkingTestRunner
328
345
  group = groups[group - 1] || raise("Group #{group} not found")
329
346
 
330
347
  # return tests with runtime
331
- tests = Hash[tests]
348
+ tests = tests.to_h
332
349
  group.map { |test| [test, (tests[test] if group_by == :runtime)] }
333
350
  end
334
351
 
@@ -344,7 +361,7 @@ module ForkingTestRunner
344
361
  end
345
362
  end
346
363
 
347
- def toggle_test_autorun(value, file=nil)
364
+ def toggle_test_autorun(value, file = nil)
348
365
  if @options.fetch(:rspec)
349
366
  if value
350
367
  exit(RSpec::Core::Runner.run([file] + ARGV))
@@ -381,7 +398,7 @@ module ForkingTestRunner
381
398
  File.unlink(report) # do not leave junk behind
382
399
  end
383
400
 
384
- data = JSON.pretty_generate(key => {"coverage" => coverage, "timestamp" => Time.now.to_i })
401
+ data = JSON.pretty_generate(key => { "coverage" => coverage, "timestamp" => Time.now.to_i })
385
402
  File.write(SingleCov.coverage_report, data)
386
403
 
387
404
  # 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.12.0
4
+ version: 1.14.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Michael Grosser
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-05-19 00:00:00.000000000 Z
11
+ date: 2024-08-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: parallel_tests
@@ -39,21 +39,27 @@ dependencies:
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
41
  - !ruby/object:Gem::Dependency
42
- name: rake
42
+ name: bundler
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '2.3'
45
48
  - - ">="
46
49
  - !ruby/object:Gem::Version
47
- version: '0'
50
+ version: 2.3.27
48
51
  type: :development
49
52
  prerelease: false
50
53
  version_requirements: !ruby/object:Gem::Requirement
51
54
  requirements:
55
+ - - "~>"
56
+ - !ruby/object:Gem::Version
57
+ version: '2.3'
52
58
  - - ">="
53
59
  - !ruby/object:Gem::Version
54
- version: '0'
60
+ version: 2.3.27
55
61
  - !ruby/object:Gem::Dependency
56
- name: rspec
62
+ name: minitest
57
63
  requirement: !ruby/object:Gem::Requirement
58
64
  requirements:
59
65
  - - ">="
@@ -67,7 +73,7 @@ dependencies:
67
73
  - !ruby/object:Gem::Version
68
74
  version: '0'
69
75
  - !ruby/object:Gem::Dependency
70
- name: sqlite3
76
+ name: rake
71
77
  requirement: !ruby/object:Gem::Requirement
72
78
  requirements:
73
79
  - - ">="
@@ -81,7 +87,7 @@ dependencies:
81
87
  - !ruby/object:Gem::Version
82
88
  version: '0'
83
89
  - !ruby/object:Gem::Dependency
84
- name: minitest
90
+ name: rspec
85
91
  requirement: !ruby/object:Gem::Requirement
86
92
  requirements:
87
93
  - - ">="
@@ -94,7 +100,35 @@ dependencies:
94
100
  - - ">="
95
101
  - !ruby/object:Gem::Version
96
102
  version: '0'
97
- description:
103
+ - !ruby/object:Gem::Dependency
104
+ name: rubocop
105
+ requirement: !ruby/object:Gem::Requirement
106
+ requirements:
107
+ - - "~>"
108
+ - !ruby/object:Gem::Version
109
+ version: 1.65.1
110
+ type: :development
111
+ prerelease: false
112
+ version_requirements: !ruby/object:Gem::Requirement
113
+ requirements:
114
+ - - "~>"
115
+ - !ruby/object:Gem::Version
116
+ version: 1.65.1
117
+ - !ruby/object:Gem::Dependency
118
+ name: sqlite3
119
+ requirement: !ruby/object:Gem::Requirement
120
+ requirements:
121
+ - - "~>"
122
+ - !ruby/object:Gem::Version
123
+ version: 1.6.0
124
+ type: :development
125
+ prerelease: false
126
+ version_requirements: !ruby/object:Gem::Requirement
127
+ requirements:
128
+ - - "~>"
129
+ - !ruby/object:Gem::Version
130
+ version: 1.6.0
131
+ description:
98
132
  email: michael@grosser.it
99
133
  executables:
100
134
  - forking-test-runner
@@ -111,7 +145,7 @@ homepage: https://github.com/grosser/forking_test_runner
111
145
  licenses:
112
146
  - MIT
113
147
  metadata: {}
114
- post_install_message:
148
+ post_install_message:
115
149
  rdoc_options: []
116
150
  require_paths:
117
151
  - lib
@@ -119,15 +153,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
119
153
  requirements:
120
154
  - - ">="
121
155
  - !ruby/object:Gem::Version
122
- version: 2.5.0
156
+ version: 2.7.0
123
157
  required_rubygems_version: !ruby/object:Gem::Requirement
124
158
  requirements:
125
159
  - - ">="
126
160
  - !ruby/object:Gem::Version
127
161
  version: '0'
128
162
  requirements: []
129
- rubygems_version: 3.2.16
130
- signing_key:
163
+ rubygems_version: 3.4.10
164
+ signing_key:
131
165
  specification_version: 4
132
166
  summary: Run every test in a fork to avoid pollution and get clean output per test
133
167
  test_files: []