Skip to content

Commit 9bcca30

Browse files
rheniumk0kubun
authored andcommitted
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. (cherry picked from commit fa8df43)
1 parent 844a167 commit 9bcca30

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
@@ -1802,46 +1802,29 @@ def test_fallback_to_sh
18021802

18031803
def test_spawn_too_long_path
18041804
bug4314 = '[ruby-core:34842]'
1805-
assert_fail_too_long_path(%w"echo", bug4314)
1805+
assert_fail_too_long_path(false, bug4314)
18061806
end
18071807

18081808
def test_aspawn_too_long_path
1809-
bug4315 = '[ruby-core:34833] #7904 [ruby-core:52628] #11613'
1810-
assert_fail_too_long_path(%w"echo |", bug4315)
1809+
bug4315 = '[ruby-core:34833]'
1810+
assert_fail_too_long_path(true, bug4315)
18111811
end
18121812

1813-
def assert_fail_too_long_path((cmd, sep), mesg)
1814-
sep ||= ""
1815-
min = 1_000 / (cmd.size + sep.size)
1816-
cmds = Array.new(min, cmd)
1813+
def assert_fail_too_long_path(use_shell, mesg)
1814+
cmd = "a" * 10_000_000
1815+
cmd.prepend("echo|") if use_shell
18171816
exs = [Errno::ENOENT]
18181817
exs << Errno::EINVAL if windows?
18191818
exs << Errno::E2BIG if defined?(Errno::E2BIG)
18201819
opts = {[STDOUT, STDERR]=>File::NULL}
1821-
if defined?(Process::RLIMIT_NPROC)
1822-
opts[:rlimit_nproc] = /openbsd/i =~ RUBY_PLATFORM ? 64 : 128
1823-
end
1824-
EnvUtil.suppress_warning do
1825-
assert_raise(*exs, mesg) do
1826-
begin
1827-
loop do
1828-
Process.spawn(cmds.join(sep), opts)
1829-
min = [cmds.size, min].max
1830-
begin
1831-
cmds *= 100
1832-
rescue ArgumentError
1833-
raise NoMemoryError
1834-
end
1835-
end
1836-
rescue NoMemoryError
1837-
size = cmds.size
1838-
raise if min >= size - 1
1839-
min = [min, size /= 2].max
1840-
cmds[size..-1] = []
1841-
raise if size < 250
1842-
retry
1843-
end
1820+
begin
1821+
EnvUtil.suppress_warning do
1822+
Process.spawn(cmd, opts)
18441823
end
1824+
rescue => e
1825+
assert_include(exs, e.class, mesg)
1826+
else
1827+
omit "system supports very long command line; skipping"
18451828
end
18461829
end
18471830

0 commit comments

Comments
 (0)