minitest-parallel_fork 1.1.2 → 1.2.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: 03e48c02a4df6b51494a491f98a873028c7c394a58f3507a5818f7697af70208
4
- data.tar.gz: ac75886465a2883f7631f38663ff9c20923492cdc03b58d80a3694dbc6b91430
3
+ metadata.gz: 9c152ef9216b8cbc9700f7f7e0281847695b325e660b51268b0d148a44e5aba2
4
+ data.tar.gz: 9d0739abeb8ccfaeb0ed023cb75b4fe30bb3f6e509af6d952204042229356649
5
5
  SHA512:
6
- metadata.gz: ecb985d07f4b65d0496a4b33b01215e8863882a3a1e6131178285a573305c3a0aab70de56c4759f7b02d491d827f336644fdeb443c4bcdedebb4447187b827be
7
- data.tar.gz: ea0eb216c1b9ed8c2edb1ba21b6d8db81a54b307ae5a3a63db99b0fca0e1fb1e8c3ad46d6adb2ae2bb1c6a92de092c20a9045bdf5a4c477bfb52996a4f7e6ae8
6
+ metadata.gz: e075bac95ab8dd13987e59533ace22ff48d878db63399659764f7af6c553cf835282b39044b50592ec776ab5ebc2d1af095bc9d8df955c0b230cce3cfe58a2e3
7
+ data.tar.gz: 57448ca69342f474102377fb287c67d298db98147bef22450d721cdae0acc4e9f65aad7d3e3937fc834118fd10e6200ced55d04609bc7ac43527dc1d6b63f5c7
data/CHANGELOG CHANGED
@@ -1,3 +1,9 @@
1
+ === 1.2.0 (2021-08-16)
2
+
3
+ * Work correctly with Minitest 5.14+ (jeremyevans)
4
+
5
+ * Add on_parallel_fork_marshal_failure hook for handling marshal failures (child process exiting) (jeremyevans)
6
+
1
7
  === 1.1.2 (2018-07-05)
2
8
 
3
9
  * Handle raised exceptions containing unmarshallable data (jeremyevans)
data/README.rdoc CHANGED
@@ -59,6 +59,15 @@ disconnected, and after forking, the database name is changed in each child to r
59
59
  a child-specific database, so that the child processes do not share a database and are
60
60
  thus independent.
61
61
 
62
+ There is also a hook for debugging. +on_parallel_fork_marshal_failure+ is called if
63
+ there is an error unmarshalling data sent from the child process to the parent process.
64
+ This can happen if one of the child processes exits unexpected during the test, before
65
+ it reports results.
66
+
67
+ Minitest.on_parallel_fork_marshal_failure do
68
+ # Gather relevant logs for more debugging
69
+ end
70
+
62
71
  == ActiveRecord
63
72
 
64
73
  To use this with Rails/ActiveRecord, you probably want to use hooks similar to:
@@ -6,11 +6,19 @@ module Minitest
6
6
  def self.before_parallel_fork(&block)
7
7
  @before_parallel_fork = block
8
8
  end
9
+ @before_parallel_fork = nil
9
10
 
10
11
  # Set the after_parallel_fork block to the given block
11
12
  def self.after_parallel_fork(i=nil, &block)
12
13
  @after_parallel_fork = block
13
14
  end
15
+ @after_parallel_fork = nil
16
+
17
+ # Set the on_parallel_fork_marshal_failure block to the given block
18
+ def self.on_parallel_fork_marshal_failure(&block)
19
+ @on_parallel_fork_marshal_failure = block
20
+ end
21
+ @on_parallel_fork_marshal_failure = nil
14
22
 
15
23
  module Unparallelize
16
24
  define_method(:run_one_method, &Minitest::Test.method(:run_one_method))
@@ -28,7 +36,7 @@ module Minitest
28
36
 
29
37
  n = (ENV['NCPU'] || 4).to_i
30
38
  reads = []
31
- if defined?(@before_parallel_fork)
39
+ if @before_parallel_fork
32
40
  @before_parallel_fork.call
33
41
  end
34
42
  n.times do |i|
@@ -36,7 +44,7 @@ module Minitest
36
44
  reads << read
37
45
  fork do
38
46
  read.close
39
- if defined?(@after_parallel_fork)
47
+ if @after_parallel_fork
40
48
  @after_parallel_fork.call(i)
41
49
  end
42
50
 
@@ -60,12 +68,17 @@ module Minitest
60
68
  data[-1].each do |result|
61
69
  result.failures.each do |failure|
62
70
  if failure.is_a?(Minitest::UnexpectedError)
63
- e = failure.exception
71
+ e = failure.respond_to?(:error) ? failure.error : failure.exception
64
72
  begin
