Skip to content

Commit a672b34

Browse files
author
Vladimir Kotal
committed
add test for long lines
1 parent 3d8ff14 commit a672b34

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

opengrok-tools/src/test/python/test_command.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,32 @@ def test_stderr():
169169
assert 'root' in "\n".join(cmd.getoutput())
170170

171171

172+
# This test needs the "/bin/cat" command, therefore it is Unix only.
173+
@pytest.mark.skipif(not os.name.startswith("posix"), reason="requires posix")
174+
def test_long_output():
175+
"""
176+
Test that output thread in the Command class captures all of the output.
177+
(and also it does not hang the command by filling up the pipe)
178+
"""
179+
# in bytes, should be enough to fill a pipe
180+
num_lines = 500
181+
line_length = 1000
182+
with tempfile.NamedTemporaryFile() as file:
183+
for _ in range(num_lines):
184+
file.write(b'A' * line_length)
185+
file.write(b'\n')
186+
file.flush()
187+
assert os.path.getsize(file.name) == num_lines * (line_length + 1)
188+
189+
cmd = Command(["/bin/cat", file.name])
190+
cmd.execute()
191+
192+
assert cmd.getstate() == Command.FINISHED
193+
assert cmd.getretcode() == 0
194+
assert cmd.geterroutput() is None
195+
assert len(cmd.getoutputstr()) == num_lines * (line_length + 1)
196+
197+
172198
@pytest.mark.skipif(not os.name.startswith("posix"), reason="requires posix")
173199
def test_resource_limits():
174200
"""

0 commit comments

Comments
 (0)