From 1823a58d64bad9977237074e38edfde0f91adf36 Mon Sep 17 00:00:00 2001 From: Egor Tensin Date: Sun, 9 Jul 2023 23:39:01 +0200 Subject: test: test long CI run output It immediately exposed a horrible bug in net.c, which is now fixed. --- src/net.c | 2 +- test/py/conftest.py | 6 +++--- test/py/lib/test_repo.py | 30 ++++++++++++++++++++++++++++++ 3 files changed, 34 insertions(+), 4 deletions(-) diff --git a/src/net.c b/src/net.c index 1484cfb..7278218 100644 --- a/src/net.c +++ b/src/net.c @@ -188,7 +188,7 @@ int net_recv(int fd, void *buf, size_t size) ssize_t read_total = 0; while ((size_t)read_total < size) { - ssize_t read_now = read(fd, buf, size); + ssize_t read_now = read(fd, (unsigned char *)buf + read_total, size - read_total); if (!read_now) break; diff --git a/test/py/conftest.py b/test/py/conftest.py index 6102898..3a9c589 100644 --- a/test/py/conftest.py +++ b/test/py/conftest.py @@ -11,7 +11,7 @@ from pytest import fixture from lib.db import Database from lib.net import random_unused_port from lib.process import CmdLine -from lib.test_repo import TestRepoOutputSimple, TestRepoOutputEmpty +from lib.test_repo import TestRepoOutputSimple, TestRepoOutputEmpty, TestRepoOutputLong class Param: @@ -188,8 +188,8 @@ def client(client_cmd): return client_cmd -@fixture(params=[TestRepoOutputSimple, TestRepoOutputEmpty], - ids=['output_simple', 'output_empty']) +@fixture(params=[TestRepoOutputSimple, TestRepoOutputEmpty, TestRepoOutputLong], + ids=['output_simple', 'output_empty', 'output_long']) def test_repo(tmp_path, request): return request.param(os.path.join(tmp_path, 'repo')) diff --git a/test/py/lib/test_repo.py b/test/py/lib/test_repo.py index 94b6f93..3234de5 100644 --- a/test/py/lib/test_repo.py +++ b/test/py/lib/test_repo.py @@ -4,8 +4,10 @@ # Distributed under the MIT License. import abc +import base64 import logging import os +import random import shlex import shutil @@ -137,3 +139,31 @@ class TestRepoOutputEmpty(TestRepoOutput): def run_output_matches(self, output): return len(output) == 0 + + +# Making it a bash script introduces way too much overhead with all the +# argument expansions; it slows things down considerably. +OUTPUT_SCRIPT_LONG = R'''#!/usr/bin/env python3 + +output = {output} + +import sys +sys.stdout.write(output) +''' + + +class TestRepoOutputLong(TestRepoOutput): + __test__ = False + + OUTPUT_LEN_KB = 300 + + def __init__(self, *args, **kwargs): + nb = TestRepoOutputLong.OUTPUT_LEN_KB * 1024 + self.output = base64.encodebytes(random.randbytes(nb)).decode() + super().__init__(*args, **kwargs) + + def _format_output_script(self): + return OUTPUT_SCRIPT_LONG.format(output=repr(self.output)) + + def run_output_matches(self, output): + return output.decode() == self.output -- cgit v1.2.3