65
73
  Marshal.dump(e)
66
74
  rescue TypeError
67
- failure.exception = RuntimeError.new("Wrapped undumpable exception for: #{e.class}: #{e.message}")
68
- failure.exception.set_backtrace(e.backtrace)
75
+ e2 = RuntimeError.new("Wrapped undumpable exception for: #{e.class}: #{e.message}")
76
+ e2.set_backtrace(e.backtrace)
77
+ if failure.respond_to?(:error=)
78
+ failure.error = e2
79
+ else
80
+ failure.exception = e2
81
+ end
69
82
  end
70
83
  end
71
84
  end
@@ -78,7 +91,14 @@ module Minitest
78
91
  end
79
92
 
80
93
  reads.map{|read| Thread.new(read, &:read)}.map(&:value).each do |data|
81
- count, assertions, results = Marshal.load(data)
94
+ begin
95
+ count, assertions, results = Marshal.load(data)
96
+ rescue ArgumentError
97
+ if @on_parallel_fork_marshal_failure
98
+ @on_parallel_fork_marshal_failure.call
99
+ end
100
+ raise
101
+ end
82
102
  stat_reporter.count += count
83
103
  stat_reporter.assertions += assertions
84
104
  stat_reporter.results.concat(results)
@@ -1,5 +1,5 @@
1
1
  gem 'minitest'
2
- require 'minitest/autorun'
2
+ require 'minitest/global_expectations/autorun'
3
3
  require 'minitest/parallel_fork'
4
4
 
5
5
  a = nil
@@ -12,6 +12,12 @@ Minitest.after_parallel_fork do |i|
12
12
  print ":child#{i}#{a}"
13
13
  end
14
14
 
15
+ if ENV['MPF_TEST_CHILD_FAILURE']
16
+ Minitest.on_parallel_fork_marshal_failure do |i|
17
+ print ":child-failure#{i}#{a}"
18
+ end
19
+ end
20
+
15
21
  class MyExceptionClass < StandardError
16
22
  attr_reader :something
17
23
  end
@@ -27,7 +33,8 @@ end
27
33
  end
28
34
 
29
35
  it "should work" do
30
- sleep(1).must_equal 1
36
+ sleep(1)
37
+ 1.must_equal 1
31
38
  end
32
39
 
33
40
  it "should fail" do
@@ -35,6 +42,7 @@ end
35
42
  end
36
43
 
37
44
  it "should raise" do
45
+ exit(1) if ENV['MPF_TEST_CHILD_FAILURE']
38
46
  raise
39
47
  end
40
48
 
@@ -1,6 +1,6 @@
1
1
  ENV['MT_NO_PLUGINS'] = '1'
2
2
  gem 'minitest'
3
- require 'minitest/autorun'
3
+ require 'minitest/global_expectations/autorun'
4
4
 
5
5
  describe 'minitest/parallel_fork' do
6
6
  [[nil, ''],
@@ -24,4 +24,17 @@ describe 'minitest/parallel_fork' do
24
24
  end
25
25
  end
26
26
  end
27
+
28
+ it "should call on_parallel_fork_marshal_failure on failure" do
29
+ t = Time.now
30
+ ENV['NCPU'] = '4'
31
+ ENV['MPF_TEST_CHILD_FAILURE'] = '1'
32
+ output = `#{ENV['RUBY']} -I lib spec/minitest_parallel_fork_example.rb 2>&1`
33
+ ENV.delete('MPF_TEST_CHILD_FAILURE')
34
+
35
+ time = (Time.now - t)
36
+ time.must_be :<, 4
37
+ output.must_match /:child-failurea/
38
+ output.must_match /marshal data too short/
39
+ end
27
40
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: minitest-parallel_fork
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.2
4
+ version: 1.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jeremy Evans
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-07-05 00:00:00.000000000 Z
11
+ date: 2021-08-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: minitest
@@ -24,6 +24,20 @@ dependencies:
24
24
  - - ">="
25
25
  - !ruby/object:Gem::Version
26
26
  version: 5.11.0
27
+ - !ruby/object:Gem::Dependency
28
+ name: minitest-global_expectations
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'
27
41
  description: |
28
42
  minitest-parallel_fork adds fork-based parallelization to Minitest. Each test/spec
29
43
  suite is run in one of the forks, allowing this to work correctly when using
@@ -72,8 +86,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
72
86
  - !ruby/object:Gem::Version
73
87
  version: '0'
74
88
  requirements: []
75
- rubyforge_project:
76
- rubygems_version: 2.7.6
89
+ rubygems_version: 3.2.22
77
90
  signing_key:
78
91
  specification_version: 4
79
92
  summary: Fork-based parallelization for minitest