aboutsummaryrefslogtreecommitdiff
path: root/src/test/test.py
diff options
context:
space:
mode:
authorCharles Cabergs <me@cacharle.xyz>2020-09-28 17:00:49 +0200
committerCharles Cabergs <me@cacharle.xyz>2020-09-28 17:00:49 +0200
commit56125041e0720754651ae561f68eb186b71b331a (patch)
tree783adf5519c944dd51f70b83604c0b8242e4667f /src/test/test.py
parentb38ad263568cfc89147e5c7c9d355b0607ae1e18 (diff)
downloadphilosophers_test-56125041e0720754651ae561f68eb186b71b331a.tar.gz
philosophers_test-56125041e0720754651ae561f68eb186b71b331a.tar.bz2
philosophers_test-56125041e0720754651ae561f68eb186b71b331a.zip
Added infinite test
Diffstat (limited to 'src/test/test.py')
-rw-r--r--src/test/test.py25
1 files changed, 16 insertions, 9 deletions
diff --git a/src/test/test.py b/src/test/test.py
index e8c5ab4..91fbbca 100644
--- a/src/test/test.py
+++ b/src/test/test.py
@@ -6,7 +6,7 @@
# By: charles <me@cacharle.xyz> +#+ +:+ +#+ #
# +#+#+#+#+#+ +#+ #
# Created: 2020/09/27 11:36:32 by charles #+# #+# #
-# Updated: 2020/09/28 14:53:40 by cacharle ### ########.fr #
+# Updated: 2020/09/28 16:08:51 by cacharle ### ########.fr #
# #
# ############################################################################ #
@@ -37,13 +37,13 @@ class Test:
def __init__(
self,
- philo_num: int = None,
- timeout_die: int = None,
- timeout_eat: int = None,
- timeout_sleep: int = None,
- meal_num: int = None,
- should_fail: bool = False,
- error_cmd: [str] = None
+ philo_num: int = None,
+ timeout_die: int = None,
+ timeout_eat: int = None,
+ timeout_sleep: int = None,
+ meal_num: int = None,
+ error_cmd: [str] = None,
+ infinite: bool = False
):
self._philo_num = philo_num
self._timeout_die = timeout_die
@@ -51,6 +51,7 @@ class Test:
self._timeout_sleep = timeout_sleep
self._meal_num = meal_num
self._error_cmd = error_cmd
+ self._infinite = infinite
Test._tests.append(self)
def run(self):
@@ -74,16 +75,22 @@ class Test:
)
if self._error_cmd is not None:
self._check_error(process)
+ elif self._infinite:
+ self._check_output(process.stdout, died=False)
+ time.sleep(config.INFINITE_WAIT_TIME)
+ process.kill()
else:
self._check_output(process.stdout)
process.wait(timeout=config.TIMEOUT)
- def _check_output(self, stream):
+ def _check_output(self, stream, died: bool = True):
table = philo.Table(self._philo_num, self._timeout_eat)
for line in stream:
line = line.decode()[:-1]
table.add_log(philo.Log(line, self._philo_num))
table.check()
+ if died and not table.dead:
+ raise philo.LogError("one philosopher should have died")
def _check_error(self, process):
try: