em_pessimistic 0.1.2 → 0.2.0

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.
@@ -3,6 +3,7 @@
3
3
  # The MIT License (MIT)
4
4
  #
5
5
  # Copyright (C) 2012 Gitorious AS
6
+ # Copyright (C) 2013 Andrey Chergik
6
7
  #
7
8
  # Permission is hereby granted, free of charge, to any person obtaining a copy
8
9
  # of this software and associated documentation files (the "Software"), to deal
@@ -50,9 +51,9 @@ module EMPessimistic
50
51
  def unbind
51
52
  status = get_status
52
53
  if status.exitstatus != 0
53
- fail(@stderr.join.strip, status)
54
+ fail(@stderr.join.strip, @stdout.join.strip, status)
54
55
  else
55
- succeed(@stdout.join.strip, status)
56
+ succeed(@stdout.join.strip, @stderr.join.strip, status)
56
57
  end
57
58
  end
58
59
  end
@@ -3,6 +3,7 @@
3
3
  # The MIT License (MIT)
4
4
  #
5
5
  # Copyright (C) 2012 Gitorious AS
6
+ # Copyright (C) 2013 Andrey Chergik
6
7
  #
7
8
  # Permission is hereby granted, free of charge, to any person obtaining a copy
8
9
  # of this software and associated documentation files (the "Software"), to deal
@@ -44,7 +45,10 @@ module EMPessimistic
44
45
  $stderr.reopen(wr)
45
46
  connection = EM.popen(*args)
46
47
  $stderr.reopen(new_stderr)
47
- EM.attach(rd, Popen3StderrHandler, connection)
48
+ EM.attach(rd, Popen3StderrHandler, connection) do |c|
49
+ wr.close
50
+ new_stderr.close
51
+ end
48
52
  connection
49
53
  end
50
54
  end
@@ -2,7 +2,7 @@
2
2
  # --
3
3
  # The MIT License (MIT)
4
4
  #
5
- # Copyright (C) 2012 Gitorious AS
5
+ # Copyright (C) 2012-2013 Gitorious AS
6
6
  #
7
7
  # Permission is hereby granted, free of charge, to any person obtaining a copy
8
8
  # of this software and associated documentation files (the "Software"), to deal
@@ -24,5 +24,5 @@
24
24
  #++
25
25
 
26
26
  module EMPessimistic
27
- VERSION = "0.1.2"
27
+ VERSION = "0.2.0"
28
28
  end
@@ -30,8 +30,8 @@ describe EMPessimistic::DeferrableChildProcess do
30
30
 
31
31
  it "passes stdout data and status to callback on success" do
32
32
  process = EMPessimistic::DeferrableChildProcess.open("ls -l")
33
- process.callback do |data, status|
34
- assert_match /em_pessimistic\.gemspec/, data
33
+ process.callback do |stdout, stderr, status|
34
+ assert_match /em_pessimistic\.gemspec/, stdout
35
35
  assert_equal 0, status.exitstatus
36
36
  done!
37
37
  end
@@ -41,8 +41,8 @@ describe EMPessimistic::DeferrableChildProcess do
41
41
  it "passes stderr data and status to errback on error" do
42
42
  cmd = "git ls-tree master:Gemfile"
43
43
  process = EMPessimistic::DeferrableChildProcess.open(cmd)
44
- process.errback do |data, status|
45
- assert_equal "fatal: not a tree object", data
44
+ process.errback do |stderr, stdout, status|
45
+ assert_equal "fatal: not a tree object", stderr
46
46
  assert_equal 128, status.exitstatus
47
47
  done!
48
48
  end
