process_helper 0.1.0 → 0.1.1.pre.beta.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/process_helper.rb +16 -6
- data/process_helper.gemspec +1 -1
- data/spec/pty_handling_spec.rb +11 -2
- data/spec/timeout_handling_spec.rb +13 -0
- metadata +5 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6c2a977c3f8a1d8982bb46d4bf4468ee89211ab8
|
4
|
+
data.tar.gz: 351b82ea95ddab8f1145ed76ec89c125debe307e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c9d4da553d29cd0bda49283e252d67cb4235980664228b94ccee75fdb6c64a2065698f014bed10541e6e651ae097880f073f0011995a31b24e967965cd5f42b5
|
7
|
+
data.tar.gz: 36e04a719ad86b5da40bcc4575b1a24162c8d00dd133cf0063ee2301830f088c52c7bfa22a7f7b1fd545c461a44f7f760457229b2461ad050ebe42c0115bb144
|
data/lib/process_helper.rb
CHANGED
@@ -10,7 +10,7 @@ require 'stringio'
|
|
10
10
|
# Full documentation at https://github.com/thewoolleyman/process_helper
|
11
11
|
module ProcessHelper
|
12
12
|
# Don't forget to keep version in sync with gemspec
|
13
|
-
VERSION = '0.1.
|
13
|
+
VERSION = '0.1.1.pre.beta.1'.freeze
|
14
14
|
|
15
15
|
# rubocop:disable Style/ModuleFunction
|
16
16
|
extend self
|
@@ -48,11 +48,20 @@ module ProcessHelper
|
|
48
48
|
end
|
49
49
|
|
50
50
|
def process_with_pseudo_terminal(cmd, options)
|
51
|
+
max_seconds_to_wait_for_pid_to_exit = options[:timeout] || 60
|
51
52
|
PTY.spawn(cmd) do |stdout_and_stderr, stdin, pid|
|
52
53
|
output = get_output(stdin, stdout_and_stderr, options)
|
53
|
-
|
54
|
-
|
55
|
-
|
54
|
+
# TODO: come up with a test that illustrates pid not exiting by the time PTY exits
|
55
|
+
process_status = nil
|
56
|
+
begin
|
57
|
+
Timeout.timeout(max_seconds_to_wait_for_pid_to_exit) do
|
58
|
+
process_status = PTY.check(pid) until process_status
|
59
|
+
sleep 0.1 unless process_status
|
60
|
+
end
|
61
|
+
rescue Timeout::Error
|
62
|
+
additional_msg = "Pid #{pid} did not exit after its pseudo-terminal (PTY) returned."
|
63
|
+
handle_timeout_error(output, options, max_seconds_to_wait_for_pid_to_exit, additional_msg)
|
64
|
+
end
|
56
65
|
return [output, process_status]
|
57
66
|
end
|
58
67
|
end
|
@@ -119,8 +128,9 @@ module ProcessHelper
|
|
119
128
|
output
|
120
129
|
end
|
121
130
|
|
122
|
-
def handle_timeout_error(output, options)
|
123
|
-
msg = "Timed out after #{options.fetch(:timeout)} seconds."
|
131
|
+
def handle_timeout_error(output, options, seconds = nil, additional_msg = nil)
|
132
|
+
msg = "Timed out after #{options.fetch(:timeout, seconds)} seconds."
|
133
|
+
msg += " #{additional_msg}" if additional_msg
|
124
134
|
if options[:include_output_in_exception]
|
125
135
|
msg += " Command output prior to timeout: \"#{output}\""
|
126
136
|
end
|
data/process_helper.gemspec
CHANGED
@@ -3,7 +3,7 @@
|
|
3
3
|
Gem::Specification.new do |spec|
|
4
4
|
spec.name = 'process_helper'
|
5
5
|
# Don't forget to keep version in sync with ProcessHelper::Version
|
6
|
-
spec.version = '0.1.
|
6
|
+
spec.version = '0.1.1.pre.beta.1'
|
7
7
|
spec.authors = ['Chad Woolley', 'Glenn Oppegard']
|
8
8
|
spec.email = ['oppegard@gmail.com', 'thewoolleyman@gmail.com']
|
9
9
|
spec.summary = "Makes it easier to spawn ruby sub-processes with proper capturing /
|
data/spec/pty_handling_spec.rb
CHANGED
@@ -34,14 +34,23 @@ RSpec.describe 'pty handling' do
|
|
34
34
|
end
|
35
35
|
|
36
36
|
it 'handles linux behavior of raising Errno::EIO when pty slave is closed' do
|
37
|
-
# nothing really special about this test, all the specs in this file
|
38
|
-
# fail on linux, just documenting...
|
39
37
|
expect do
|
40
38
|
clazz.process('echo "hi" && exit 1', pty: true, exp_st: 1)
|
41
39
|
end.to output(/hi/).to_stdout
|
42
40
|
.and(not_output.to_stderr)
|
43
41
|
end
|
44
42
|
|
43
|
+
it 'can timeout if process does not exit when pty ends' do
|
44
|
+
@max_process_wait = 0.2
|
45
|
+
allow(PTY).to receive(:check).and_return(nil)
|
46
|
+
expect do
|
47
|
+
clazz.process('echo', pty: true, exp_st: 1, timeout: @max_process_wait)
|
48
|
+
end.to raise_error(
|
49
|
+
ProcessHelper::TimeoutError,
|
50
|
+
%r(Timed out after #{@max_process_wait} seconds..*did not exit.*PTY.*)
|
51
|
+
)
|
52
|
+
end
|
53
|
+
|
45
54
|
it 'does not require a newline or flush via getch' do
|
46
55
|
skip('TODO: this test just hangs, including in a debugger')
|
47
56
|
expect do
|
@@ -22,6 +22,19 @@ RSpec.describe 'timout handling with non-exiting blocking cmd requiring timeout'
|
|
22
22
|
)
|
23
23
|
end
|
24
24
|
|
25
|
+
it 'raises on sleep with a PTY' do
|
26
|
+
expect do
|
27
|
+
clazz.process(
|
28
|
+
'sleep 999',
|
29
|
+
timeout: max_process_wait,
|
30
|
+
pty: true
|
31
|
+
)
|
32
|
+
end.to raise_error(
|
33
|
+
ProcessHelper::TimeoutError,
|
34
|
+
"Timed out after #{@max_process_wait} seconds. Command output prior to timeout: \"\""
|
35
|
+
)
|
36
|
+
end
|
37
|
+
|
25
38
|
it 'does not raise error if timeout is not exceeded' do
|
26
39
|
expect do
|
27
40
|
clazz.process(
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: process_helper
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1.pre.beta.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Chad Woolley
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2017-
|
12
|
+
date: 2017-05-05 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: bundler
|
@@ -185,12 +185,12 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
185
185
|
version: 1.9.2
|
186
186
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
187
187
|
requirements:
|
188
|
-
- - "
|
188
|
+
- - ">"
|
189
189
|
- !ruby/object:Gem::Version
|
190
|
-
version:
|
190
|
+
version: 1.3.1
|
191
191
|
requirements: []
|
192
192
|
rubyforge_project:
|
193
|
-
rubygems_version: 2.
|
193
|
+
rubygems_version: 2.6.8
|
194
194
|
signing_key:
|
195
195
|
specification_version: 4
|
196
196
|
summary: Makes it easier to spawn ruby sub-processes with proper capturing / of stdout
|