right_popen 1.1.3 → 3.0.1
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.
- checksums.yaml +7 -0
- data/README.rdoc +2 -0
- data/lib/right_popen.rb +35 -31
- data/lib/right_popen/linux/popen3_async.rb +26 -10
- data/lib/right_popen/linux/process.rb +21 -25
- data/lib/right_popen/{linux/popen3_sync.rb → popen3_sync.rb} +2 -1
- data/lib/right_popen/process_base.rb +20 -16
- data/lib/right_popen/process_status.rb +3 -0
- data/lib/right_popen/safe_output_buffer.rb +3 -0
- data/lib/right_popen/target_proxy.rb +12 -8
- data/right_popen.gemspec +57 -31
- metadata +39 -128
- data/Rakefile +0 -127
- data/lib/right_popen/linux/accumulator.rb +0 -127
- data/lib/right_popen/linux/utilities.rb +0 -94
- data/lib/right_popen/version.rb +0 -28
- data/spec/background.rb +0 -28
- data/spec/increment.rb +0 -2
- data/spec/print_env.rb +0 -2
- data/spec/produce_mixed_output.rb +0 -12
- data/spec/produce_output.rb +0 -2
- data/spec/produce_status.rb +0 -1
- data/spec/produce_stderr_only.rb +0 -5
- data/spec/produce_stdout_only.rb +0 -5
- data/spec/right_popen/linux/accumulator_spec.rb +0 -267
- data/spec/right_popen/linux/utilities_spec.rb +0 -178
- data/spec/right_popen/safe_output_buffer_spec.rb +0 -26
- data/spec/right_popen_spec.rb +0 -331
- data/spec/runner.rb +0 -217
- data/spec/sleeper.rb +0 -35
- data/spec/spec_helper.rb +0 -26
- data/spec/stdout.rb +0 -28
- data/spec/writer.rb +0 -34
data/spec/runner.rb
DELETED
@@ -1,217 +0,0 @@
|
|
1
|
-
#-- -*- mode: ruby; encoding: utf-8 -*-
|
2
|
-
# Copyright: Copyright (c) 2011 RightScale, Inc.
|
3
|
-
#
|
4
|
-
# Permission is hereby granted, free of charge, to any person obtaining
|
5
|
-
# a copy of this software and associated documentation files (the
|
6
|
-
# 'Software'), to deal in the Software without restriction, including
|
7
|
-
# without limitation the rights to use, copy, modify, merge, publish,
|
8
|
-
# distribute, sublicense, and/or sell copies of the Software, and to
|
9
|
-
# permit persons to whom the Software is furnished to do so, subject to
|
10
|
-
# the following conditions:
|
11
|
-
#
|
12
|
-
# The above copyright notice and this permission notice shall be
|
13
|
-
# included in all copies or substantial portions of the Software.
|
14
|
-
#
|
15
|
-
# THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
|
16
|
-
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
17
|
-
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
18
|
-
# IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
19
|
-
# CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
20
|
-
# TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
21
|
-
# SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
22
|
-
#++
|
23
|
-
|
24
|
-
module RightScale
|
25
|
-
module RightPopen
|
26
|
-
class Runner
|
27
|
-
class RunnerStatus
|
28
|
-
def initialize(command, options={}, &callback)
|
29
|
-
options = {:repeats=>1, :force_yield=>nil, :timeout=>nil, :expect_timeout=>false}.merge(options)
|
30
|
-
|
31
|
-
@command = command
|
32
|
-
@output_text = ""
|
33
|
-
@error_text = ""
|
34
|
-
@status = nil
|
35
|
-
@did_timeout = false
|
36
|
-
@callback = callback
|
37
|
-
@pid = nil
|
38
|
-
@force_yield = options[:force_yield]
|
39
|
-
|
40
|
-
@expect_timeout = options[:expect_timeout]
|
41
|
-
@expect_size_limit = options[:expect_size_limit]
|
42
|
-
end
|
43
|
-
|
44
|
-
attr_accessor :output_text, :error_text, :status, :pid
|
45
|
-
attr_accessor :did_timeout, :did_size_limit
|
46
|
-
|
47
|
-
def on_read_stdout(data)
|
48
|
-
sleep @force_yield if @force_yield
|
49
|
-
@output_text << data
|
50
|
-
end
|
51
|
-
|
52
|
-
def on_read_stderr(data)
|
53
|
-
sleep @force_yield if @force_yield
|
54
|
-
@error_text << data
|
55
|
-
end
|
56
|
-
|
57
|
-
def on_pid(pid)
|
58
|
-
raise "PID already set!" unless @pid.nil?
|
59
|
-
@pid = pid
|
60
|
-
end
|
61
|
-
|
62
|
-
def on_timeout
|
63
|
-
puts "\n** Failed to run #{@command.inspect}: Timeout" unless @expect_timeout
|
64
|
-
@did_timeout = true
|
65
|
-
@callback.call(self) if @expect_timeout
|
66
|
-
end
|
67
|
-
|
68
|
-
def on_size_limit
|
69
|
-
puts "\n** Failed to run #{@command.inspect}: Size limit" unless @expect_size_limit
|
70
|
-
@did_size_limit = true
|
71
|
-
@callback.call(self) if @expect_size_limit
|
72
|
-
end
|
73
|
-
|
74
|
-
def on_exit(status)
|
75
|
-
@status = status
|
76
|
-
@callback.call(self)
|
77
|
-
end
|
78
|
-
end
|
79
|
-
|
80
|
-
def initialize
|
81
|
-
@count = 0
|
82
|
-
@done = false
|
83
|
-
@last_exception = nil
|
84
|
-
@last_iteration = 0
|
85
|
-
end
|
86
|
-
|
87
|
-
def run_right_popen3(synchronicity, command, runner_options={}, &callback)
|
88
|
-
runner_options = {
|
89
|
-
:repeats => 1,
|
90
|
-
:expect_timeout => false,
|
91
|
-
:expect_size_limit => false
|
92
|
-
}.merge(runner_options)
|
93
|
-
popen3_options = {
|
94
|
-
:input => runner_options[:input],
|
95
|
-
:environment => runner_options[:env],
|
96
|
-
:timeout_seconds => runner_options.has_key?(:timeout) ? runner_options[:timeout] : 2,
|
97
|
-
:size_limit_bytes => runner_options[:size_limit_bytes],
|
98
|
-
:watch_directory => runner_options[:watch_directory]
|
99
|
-
}
|
100
|
-
case synchronicity
|
101
|
-
when :sync
|
102
|
-
run_right_popen3_sync(command, runner_options, popen3_options, &callback)
|
103
|
-
when :async
|
104
|
-
run_right_popen3_async(command, runner_options, popen3_options, &callback)
|
105
|
-
else
|
106
|
-
raise "unknown synchronicity = #{synchronicity.inspect}"
|
107
|
-
end
|
108
|
-
end
|
109
|
-
|
110
|
-
def run_right_popen3_sync(command, runner_options, popen3_options, &callback)
|
111
|
-
begin
|
112
|
-
@iterations = 0
|
113
|
-
@repeats = runner_options[:repeats]
|
114
|
-
@stats = []
|
115
|
-
while @iterations < @repeats
|
116
|
-
@iterations += 1
|
117
|
-
do_right_popen3_sync(command, runner_options, popen3_options) do |runner_status|
|
118
|
-
@stats << runner_status
|
119
|
-
callback.call(runner_status) if callback
|
120
|
-
if @repeats > 1
|
121
|
-
puts if 1 == (@iterations % 64)
|
122
|
-
print '+'
|
123
|
-
puts if @iterations == @repeats
|
124
|
-
end
|
125
|
-
end
|
126
|
-
end
|
127
|
-
@stats.uniq!
|
128
|
-
@stats.size < 2 ? @stats.first : @stats
|
129
|
-
rescue Exception => e
|
130
|
-
puts "\n** Failed: #{e.message} FROM\n#{e.backtrace.join("\n")}"
|
131
|
-
raise e
|
132
|
-
end
|
133
|
-
end
|
134
|
-
|
135
|
-
def run_right_popen3_async(command, runner_options, popen3_options, &callback)
|
136
|
-
begin
|
137
|
-
@iterations = 0
|
138
|
-
@repeats = runner_options[:repeats]
|
139
|
-
@stats = []
|
140
|
-
EM.run do
|
141
|
-
EM.defer do
|
142
|
-
begin
|
143
|
-
do_right_popen3_async(command, runner_options, popen3_options) do |runner_status|
|
144
|
-
maybe_continue_popen3_async(runner_status, command, runner_options, popen3_options, &callback)
|
145
|
-
end
|
146
|
-
rescue Exception => e
|
147
|
-
puts e.class, e.message, e.backtrace.join("\n")
|
148
|
-
EM.stop
|
149
|
-
end
|
150
|
-
end
|
151
|
-
end
|
152
|
-
@stats.uniq!
|
153
|
-
@stats.size < 2 ? @stats.first : @stats
|
154
|
-
rescue Exception => e
|
155
|
-
puts "\n** Failed: #{e.message} FROM\n#{e.backtrace.join("\n")}"
|
156
|
-
raise e
|
157
|
-
end
|
158
|
-
end
|
159
|
-
|
160
|
-
def do_right_popen3(synchronicity, command, runner_options, popen3_options, &callback)
|
161
|
-
runner_status = RunnerStatus.new(command, runner_options, &callback)
|
162
|
-
popen3_options = {
|
163
|
-
:target => runner_status,
|
164
|
-
:stdout_handler => :on_read_stdout,
|
165
|
-
:stderr_handler => :on_read_stderr,
|
166
|
-
:pid_handler => :on_pid,
|
167
|
-
:timeout_handler => :on_timeout,
|
168
|
-
:size_limit_handler => :on_size_limit,
|
169
|
-
:exit_handler => :on_exit
|
170
|
-
}.merge(popen3_options)
|
171
|
-
case synchronicity
|
172
|
-
when :sync
|
173
|
-
result = ::RightScale::RightPopen.popen3_sync(command, popen3_options)
|
174
|
-
when :async
|
175
|
-
result = ::RightScale::RightPopen.popen3_async(command, popen3_options)
|
176
|
-
else
|
177
|
-
raise "Uknown synchronicity = #{synchronicity.inspect}"
|
178
|
-
end
|
179
|
-
result.should == true
|
180
|
-
true
|
181
|
-
end
|
182
|
-
|
183
|
-
def do_right_popen3_sync(command, runner_options, popen3_options, &callback)
|
184
|
-
do_right_popen3(:sync, command, runner_options, popen3_options, &callback)
|
185
|
-
end
|
186
|
-
|
187
|
-
def do_right_popen3_async(command, runner_options, popen3_options, &callback)
|
188
|
-
do_right_popen3(:async, command, runner_options, popen3_options, &callback)
|
189
|
-
end
|
190
|
-
|
191
|
-
def maybe_continue_popen3_async(runner_status, command, runner_options, popen3_options, &callback)
|
192
|
-
@iterations += 1
|
193
|
-
@stats << runner_status
|
194
|
-
callback.call(runner_status) if callback
|
195
|
-
if @iterations < @repeats
|
196
|
-
if @repeats > 1
|
197
|
-
puts if 1 == (@iterations % 64)
|
198
|
-
print '+'
|
199
|
-
puts if @iterations == @repeats
|
200
|
-
end
|
201
|
-
EM.defer do
|
202
|
-
begin
|
203
|
-
do_right_popen3_async(command, runner_options, popen3_options) do |runner_status2|
|
204
|
-
maybe_continue_popen3_async(runner_status2, command, runner_options, popen3_options, &callback)
|
205
|
-
end
|
206
|
-
rescue Exception => e
|
207
|
-
puts e.class, e.message, e.backtrace.join("\n")
|
208
|
-
EM.stop
|
209
|
-
end
|
210
|
-
end
|
211
|
-
else
|
212
|
-
EM.stop
|
213
|
-
end
|
214
|
-
end
|
215
|
-
end
|
216
|
-
end
|
217
|
-
end
|
data/spec/sleeper.rb
DELETED
@@ -1,35 +0,0 @@
|
|
1
|
-
#-- -*- mode: ruby; encoding: utf-8 -*-
|
2
|
-
# Copyright: Copyright (c) 2011 RightScale, Inc.
|
3
|
-
#
|
4
|
-
# Permission is hereby granted, free of charge, to any person obtaining
|
5
|
-
# a copy of this software and associated documentation files (the
|
6
|
-
# 'Software'), to deal in the Software without restriction, including
|
7
|
-
# without limitation the rights to use, copy, modify, merge, publish,
|
8
|
-
# distribute, sublicense, and/or sell copies of the Software, and to
|
9
|
-
# permit persons to whom the Software is furnished to do so, subject to
|
10
|
-
# the following conditions:
|
11
|
-
#
|
12
|
-
# The above copyright notice and this permission notice shall be
|
13
|
-
# included in all copies or substantial portions of the Software.
|
14
|
-
#
|
15
|
-
# THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
|
16
|
-
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
17
|
-
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
18
|
-
# IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
19
|
-
# CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
20
|
-
# TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
21
|
-
# SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
22
|
-
#++
|
23
|
-
|
24
|
-
REPEATS = (ARGV[0] || '4').to_i
|
25
|
-
|
26
|
-
STDOUT.sync = true
|
27
|
-
STDERR.sync = true
|
28
|
-
REPEATS.times do |i|
|
29
|
-
STDOUT.puts "To sleep... #{i}"
|
30
|
-
STDERR.puts "Perchance to dream... #{i}"
|
31
|
-
sleep 1
|
32
|
-
end
|
33
|
-
STDOUT.puts "The sleeper must awaken."
|
34
|
-
|
35
|
-
exit 0
|
data/spec/spec_helper.rb
DELETED
@@ -1,26 +0,0 @@
|
|
1
|
-
require 'rubygems'
|
2
|
-
require 'bundler/setup'
|
3
|
-
require 'spec'
|
4
|
-
require 'eventmachine'
|
5
|
-
require 'flexmock'
|
6
|
-
require File.join(File.dirname(__FILE__), '..', 'lib', 'right_popen')
|
7
|
-
|
8
|
-
RUBY_CMD = 'ruby'
|
9
|
-
STANDARD_MESSAGE = 'Standard message'
|
10
|
-
ERROR_MESSAGE = 'Error message'
|
11
|
-
EXIT_STATUS = 146
|
12
|
-
|
13
|
-
# manually bump count up for more aggressive multi-processor testing, lessen
|
14
|
-
# for a quick smoke test
|
15
|
-
LARGE_OUTPUT_COUNTER = 1000
|
16
|
-
|
17
|
-
# bump up count for most exhaustive leak detection.
|
18
|
-
REPEAT_TEST_COUNTER = 256
|
19
|
-
|
20
|
-
def is_windows?
|
21
|
-
return RUBY_PLATFORM =~ /mswin/
|
22
|
-
end
|
23
|
-
|
24
|
-
Spec::Runner.configure do |config|
|
25
|
-
config.mock_with :flexmock
|
26
|
-
end
|
data/spec/stdout.rb
DELETED
@@ -1,28 +0,0 @@
|
|
1
|
-
#-- -*- mode: ruby; encoding: utf-8 -*-
|
2
|
-
# Copyright: Copyright (c) 2011 RightScale, Inc.
|
3
|
-
#
|
4
|
-
# Permission is hereby granted, free of charge, to any person obtaining
|
5
|
-
# a copy of this software and associated documentation files (the
|
6
|
-
# 'Software'), to deal in the Software without restriction, including
|
7
|
-
# without limitation the rights to use, copy, modify, merge, publish,
|
8
|
-
# distribute, sublicense, and/or sell copies of the Software, and to
|
9
|
-
# permit persons to whom the Software is furnished to do so, subject to
|
10
|
-
# the following conditions:
|
11
|
-
#
|
12
|
-
# The above copyright notice and this permission notice shall be
|
13
|
-
# included in all copies or substantial portions of the Software.
|
14
|
-
#
|
15
|
-
# THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
|
16
|
-
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
17
|
-
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
18
|
-
# IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
19
|
-
# CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
20
|
-
# TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
21
|
-
# SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
22
|
-
#++
|
23
|
-
|
24
|
-
$stderr.puts "Closing stdout"
|
25
|
-
STDOUT.close
|
26
|
-
sleep 15
|
27
|
-
$stderr.puts "Exiting"
|
28
|
-
exit 0
|
data/spec/writer.rb
DELETED
@@ -1,34 +0,0 @@
|
|
1
|
-
#-- -*- mode: ruby; encoding: utf-8 -*-
|
2
|
-
# Copyright: Copyright (c) 2011 RightScale, Inc.
|
3
|
-
#
|
4
|
-
# Permission is hereby granted, free of charge, to any person obtaining
|
5
|
-
# a copy of this software and associated documentation files (the
|
6
|
-
# 'Software'), to deal in the Software without restriction, including
|
7
|
-
# without limitation the rights to use, copy, modify, merge, publish,
|
8
|
-
# distribute, sublicense, and/or sell copies of the Software, and to
|
9
|
-
# permit persons to whom the Software is furnished to do so, subject to
|
10
|
-
# the following conditions:
|
11
|
-
#
|
12
|
-
# The above copyright notice and this permission notice shall be
|
13
|
-
# included in all copies or substantial portions of the Software.
|
14
|
-
#
|
15
|
-
# THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
|
16
|
-
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
17
|
-
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
18
|
-
# IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
19
|
-
# CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
20
|
-
# TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
21
|
-
# SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
22
|
-
#++
|
23
|
-
|
24
|
-
watched_dir = ARGV[0]
|
25
|
-
|
26
|
-
10.times do |i|
|
27
|
-
path = ::File.join(watched_dir, "file#{i}.txt")
|
28
|
-
::File.open(path, 'w') do |f|
|
29
|
-
f.write 'x' * 100
|
30
|
-
end
|
31
|
-
sleep 0.2
|
32
|
-
end
|
33
|
-
|
34
|
-
exit 0
|