Skip to content

Commit fa8df43

Browse files
committed
test/ruby/test_process.rb: simplify testing spawn with long strings
test_aspawn_too_long_path just wants to verify that passing a very long string to spawn does not cause a crash. Use an input string that is long enough for this purpose and does not ends up with spawning too many processes. This change makes this test run much faster on systems where /bin/sh is bash, which retries fork() several times with long delays before giving up.
1 parent a4cccea commit fa8df43

1 file changed

Lines changed: 13 additions & 30 deletions

File tree

‎test/ruby/test_process.rb‎

Lines changed: 13 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1855,46 +1855,29 @@ def test_fallback_to_sh
18551855

18561856
def test_spawn_too_long_path
18571857
bug4314 = '[ruby-core:34842]'
1858-
assert_fail_too_long_path(%w"echo", bug4314)
1858+
assert_fail_too_long_path(false, bug4314)
18591859
end
18601860

18611861
def test_aspawn_too_long_path
1862-
bug4315 = '[ruby-core:34833] #7904 [ruby-core:52628] #11613'
1863-
assert_fail_too_long_path(%w"echo |", bug4315)
1862+
bug4315 = '[ruby-core:34833]'
1863+
assert_fail_too_long_path(true, bug4315)
18641864
end
18651865

1866-
def assert_fail_too_long_path((cmd, sep), mesg)
1867-
sep ||= ""
1868-
min = 1_000 / (cmd.size + sep.size)
1869-
cmds = Array.new(min, cmd)
1866+
def assert_fail_too_long_path(use_shell, mesg)
1867+
cmd = "a" * 10_000_000
1868+
cmd.prepend("echo|") if use_shell
18701869
exs = [Errno::ENOENT]
18711870
exs << Errno::EINVAL if windows?
18721871
exs << Errno::E2BIG if defined?(Errno::E2BIG)
18731872
opts = {[STDOUT, STDERR]=>File::NULL}
1874-
if defined?(Process::RLIMIT_NPROC)
1875-
opts[:rlimit_nproc] = /openbsd/i =~ RUBY_PLATFORM ? 64 : 128
1876-
end
1877-
EnvUtil.suppress_warning do
1878-
assert_raise(*exs, mesg) do
1879-
begin
1880-
loop do
1881-
Process.spawn(cmds.join(sep), opts)
1882-
min = [cmds.size, min].max
1883-
begin
1884-
cmds *= 100
1885-
rescue ArgumentError
1886-
raise NoMemoryError
1887-
end
1888-
end
1889-
rescue NoMemoryError
1890-
size = cmds.size
1891-
raise if min >= size - 1
1892-
min = [min, size /= 2].max
1893-
cmds[size..-1] = []
1894-
raise if size < 250
1895-
retry
1896-
end
1873+
begin
1874+
EnvUtil.suppress_warning do
1875+
Process.spawn(cmd, opts)
18971876
end
1877+
rescue => e
1878+
assert_include(exs, e.class, mesg)
1879+
else
1880+
omit "system supports very long command line; skipping"
18981881
end
18991882
end
19001883

0 commit comments

Comments
 (0)