@@ -0,0 +1,77 @@
1
+ # encoding: utf-8
2
+ # --
3
+ # The MIT License (MIT)
4
+ #
5
+ # Copyright (C) 2013 Andrey Chergik
6
+ #
7
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
8
+ # of this software and associated documentation files (the "Software"), to deal
9
+ # in the Software without restriction, including without limitation the rights
10
+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11
+ # copies of the Software, and to permit persons to whom the Software is
12
+ # furnished to do so, subject to the following conditions:
13
+ #
14
+ # The above copyright notice and this permission notice shall be included in all
15
+ # copies or substantial portions of the Software.
16
+ #
17
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23
+ # SOFTWARE.
24
+ #++
25
+ require "test_helper"
26
+ require 'fosl/parser'
27
+ require "em_pessimistic/deferrable_child_process"
28
+
29
+ describe EMPessimistic::DeferrableChildProcess do
30
+ include EM::MiniTest::Spec
31
+
32
+ def timeout_interval
33
+ 5
34
+ end
35
+
36
+ it "has no dubious opened pipes and unix domain sockets after all child processes exited" do
37
+
38
+ parse = FOSL::Parser.new
39
+ pid = Process.pid
40
+ finished = 0
41
+
42
+ # Increase this amount to your ("system opened file descriptors limit" / 3) and you will meet "Errno::EMFILE: Too many open files" exception.
43
+ amount = 1
44
+
45
+ EM.add_periodic_timer(1) do
46
+
47
+ data = Hash[parse.lsof("+p #{pid}")[pid].files.group_by { |f| f[:type] }.select { |k,v| /^(?:unix|PIPE)$/.match(k) }]
48
+ if finished == amount
49
+ assert data["PIPE"], 'there are several PIPEs owned by this process'
50
+
51
+ # One Pipe is for "lsof" process. Two others for EM loop.
52
+ assert_equal 3, data["PIPE"].length
53
+ assert !data["unix"], 'all unix domain sockets for this process are closed'
54
+ done!
55
+ else
56
+ ap data
57
+ end
58
+
59
+ end
60
+
61
+ amount.times do |i|
62
+ process = EMPessimistic::DeferrableChildProcess.open("ruby -v")
63
+
64
+ process.callback do |stdout, stderr, status|
65
+ finished += 1
66
+ end
67
+
68
+ process.errback do |stderr, stdout, status|
69
+ finished += 1
70
+ end
71
+ end
72
+
73
+ wait!
74
+
75
+ end
76
+ end
77
+
metadata CHANGED
@@ -1,133 +1,139 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: em_pessimistic
3
- version: !ruby/object:Gem::Version
4
- hash: 31
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.2.0
5
5
  prerelease:
6
- segments:
7
- - 0
8
- - 1
9
- - 2
10
- version: 0.1.2
11
6
  platform: ruby
12
- authors:
7
+ authors:
13
8
  - Christian Johansen
9
+ - Andrey Chergik
14
10
  autorequire:
15
11
  bindir: bin
16
12
  cert_chain: []
17
-
18
- date: 2012-09-19 00:00:00 +02:00
19
- default_executable:
20
- dependencies:
21
- - !ruby/object:Gem::Dependency
13
+ date: 2013-02-04 00:00:00.000000000 Z
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
22
16
  name: eventmachine
23
- prerelease: false
24
- requirement: &id001 !ruby/object:Gem::Requirement
17
+ requirement: !ruby/object:Gem::Requirement
25
18
  none: false
26
- requirements:
19
+ requirements:
27
20
  - - ~>
28
- - !ruby/object:Gem::Version
29
- hash: 15
30
- segments:
31
- - 1
32
- - 0
33
- version: "1.0"
21
+ - !ruby/object:Gem::Version
22
+ version: '1.0'
34
23
  type: :runtime
35
- version_requirements: *id001
36
- - !ruby/object:Gem::Dependency
37
- name: minitest
38
24
  prerelease: false
39
- requirement: &id002 !ruby/object:Gem::Requirement
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ none: false
27
+ requirements:
28
+ - - ~>
29
+ - !ruby/object:Gem::Version
30
+ version: '1.0'
31
+ - !ruby/object:Gem::Dependency
32
+ name: minitest
33
+ requirement: !ruby/object:Gem::Requirement
40
34
  none: false
41
- requirements:
35
+ requirements:
42
36
  - - ~>
43
- - !ruby/object:Gem::Version
44
- hash: 3
45
- segments:
46
- - 2
47
- - 0
48
- version: "2.0"
37
+ - !ruby/object:Gem::Version
38
+ version: '2.0'
49
39
  type: :development
50
- version_requirements: *id002
51
- - !ruby/object:Gem::Dependency
52
- name: em-minitest-spec
53
40
  prerelease: false
54
- requirement: &id003 !ruby/object:Gem::Requirement
41
+ version_requirements: !ruby/object:Gem::Requirement
55
42
  none: false
56
- requirements:
43
+ requirements:
57
44
  - - ~>
58
- - !ruby/object:Gem::Version
59
- hash: 13
60
- segments:
61
- - 1
62
- - 1
63
- version: "1.1"
45
+ - !ruby/object:Gem::Version
46
+ version: '2.0'
47
+ - !ruby/object:Gem::Dependency
48
+ name: em-minitest-spec
49
+ requirement: !ruby/object:Gem::Requirement
50
+ none: false
51
+ requirements:
52
+ - - ~>
53
+ - !ruby/object:Gem::Version
54
+ version: '1.1'
64
55
  type: :development
