Skip to content
Snippets Groups Projects
Commit 58111b18 authored by Guillaume Chanel's avatar Guillaume Chanel
Browse files

Add pipe test with more data than the pipe size

Several students implemented the pipe in two steps:
- write all
- read all

This test was designed to detect this problem
parent dcffe4ad
No related branches found
No related tags found
No related merge requests found
Pipeline #23707 failed
...@@ -22,6 +22,8 @@ import time ...@@ -22,6 +22,8 @@ import time
from pathlib import Path from pathlib import Path
import psutil import psutil
from colorama import Fore from colorama import Fore
import random
import string
def print_usage(): def print_usage():
...@@ -155,7 +157,7 @@ class Shell: ...@@ -155,7 +157,7 @@ class Shell:
# Kill the children and raise timeout error # Kill the children and raise timeout error
for c in children: for c in children:
c.kill() c.kill()
raise psutil.TimeoutExpired('The process took more than the timeout ({}s) to terminate (last command executed: {})'.format(duration, self.last_cmd)) raise TimeoutError('The process took more than timeout ({:.2f}s) to terminate (last command executed: {})'.format(duration, self.last_cmd))
def exec_command(self, command: Cmd, wait_cmd: bool = True, timeout: int = 3): def exec_command(self, command: Cmd, wait_cmd: bool = True, timeout: int = 3):
...@@ -401,6 +403,7 @@ class Test: ...@@ -401,6 +403,7 @@ class Test:
shell.exit() shell.exit()
@test @test
def test_pipe(self): def test_pipe(self):
# Working commands # Working commands
...@@ -415,6 +418,21 @@ class Test: ...@@ -415,6 +418,21 @@ class Test:
shell.exec_commands([cmd]) shell.exec_commands([cmd])
self._test_command_results(cmd, shell, test_stdout='notest', test_stderr='include', test_return=False, test_in_shell=True) self._test_command_results(cmd, shell, test_stdout='notest', test_stderr='include', test_return=False, test_in_shell=True)
# Test a pipe with a high quantity of data
# The idea is to ensure that both processes are running concurrently
# If not, the writing end of the pipe should block since its capacity has been exceeded and no read occurs
LINUX_PIPE_SIZE = 65536
with tempfile.NamedTemporaryFile("wt") as f:
f.writelines(random.choices(string.ascii_letters, k=2*LINUX_PIPE_SIZE))
cmd = Cmd(['cat', f.name, '|', 'grep', 'word'])
shell = Shell(self.shell_exec)
try:
shell.exec_commands([cmd])
except TimeoutError as e:
raise TimeoutError(str(e) + '. This happened when trying to communicate more data than the size of the pipe. Probably the write side of the pipe blocked because the other side was not read.')
@test @test
def test_background_jobs(self): def test_background_jobs(self):
# Check possibility to have two processes running # Check possibility to have two processes running
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment