@@ -33,14 +33,58 @@ def bisect(cli_args, expected_status=nil)
33
33
end
34
34
end
35
35
36
- context "when the bisect commasaturingnd is long " do
36
+ context "when the bisect command saturates the pipe " do
37
37
# On OSX and Linux a file descriptor limit meant that the bisect process got stuck at a certain limit.
38
38
# This test demonstrates that we can run large bisects above this limit (found to be at time of commit).
39
39
# See: https://github.com/rspec/rspec-core/pull/2669
40
40
it 'does not hit pipe size limit and does not get stuck' do
41
41
output = bisect ( %W[ spec/rspec/core/resources/blocking_pipe_bisect_spec.rb_ ] , 1 )
42
42
expect ( output ) . to include ( "No failures found." )
43
43
end
44
+
45
+ it 'does not leave zombie processes' , :unless => RSpec ::Support ::OS . windows? do
46
+ bisect ( [ '--format' , 'json' , 'spec/rspec/core/resources/blocking_pipe_bisect_spec.rb_' ] , 1 )
47
+
48
+ zombie_process = RSpecChildProcess . new ( Process . pid ) . zombie_process
49
+ expect ( zombie_process ) . to eq ( [ ] ) , <<-MSG
50
+ Expected no zombie processes got #{ zombie_process . count } :
51
+ #{ zombie_process }
52
+ MSG
53
+ end
54
+ end
55
+
56
+ class RSpecChildProcess
57
+ Ps = Struct . new ( :pid , :ppid , :state , :command )
58
+
59
+ def initialize ( pid )
60
+ @list = child_process_list ( pid )
61
+ end
62
+
63
+ def zombie_process
64
+ @list . select { |child_process | child_process . state =~ /Z/ }
65
+ end
66
+
67
+ private
68
+
69
+ def child_process_list ( pid )
70
+ childs_process_list = [ ]
71
+ ps_pipe = `ps -o pid=,ppid=,state=,args= | grep #{ pid } `
72
+
73
+ ps_pipe . split ( /\n / ) . map do |line |
74
+ ps_part = line . lstrip . split ( /\s +/ )
75
+
76
+ next unless ps_part [ 1 ] . to_i == pid
77
+
78
+ child_process = Ps . new
79
+ child_process . pid = ps_part [ 0 ]
80
+ child_process . ppid = ps_part [ 1 ]
81
+ child_process . state = ps_part [ 2 ]
82
+ child_process . command = ps_part [ 3 ..-1 ] . join ( ' ' )
83
+
84
+ childs_process_list << child_process
85
+ end
86
+ childs_process_list
87
+ end
44
88
end
45
89
end
46
90
end
0 commit comments