65
- version_requirements: *id003
66
- - !ruby/object:Gem::Dependency
56
+ prerelease: false
57
+ version_requirements: !ruby/object:Gem::Requirement
58
+ none: false
59
+ requirements:
60
+ - - ~>
61
+ - !ruby/object:Gem::Version
62
+ version: '1.1'
63
+ - !ruby/object:Gem::Dependency
67
64
  name: rake
65
+ requirement: !ruby/object:Gem::Requirement
66
+ none: false
67
+ requirements:
68
+ - - ~>
69
+ - !ruby/object:Gem::Version
70
+ version: '0.9'
71
+ type: :development
68
72
  prerelease: false
69
- requirement: &id004 !ruby/object:Gem::Requirement
73
+ version_requirements: !ruby/object:Gem::Requirement
70
74
  none: false
71
- requirements:
75
+ requirements:
72
76
  - - ~>
73
- - !ruby/object:Gem::Version
74
- hash: 25
75
- segments:
76
- - 0
77
- - 9
78
- version: "0.9"
77
+ - !ruby/object:Gem::Version
78
+ version: '0.9'
79
+ - !ruby/object:Gem::Dependency
80
+ name: fosl
81
+ requirement: !ruby/object:Gem::Requirement
82
+ none: false
83
+ requirements:
84
+ - - ~>
85
+ - !ruby/object:Gem::Version
86
+ version: 0.0.1
79
87
  type: :development
80
- version_requirements: *id004
81
- description: EventMachine's built-in popen does not provide access to stderr. Likewise, it's DeferrableChildProcess does not use an errback for when the process fails. This gem fixes both of those mistakes.
82
- email:
88
+ prerelease: false
89
+ version_requirements: !ruby/object:Gem::Requirement
90
+ none: false
91
+ requirements:
92
+ - - ~>
93
+ - !ruby/object:Gem::Version
94
+ version: 0.0.1
95
+ description: EventMachine's built-in popen does not provide access to stderr. Likewise,
96
+ it's DeferrableChildProcess does not use an errback for when the process fails.
97
+ This gem fixes both of those mistakes.
98
+ email:
83
99
  - christian@gitorious.org
100
+ - achergik@gmail.com
84
101
  executables: []
85
-
86
102
  extensions: []
87
-
88
103
  extra_rdoc_files: []
89
-
90
- files:
104
+ files:
91
105
  - lib/em_pessimistic.rb
92
106
  - lib/em_pessimistic/deferrable_child_process.rb
93
107
  - lib/em_pessimistic/popen3.rb
94
108
  - lib/em_pessimistic/version.rb
95
109
  - test/em_pessimistic/deferrable_child_process_test.rb
110
+ - test/em_pessimistic/opened_descriptors_leak_test.rb
96
111
  - test/test_helper.rb
97
- has_rdoc: true
98
112
  homepage: http://gitorious.org/gitorious/em_pessimistic
99
113
  licenses: []
100
-
101
114
  post_install_message:
102
115
  rdoc_options: []
103
-
104
- require_paths:
116
+ require_paths:
105
117
  - lib
106
- required_ruby_version: !ruby/object:Gem::Requirement
118
+ required_ruby_version: !ruby/object:Gem::Requirement
107
119
  none: false
108
- requirements:
109
- - - ">="
110
- - !ruby/object:Gem::Version
111
- hash: 3
112
- segments:
113
- - 0
114
- version: "0"
115
- required_rubygems_version: !ruby/object:Gem::Requirement
120
+ requirements:
121
+ - - ! '>='
122
+ - !ruby/object:Gem::Version
123
+ version: '0'
124
+ required_rubygems_version: !ruby/object:Gem::Requirement
116
125
  none: false
117
- requirements:
118
- - - ">="
119
- - !ruby/object:Gem::Version
120
- hash: 3
121
- segments:
122
- - 0
123
- version: "0"
126
+ requirements:
127
+ - - ! '>='
128
+ - !ruby/object:Gem::Version
129
+ version: '0'
124
130
  requirements: []
125
-
126
131
  rubyforge_project: em_pessimistic
127
- rubygems_version: 1.4.2
132
+ rubygems_version: 1.8.24
128
133
  signing_key:
129
134
  specification_version: 3
130
135
  summary: popen with stderr and DeferrableChildProcess with errback for EventMachine
131
- test_files:
136
+ test_files:
132
137
  - test/em_pessimistic/deferrable_child_process_test.rb
138
+ - test/em_pessimistic/opened_descriptors_leak_test.rb
133
139
  - test/test_helper.rb