right_popen 1.0.2 → 1.0.3
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.
- data/Rakefile +5 -0
- data/lib/linux/right_popen.rb +0 -1
- data/right_popen.gemspec +3 -3
- data/spec/right_popen_spec.rb +57 -7
- metadata +2 -5
data/Rakefile
CHANGED
data/lib/linux/right_popen.rb
CHANGED
data/right_popen.gemspec
CHANGED
@@ -4,7 +4,7 @@ spec = Gem::Specification.new do |spec|
|
|
4
4
|
is_windows = RUBY_PLATFORM =~ /mswin/
|
5
5
|
|
6
6
|
spec.name = 'right_popen'
|
7
|
-
spec.version = '1.0.
|
7
|
+
spec.version = '1.0.3'
|
8
8
|
spec.authors = ['Scott Messier', 'Raphael Simon']
|
9
9
|
spec.email = 'scott@rightscale.com'
|
10
10
|
spec.homepage = 'https://github.com/rightscale/right_popen'
|
@@ -46,8 +46,8 @@ EOF
|
|
46
46
|
end
|
47
47
|
spec.files = candidates.sort!
|
48
48
|
|
49
|
-
# Current implementation
|
50
|
-
spec.add_runtime_dependency(%q<eventmachine>, [">= 0.12.8"
|
49
|
+
# Current implementation supports > 0.12.8
|
50
|
+
spec.add_runtime_dependency(%q<eventmachine>, [">= 0.12.8"])
|
51
51
|
if is_windows
|
52
52
|
spec.add_runtime_dependency(%q<win32-process>, [">= 0.6.1"])
|
53
53
|
end
|
data/spec/right_popen_spec.rb
CHANGED
@@ -10,32 +10,73 @@ EXIT_STATUS = 146
|
|
10
10
|
# for a quick smoke test
|
11
11
|
LARGE_OUTPUT_COUNTER = 1000
|
12
12
|
|
13
|
+
# bump up count for most exhaustive leak detection.
|
14
|
+
REPEAT_TEST_COUNTER = 256
|
15
|
+
|
13
16
|
describe 'RightScale::popen3' do
|
14
17
|
|
15
18
|
module RightPopenSpec
|
16
19
|
|
17
20
|
class Runner
|
18
21
|
def initialize
|
19
|
-
@done
|
22
|
+
@done = false
|
23
|
+
@output_text = nil
|
24
|
+
@error_text = nil
|
25
|
+
@status = nil
|
26
|
+
@last_exception = nil
|
27
|
+
@last_iteration = 0
|
28
|
+
end
|
29
|
+
|
30
|
+
attr_reader :output_text, :error_text, :status
|
31
|
+
|
32
|
+
def do_right_popen(command)
|
20
33
|
@output_text = ''
|
21
34
|
@error_text = ''
|
22
35
|
@status = nil
|
36
|
+
RightScale.popen3(command, self, :on_read_stdout, :on_read_stderr, :on_exit)
|
23
37
|
end
|
24
38
|
|
25
|
-
|
26
|
-
|
27
|
-
|
39
|
+
def run_right_popen(command, count = 1)
|
40
|
+
puts "#{count}>" if count > 1
|
41
|
+
last_iteration = 0
|
28
42
|
EM.next_tick do
|
29
|
-
|
43
|
+
do_right_popen(command)
|
30
44
|
end
|
31
45
|
EM.run do
|
32
|
-
timer = EM::PeriodicTimer.new(0.
|
33
|
-
|
46
|
+
timer = EM::PeriodicTimer.new(0.05) do
|
47
|
+
begin
|
48
|
+
if @done || @last_exception
|
49
|
+
last_iteration = last_iteration + 1
|
50
|
+
if @last_exception.nil? && last_iteration < count
|
51
|
+
@done = false
|
52
|
+
EM.next_tick do
|
53
|
+
if count > 1
|
54
|
+
print '+'
|
55
|
+
STDOUT.flush
|
56
|
+
end
|
57
|
+
do_right_popen(command)
|
58
|
+
end
|
59
|
+
else
|
60
|
+
puts "<" if count > 1
|
61
|
+
timer.cancel
|
62
|
+
EM.stop
|
63
|
+
end
|
64
|
+
end
|
65
|
+
rescue Exception => e
|
66
|
+
@last_exception = e
|
34
67
|
timer.cancel
|
35
68
|
EM.stop
|
36
69
|
end
|
37
70
|
end
|
38
71
|
end
|
72
|
+
if @last_exception
|
73
|
+
if count > 1
|
74
|
+
message = "<#{last_iteration + 1}\n#{last_exception.message}"
|
75
|
+
else
|
76
|
+
message = last_exception.message
|
77
|
+
end
|
78
|
+
raise @last_exception.class, "#{message}\n#{@last_exception.backtrace.join("\n")}"
|
79
|
+
end
|
39
80
|
end
|
40
81
|
|
41
82
|
def on_read_stdout(data)
|
@@ -122,4 +163,13 @@ describe 'RightScale::popen3' do
|
|
122
163
|
runner.error_text.should == results
|
123
164
|
end
|
124
165
|
|
166
|
+
it 'should run repeatedly without leaking resources' do
|
167
|
+
command = "\"#{RUBY_CMD}\" \"#{File.expand_path(File.join(File.dirname(__FILE__), 'produce_output.rb'))}\" \"#{STANDARD_MESSAGE}\" \"#{ERROR_MESSAGE}\""
|
168
|
+
runner = RightPopenSpec::Runner.new
|
169
|
+
runner.run_right_popen(command, REPEAT_TEST_COUNTER)
|
170
|
+
runner.status.exitstatus.should == 0
|
171
|
+
runner.output_text.should == STANDARD_MESSAGE + "\n"
|
172
|
+
runner.error_text.should == ERROR_MESSAGE + "\n"
|
173
|
+
end
|
174
|
+
|
125
175
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: right_popen
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Scott Messier
|
@@ -10,7 +10,7 @@ autorequire:
|
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
12
|
|
13
|
-
date: 2010-02-
|
13
|
+
date: 2010-02-18 00:00:00 -08:00
|
14
14
|
default_executable:
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
@@ -22,9 +22,6 @@ dependencies:
|
|
22
22
|
- - ">="
|
23
23
|
- !ruby/object:Gem::Version
|
24
24
|
version: 0.12.8
|
25
|
-
- - <
|
26
|
-
- !ruby/object:Gem::Version
|
27
|
-
version: 0.12.9
|
28
25
|
version:
|
29
26
|
description: |
|
30
27
|
RightPopen allows running external processes aynchronously while still
|