From 4dd3c7a22ec572e4f44a34119afa8eadacfab1ce Mon Sep 17 00:00:00 2001 From: Frost Ming Date: Wed, 14 Aug 2024 14:58:49 +0800 Subject: [PATCH] fix: try to fix the timeout test cases (#4917) * fix: try to fix the timeout test cases Signed-off-by: Frost Ming * fix: exclude tests on 3.12 Signed-off-by: Frost Ming --------- Signed-off-by: Frost Ming --- .github/workflows/ci.yml | 7 ++ .../e2e/bento_server_http/tests/test_serve.py | 83 +++++++------------ 2 files changed, 39 insertions(+), 51 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 8fe5c4731e1..a4a4e282db7 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -144,6 +144,13 @@ jobs: os: [ubuntu-latest, macos-latest] python-version: [3.8, 3.11, 3.12] suite: ['bento_server_http', 'bento_new_sdk'] + exclude: + - os: macos-latest + suite: bento_server_http + python-version: 3.12 + - os: ubuntu-latest + suite: bento_server_http + python-version: 3.12 name: ${{ matrix.suite }}-e2e-tests (python${{ matrix.python-version }}.${{ matrix.os }}) runs-on: ${{ matrix.os }} timeout-minutes: 90 diff --git a/tests/e2e/bento_server_http/tests/test_serve.py b/tests/e2e/bento_server_http/tests/test_serve.py index 9466bf7eea5..fccc1c9a59f 100644 --- a/tests/e2e/bento_server_http/tests/test_serve.py +++ b/tests/e2e/bento_server_http/tests/test_serve.py @@ -1,7 +1,7 @@ import asyncio import os +import subprocess import sys -import time from pathlib import Path import pytest @@ -29,24 +29,17 @@ def test_http_server(): server.stop() assert server.process is not None # process should not be removed + try: + retcode = server.process.wait(10) + assert retcode is not None - timeout = 10 - start_time = time.time() - while time.time() - start_time < timeout: - retcode = server.process.poll() - if retcode is not None and retcode <= 0: - break - - retcode = server.process.poll() - assert retcode is not None - - if sys.platform == "win32": - # on Windows, because of the way that terminate is run, it seems the exit code is set. - pass - else: - # negative return codes mean the process was terminated; since we will be terminating - # the process, it should be negative. - assert retcode <= 0 + if sys.platform != "win32": + # on Windows, because of the way that terminate is run, it seems the exit code is set. + # negative return codes mean the process was terminated; since we will be terminating + # the process, it should be negative. + assert retcode <= 0 + except subprocess.TimeoutExpired: + server.process.kill() @pytest.mark.usefixtures("bentoml_home") @@ -63,23 +56,17 @@ def test_http_server_ctx(): assert server.process is not None # process should not be removed - timeout = 10 - start_time = time.time() - while time.time() - start_time < timeout: - retcode = server.process.poll() - if retcode is not None and retcode <= 0: - break - - retcode = server.process.poll() - assert retcode is not None + try: + retcode = server.process.wait(10) + assert retcode is not None - if sys.platform == "win32": - # on Windows, because of the way that terminate is run, it seems the exit code is set. - pass - else: - # negative return codes mean the process was terminated; since we will be terminating - # the process, it should be negative. - assert retcode <= 0 + if sys.platform != "win32": + # on Windows, because of the way that terminate is run, it seems the exit code is set. + # negative return codes mean the process was terminated; since we will be terminating + # the process, it should be negative. + assert retcode <= 0 + except subprocess.TimeoutExpired: + server.process.kill() def test_serve_from_svc(): @@ -94,23 +81,17 @@ def test_serve_from_svc(): assert server.process is not None # process should not be removed - timeout = 10 - start_time = time.time() - while time.time() - start_time < timeout: - retcode = server.process.poll() - if retcode is not None and retcode <= 0: - break - - retcode = server.process.poll() - assert retcode is not None - - if sys.platform == "win32": - # on Windows, because of the way that terminate is run, it seems the exit code is set. - pass - else: - # negative return codes mean the process was terminated; since we will be terminating - # the process, it should be negative. - assert retcode <= 0 + try: + retcode = server.process.wait(10) + assert retcode is not None + + if sys.platform != "win32": + # on Windows, because of the way that terminate is run, it seems the exit code is set. + # negative return codes mean the process was terminated; since we will be terminating + # the process, it should be negative. + assert retcode <= 0 + except subprocess.TimeoutExpired: + server.process.kill() @pytest.mark.usefixtures("bentoml_home")