process-helper 1.0.0 → 1.1.0
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 +7 -0
- data/spec/process_helper_spec.rb +15 -0
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d5801c46c90163e46beb528091ad2dfa932cafd0
|
4
|
+
data.tar.gz: c8fa6a8f6b5c503b3ea2369bd0b15264badef55d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f78e7ad32fd2720831db9ff75982665e305f975c91be07c659f4618c885d83e86543705efcfc56d4b2b90f516b6bda43db36724082fd1ff3e787c6fd94fb390b
|
7
|
+
data.tar.gz: 4088d5ed29f3ad6ab9c6a01c38655c318a33b9fe35bfafb59ea6299ad6ef11278a7f2d1f6229870591d1a5456c7732450bf2e1b5ee37a2870777c5e7614ded23
|
data/lib/process-helper.rb
CHANGED
@@ -99,6 +99,7 @@ module ProcessHelper
|
|
99
99
|
@lines = prefill.dup
|
100
100
|
@mutex = Mutex.new
|
101
101
|
@opts = opts
|
102
|
+
@eof = false
|
102
103
|
end
|
103
104
|
|
104
105
|
def start
|
@@ -108,10 +109,15 @@ module ProcessHelper
|
|
108
109
|
STDOUT.puts l if @opts[:print_lines]
|
109
110
|
@mutex.synchronize { @lines.push l }
|
110
111
|
end
|
112
|
+
@mutex.synchronize { @eof = true }
|
111
113
|
end
|
112
114
|
self
|
113
115
|
end
|
114
116
|
|
117
|
+
def eof
|
118
|
+
@mutex.synchronize { !!@eof }
|
119
|
+
end
|
120
|
+
|
115
121
|
def wait_for_output(regex, opts = {})
|
116
122
|
opts = { :poll_rate => 0.25 }.merge(opts)
|
117
123
|
opts[:timeout] ||= 30
|
@@ -119,6 +125,7 @@ module ProcessHelper
|
|
119
125
|
until _any_line_matches(regex)
|
120
126
|
sleep(opts[:poll_rate])
|
121
127
|
fail "Timeout of #{opts[:timeout]} seconds exceeded while waiting for output that matches '#{regex}'" if DateTime.now > cutoff
|
128
|
+
fail "EOF encountered while waiting for output that matches '#{regex}'" if eof and !_any_line_matches(regex)
|
122
129
|
end
|
123
130
|
end
|
124
131
|
|
data/spec/process_helper_spec.rb
CHANGED
@@ -97,6 +97,21 @@ module ProcessHelper
|
|
97
97
|
expect(startup_log[-1]).to eq("frog\n")
|
98
98
|
end
|
99
99
|
|
100
|
+
it 'It should give up when EOF is hit' do
|
101
|
+
t0 = Time.now
|
102
|
+
process = ProcessHelper.new
|
103
|
+
expect {
|
104
|
+
process.start(
|
105
|
+
['sh', '-c', 'sleep 1'],
|
106
|
+
/this message never appears/,
|
107
|
+
5,
|
108
|
+
)
|
109
|
+
}.to raise_error(/EOF/)
|
110
|
+
t1 = Time.now
|
111
|
+
|
112
|
+
expect((t1-t0-1).abs).to be < 0.5 # didn't wait for timeout
|
113
|
+
end
|
114
|
+
|
100
115
|
it 'It should be able to arbitrarly wait for output' do
|
101
116
|
t0 = Time.now
|
102
117
|
process = ProcessHelper.new
|
metadata
CHANGED
@@ -1,10 +1,11 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: process-helper
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
|
-
-
|
7
|
+
- rachel evans
|
8
|
+
- fae hutter
|
8
9
|
- andrew wheat
|
9
10
|
- tristan hill
|
10
11
|
- robert shield
|
@@ -56,7 +57,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
56
57
|
version: '0'
|
57
58
|
requirements: []
|
58
59
|
rubyforge_project:
|
59
|
-
rubygems_version: 2.
|
60
|
+
rubygems_version: 2.4.3
|
60
61
|
signing_key:
|
61
62
|
specification_version: 4
|
62
63
|
summary: Utility for managing sub processes.
|