sensu-spawn 2.1.0 → 2.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +3 -7
- data/CHANGELOG.md +20 -0
- data/lib/sensu/spawn.rb +41 -19
- data/sensu-spawn.gemspec +1 -1
- data/spec/assets/{output_1MB → 1MB} +0 -0
- data/spec/spawn_spec.rb +24 -2
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 933b1edd838b280c1c606e6a5fbdd4932e6e6582
|
4
|
+
data.tar.gz: 7944ef71e84a4e1fabcef50e8b4a590b10824612
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ec39a9080eee2e4f2f1e0e18df4481672b18964b589eb00137889b82c24a1670e87a43e2bec644fd64fbadbcc34777f00e2c9067f8b3c100b5f5af0da43f8bdf
|
7
|
+
data.tar.gz: 8d79c64a92832767ef052479dee5ba1847d71a7c28f9e2232a5e8e6f9b8cf2eab05b6e3ffb41e590729c8b99ae5fb1a93a8961bb67fdbcf67acaecf36fabc6e5
|
data/.travis.yml
CHANGED
@@ -1,16 +1,12 @@
|
|
1
1
|
sudo: false
|
2
2
|
language: ruby
|
3
3
|
rvm:
|
4
|
-
- 1.8.7
|
5
|
-
- 1.9.2
|
6
|
-
- 1.9.3
|
7
4
|
- 2.0.0
|
8
5
|
- 2.1.0
|
6
|
+
- 2.2.0
|
9
7
|
- 2.2.3
|
10
|
-
-
|
8
|
+
- 2.3.0
|
9
|
+
- jruby-9.0.5.0
|
11
10
|
notifications:
|
12
11
|
irc:
|
13
12
|
- "irc.freenode.net#sensu"
|
14
|
-
addons:
|
15
|
-
code_climate:
|
16
|
-
repo_token: 6e0d725a7d86b1565bc5a8cfa218cf9fb59811b8d4b030e62b6a4745da9f0f96
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,23 @@
|
|
1
|
+
## 2.2.0 - 2016-05-26
|
2
|
+
|
3
|
+
### Fixes
|
4
|
+
|
5
|
+
Alternating between partial child process STDIN writes and STDOUT/ERR
|
6
|
+
reads, fixing the large STDIN write deadlock.
|
7
|
+
|
8
|
+
## 2.1.0 - 2016-05-26
|
9
|
+
|
10
|
+
### Fixes
|
11
|
+
|
12
|
+
Replaced ChildProcess poll_for_exit() with stdlib Timeout to fix large
|
13
|
+
child output deadlock.
|
14
|
+
|
15
|
+
## 2.0.0 - 2016-05-16
|
16
|
+
|
17
|
+
### Features
|
18
|
+
|
19
|
+
Configurable concurrent child process limit.
|
20
|
+
|
1
21
|
## 1.8.0 - 2016-03-16
|
2
22
|
|
3
23
|
### Fixes
|
data/lib/sensu/spawn.rb
CHANGED
@@ -58,8 +58,19 @@ module Sensu
|
|
58
58
|
# the current platform. ChildProcess supports POSIX Spawn for
|
59
59
|
# several platforms (OSs & architectures), however, Sensu only
|
60
60
|
# enables the use of POSIX Spawn on a select few.
|
61
|
+
#
|
62
|
+
# @return [TrueClass, FalseClass]
|
61
63
|
def posix_spawn?
|
62
|
-
@posix_spawn
|
64
|
+
return @posix_spawn unless @posix_spawn.nil?
|
65
|
+
@posix_spawn = POSIX_SPAWN_PLATFORMS.include?(ChildProcess.os)
|
66
|
+
end
|
67
|
+
|
68
|
+
# Determine if the current platform is Windows.
|
69
|
+
#
|
70
|
+
# @return [TrueClass, FalseClass]
|
71
|
+
def on_windows?
|
72
|
+
return @on_windows unless @on_windows.nil?
|
73
|
+
@on_windows = ChildProcess.windows?
|
63
74
|
end
|
64
75
|
|
65
76
|
# Build a child process attached to a pipe, in order to capture
|
@@ -71,8 +82,8 @@ module Sensu
|
|
71
82
|
# @return [Array] child object, pipe reader, pipe writer.
|
72
83
|
def build_child_process(command)
|
73
84
|
reader, writer = IO.pipe
|
74
|
-
shell = case
|
75
|
-
when
|
85
|
+
shell = case
|
86
|
+
when on_windows?
|
76
87
|
["cmd", "/c"]
|
77
88
|
else
|
78
89
|
["sh", "-c"]
|
@@ -85,17 +96,31 @@ module Sensu
|
|
85
96
|
[child, reader, writer]
|
86
97
|
end
|
87
98
|
|
88
|
-
#
|
99
|
+
# Write data to a stream/file and read a stream/file
|
100
|
+
# until end of file (EOF).
|
89
101
|
#
|
90
|
-
# @param [Object]
|
91
|
-
# @
|
92
|
-
|
102
|
+
# @param writer [Object] to write data to (optional).
|
103
|
+
# @param reader [Object] to read contents of until EOF.
|
104
|
+
# @param data [String] to be written to writer.
|
105
|
+
# @return [String] the reader stream/file contents.
|
106
|
+
def write_and_read(writer, reader, data)
|
107
|
+
buffer = (data || "").dup
|
93
108
|
output = ""
|
94
|
-
|
95
|
-
|
96
|
-
|
109
|
+
loop do
|
110
|
+
unless buffer.empty?
|
111
|
+
writer.write(buffer.slice!(0, 8191))
|
112
|
+
writer.close if buffer.empty?
|
113
|
+
end
|
114
|
+
begin
|
115
|
+
readable, _ = IO.select([reader], nil, nil, 0)
|
116
|
+
if readable || buffer.empty?
|
117
|
+
output << reader.readpartial(8192)
|
118
|
+
end
|
119
|
+
rescue EOFError
|
120
|
+
reader.close
|
121
|
+
break
|
122
|
+
end
|
97
123
|
end
|
98
|
-
reader.close
|
99
124
|
output
|
100
125
|
end
|
101
126
|
|
@@ -122,17 +147,14 @@ module Sensu
|
|
122
147
|
child.start
|
123
148
|
end
|
124
149
|
writer.close
|
125
|
-
|
126
|
-
child.io.stdin.write(options[:data])
|
127
|
-
child.io.stdin.close
|
128
|
-
end
|
150
|
+
output = ""
|
129
151
|
if options[:timeout]
|
130
|
-
|
131
|
-
|
152
|
+
Timeout::timeout(options[:timeout], ChildProcess::TimeoutError) do
|
153
|
+
output = write_and_read(child.io.stdin, reader, options[:data])
|
154
|
+
child.wait
|
132
155
|
end
|
133
|
-
child.wait
|
134
156
|
else
|
135
|
-
output =
|
157
|
+
output = write_and_read(child.io.stdin, reader, options[:data])
|
136
158
|
child.wait
|
137
159
|
end
|
138
160
|
[output, child.exit_code]
|
data/sensu-spawn.gemspec
CHANGED
File without changes
|
data/spec/spawn_spec.rb
CHANGED
@@ -19,7 +19,7 @@ describe "Sensu::Spawn" do
|
|
19
19
|
end
|
20
20
|
|
21
21
|
it "can spawn a process with output greater than 64KB" do |output, status|
|
22
|
-
output_asset = "spec/assets/
|
22
|
+
output_asset = "spec/assets/1MB"
|
23
23
|
expected_output = IO.read(output_asset)
|
24
24
|
async_wrapper do
|
25
25
|
Sensu::Spawn.process("cat #{output_asset}") do |output, status|
|
@@ -31,7 +31,7 @@ describe "Sensu::Spawn" do
|
|
31
31
|
end
|
32
32
|
|
33
33
|
it "can spawn a process with output greater than 64KB with a timeout" do |output, status|
|
34
|
-
output_asset = "spec/assets/
|
34
|
+
output_asset = "spec/assets/1MB"
|
35
35
|
expected_output = IO.read(output_asset)
|
36
36
|
async_wrapper do
|
37
37
|
Sensu::Spawn.process("cat #{output_asset}", :timeout => 10) do |output, status|
|
@@ -81,4 +81,26 @@ describe "Sensu::Spawn" do
|
|
81
81
|
end
|
82
82
|
end
|
83
83
|
end
|
84
|
+
|
85
|
+
it "can spawn a process that reads input greater than 64KB from STDIN" do |output, status|
|
86
|
+
input_asset = IO.read("spec/assets/1MB")
|
87
|
+
async_wrapper do
|
88
|
+
Sensu::Spawn.process("cat", :data => input_asset) do |output, status|
|
89
|
+
expect(output).to eq(input_asset)
|
90
|
+
expect(status).to eq(0)
|
91
|
+
async_done
|
92
|
+
end
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
96
|
+
it "can spawn a process that reads from STDIN and does not output to STDOUT" do
|
97
|
+
input_asset = IO.read("spec/assets/1MB")
|
98
|
+
async_wrapper do
|
99
|
+
Sensu::Spawn.process("cat > /tmp/sensu-spawn-test", :data => input_asset) do |output, status|
|
100
|
+
expect(output).to eq("")
|
101
|
+
expect(status).to eq(0)
|
102
|
+
async_done
|
103
|
+
end
|
104
|
+
end
|
105
|
+
end
|
84
106
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sensu-spawn
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
4
|
+
version: 2.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sean Porter
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-05-
|
11
|
+
date: 2016-05-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: eventmachine
|
@@ -110,7 +110,7 @@ files:
|
|
110
110
|
- Rakefile
|
111
111
|
- lib/sensu/spawn.rb
|
112
112
|
- sensu-spawn.gemspec
|
113
|
-
- spec/assets/
|
113
|
+
- spec/assets/1MB
|
114
114
|
- spec/helpers.rb
|
115
115
|
- spec/spawn_spec.rb
|
116
116
|
homepage: https://github.com/sensu/sensu-spawn
|
@@ -138,6 +138,6 @@ signing_key:
|
|
138
138
|
specification_version: 4
|
139
139
|
summary: The Sensu spawn process library
|
140
140
|
test_files:
|
141
|
-
- spec/assets/
|
141
|
+
- spec/assets/1MB
|
142
142
|
- spec/helpers.rb
|
143
143
|
- spec/spawn_spec.rb
|