Skip to content

Commit 17bb968

Browse files
author
Peter Degen-Portnoy
committed
Merge pull request #16 from notalex/OTWO-3218
OTWO-3218: Fix hung processes due to full io buffers
2 parents 2c2ac14 + 6147fb8 commit 17bb968

File tree

2 files changed

+27
-12
lines changed

2 files changed

+27
-12
lines changed

lib/scm/shellout.rb

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,18 +9,8 @@ def self.relay src, dst
99
end
1010

1111
def self.execute(cmd)
12-
out = ''
13-
err = ''
14-
exit_status = nil
15-
Open3.popen3(cmd) { |stdin, stdout, stderr, wait_thread|
16-
while line = stdout.gets
17-
out << line
18-
end
19-
while line = stderr.gets
20-
err << line
21-
end
22-
exit_status = wait_thread.value
23-
}
12+
out, err, exit_status = Open3.capture3(cmd)
13+
2414
return exit_status, out, err
2515
end
2616

test/unit/shellout_test.rb

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
require_relative '../test_helper'
2+
3+
class ShelloutTest < Scm::Test
4+
def test_execute_must_pipe_the_results_accurately
5+
status, out, err = Shellout.execute("ruby -e 'puts %[hello world]; STDERR.puts(%[some error])'")
6+
7+
assert_equal out, "hello world\n"
8+
assert_equal err, "some error\n"
9+
assert_equal status.success?, true
10+
end
11+
12+
def test_execute_must_return_appropriate_status_for_a_failed_process
13+
status, out, err = Shellout.execute("ruby -e 'exit(1)'")
14+
15+
assert_equal status.success?, false
16+
end
17+
18+
def test_execute_must_not_hang_when_io_buffer_is_full
19+
assert_nothing_raised do
20+
Timeout::timeout(1) do
21+
Shellout.execute("ruby -e 'STDERR.puts(%[some line\n] * 10000)'")
22+
end
23+
end
24+
end
25+
end

0 commit comments

Comments
 (0)