Skip to content

Websocket support in chains (entrypoint only). #4011

Websocket support in chains (entrypoint only).

Websocket support in chains (entrypoint only). #4011

GitHub Actions / JUnit Test Report failed Feb 22, 2025 in 0s

32 tests run, 31 passed, 0 skipped, 1 failed.

Annotations

Check failure on line 60 in truss/tests/test_model_inference.py

See this annotation in the file changed.

@github-actions github-actions / JUnit Test Report

test_model_inference.test_truss_with_requests_and_invalid_argument_combinations

AssertionError: Did not find expected error in logs.
  Expected error: Truss model must have a `predict` method.
  Expected message: Exception while loading model
  Actual logs:
  [{'asctime': '2025-02-22 01:05:26,873', 'levelname': 'INFO', 'message': 'Using no-op tracing (tracing was disabled).'}, {'asctime': '2025-02-22 01:05:26,908', 'levelname': 'INFO', 'message': 'Started server process [1]', 'color_message': 'Started server process [\x1b[36m%d\x1b[0m]'}, {'asctime': '2025-02-22 01:05:26,909', 'levelname': 'INFO', 'message': 'Waiting for application startup.'}, {'asctime': '2025-02-22 01:05:26,909', 'levelname': 'INFO', 'message': 'Executing model.load()...'}, {'asctime': '2025-02-22 01:05:26,909', 'levelname': 'INFO', 'message': 'Application startup complete.'}, {'asctime': '2025-02-22 01:05:26,910', 'levelname': 'INFO', 'message': 'Uvicorn running on http://0.0.0.0:8080 (Press CTRL+C to quit)', 'color_message': 'Uvicorn running on \x1b[1m%s://%s:%d\x1b[0m (Press CTRL+C to quit)'}, {'asctime': '2025-02-22 01:05:26,910', 'levelname': 'INFO', 'message': 'Loading truss model from file.'}, {'asctime': '2025-02-22 01:05:26,914', 'levelname': 'ERROR', 'message': 'Exception while loading model', 'exc_info': 'Traceback (most recent call last):\n  File "/app/model_wrapper.py", line 433, in load\n    self._load_impl()\n  File "/app/model_wrapper.py", line 519, in _load_impl\n    self._maybe_model_descriptor = ModelDescriptor.from_model(self._model)\n  File "/app/model_wrapper.py", line 326, in from_model\n    raise errors.ModelDefinitionError(\ncommon.errors.ModelDefinitionError: Truss model must have a `predict` or `websocket` method.'}]
assert False
 +  where False = any(<generator object _assert_logs_contain_error.<locals>.<genexpr> at 0x7f60b552bf90>)
Raw output
@pytest.mark.integration
    def test_truss_with_requests_and_invalid_argument_combinations():
        model = """
        import fastapi
        class Model:
            async def preprocess(self, inputs): ...
    
            def predict(self, request: fastapi.Request): ...
        """
        with ensure_kill_all(), _temp_truss(model) as tr:
            container = tr.docker_run(
                local_port=8090, detach=True, wait_for_server_ready=False
            )
            time.sleep(1.0)  # Wait for logs.
            _assert_logs_contain_error(
                container.logs(),
                "When using `preprocess`, the predict method cannot only have the request argument",
                "Exception while loading model",
            )
    
        model = """
        import fastapi
        class Model:
            def preprocess(self, inputs): ...
    
            async def predict(self, inputs, request: fastapi.Request): ...
    
            def postprocess(self, request: fastapi.Request): ...
        """
        with ensure_kill_all(), _temp_truss(model) as tr:
            container = tr.docker_run(
                local_port=8090, detach=True, wait_for_server_ready=False
            )
            time.sleep(1.0)  # Wait for logs.
            _assert_logs_contain_error(
                container.logs(),
                "The `postprocess` method cannot only have the request argument",
                "Exception while loading model",
            )
    
        model = """
        import fastapi
        class Model:
            def preprocess(self, inputs): ...
        """
        with ensure_kill_all(), _temp_truss(model) as tr:
            container = tr.docker_run(
                local_port=8090, detach=True, wait_for_server_ready=False
            )
            time.sleep(1.0)  # Wait for logs.
>           _assert_logs_contain_error(
                container.logs(),
                "Truss model must have a `predict` method.",
                "Exception while loading model",
            )

truss/tests/test_model_inference.py:1540: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

logs = '{"asctime": "2025-02-22 01:05:26,873", "levelname": "INFO", "message": "Using no-op tracing (tracing was disabled)."}...delDefinitionError(\\ncommon.errors.ModelDefinitionError: Truss model must have a `predict` or `websocket` method."}\n'
error = 'Truss model must have a `predict` method.'
message = 'Exception while loading model'

    def _assert_logs_contain_error(logs: str, error: str, message=DEFAULT_LOG_ERROR):
        loglines = [json.loads(line) for line in logs.splitlines()]
>       assert any(
            _log_contains_line(line, message, "ERROR", error) for line in loglines
        ), (
            f"Did not find expected error in logs.\nExpected error: {error}\n"
            f"Expected message: {message}\nActual logs:\n{loglines}"
        )
E       AssertionError: Did not find expected error in logs.
E         Expected error: Truss model must have a `predict` method.
E         Expected message: Exception while loading model
E         Actual logs:
E         [{'asctime': '2025-02-22 01:05:26,873', 'levelname': 'INFO', 'message': 'Using no-op tracing (tracing was disabled).'}, {'asctime': '2025-02-22 01:05:26,908', 'levelname': 'INFO', 'message': 'Started server process [1]', 'color_message': 'Started server process [\x1b[36m%d\x1b[0m]'}, {'asctime': '2025-02-22 01:05:26,909', 'levelname': 'INFO', 'message': 'Waiting for application startup.'}, {'asctime': '2025-02-22 01:05:26,909', 'levelname': 'INFO', 'message': 'Executing model.load()...'}, {'asctime': '2025-02-22 01:05:26,909', 'levelname': 'INFO', 'message': 'Application startup complete.'}, {'asctime': '2025-02-22 01:05:26,910', 'levelname': 'INFO', 'message': 'Uvicorn running on http://0.0.0.0:8080 (Press CTRL+C to quit)', 'color_message': 'Uvicorn running on \x1b[1m%s://%s:%d\x1b[0m (Press CTRL+C to quit)'}, {'asctime': '2025-02-22 01:05:26,910', 'levelname': 'INFO', 'message': 'Loading truss model from file.'}, {'asctime': '2025-02-22 01:05:26,914', 'levelname': 'ERROR', 'message': 'Exception while loading model', 'exc_info': 'Traceback (most recent call last):\n  File "/app/model_wrapper.py", line 433, in load\n    self._load_impl()\n  File "/app/model_wrapper.py", line 519, in _load_impl\n    self._maybe_model_descriptor = ModelDescriptor.from_model(self._model)\n  File "/app/model_wrapper.py", line 326, in from_model\n    raise errors.ModelDefinitionError(\ncommon.errors.ModelDefinitionError: Truss model must have a `predict` or `websocket` method.'}]
E       assert False
E        +  where False = any(<generator object _assert_logs_contain_error.<locals>.<genexpr> at 0x7f60b552bf90>)

truss/tests/test_model_inference.py:60: AssertionError