Skip to content

Parser integration test sometimes fails in the pipeline #17

@annaerdi

Description

@annaerdi

There is one integration test for the DummyParser (tests/library_integration/test_parser_integration.py), which usually passes, but sometimes randomly fails. Reason is unknown and I don't know how to reproduce. If we re-run the job it usually passes again for the second time.

Run uv run pytest
============================= test session starts ==============================
platform linux -- Python 3.12.3, pytest-9.0.2, pluggy-1.6.0
rootdir: /home/runner/work/DetectMateService/DetectMateService
configfile: pyproject.toml
plugins: cov-7.0.0
collected 116 items

tests/library_integration/test_detector_integration.py .........         [  7%]
tests/library_integration/test_one_pipe_to_rule_them_all.py ......       [ 12%]
tests/library_integration/test_parser_integration.py .........F.         [ 22%]
tests/library_integration/test_pipe_filereader_matcher_nvd.py .....      [ 26%]
tests/library_integration/test_reader_integration.py ..........          [ 35%]
tests/test_cli_logging_setup.py ..                                       [ 37%]
tests/test_component_id.py ........                                      [ 43%]
tests/test_config_reading.py .....                                       [ 4[8](https://github.com/ait-detectmate/DetectMateService/actions/runs/20271790646/job/58209355728#step:6:9)%]
tests/test_detectmatelibrary_import.py ...                               [ 50%]
tests/test_engine_loop.py .                                              [ 51%]
tests/test_engine_multi_output.py ................                       [ 65%]
tests/test_engine_socket_factory_error_handling.py ........              [ 72%]
tests/test_manager_commands.py ...                                       [ 75%]
tests/test_manager_socket_error_handling.py .......                      [ 81%]
tests/test_reconfigure_params.py ..........                              [ 8[9](https://github.com/ait-detectmate/DetectMateService/actions/runs/20271790646/job/58209355728#step:6:10)%]
tests/test_service_multi_output_integration.py ........                  [ 96%]
tests/test_smoke_service.py ....                                         [[10](https://github.com/ait-detectmate/DetectMateService/actions/runs/20271790646/job/58209355728#step:6:11)0%]

=================================== FAILURES ===================================
_________ TestParserServiceViaEngine.test_consecutive_message_parsing __________

self = <test_parser_integration.TestParserServiceViaEngine object at 0x7f0c0a3d24e0>
running_parser_service = {'engine_addr': 'ipc:///tmp/test_parser_engine_1765896149827.ipc', 'manager_addr': 'ipc:///tmp/test_parser_cmd_1765896149827.ipc', 'process': <Popen: returncode: None args: ['/home/runner/work/DetectMateService/DetectM...>}
test_log_messages = [b'1\n\x051.0.0\x10\x01\x1a&User john logged in from 192.168.1.100"\x0bauth_server*\tserver-01', b'1\n\x051.0.0\x10\x0...tabase*\x05db-01', b'1\n\x051.0.0\x10\x03\x1a-File config.txt accessed by admin at 10:45:30"\x0bfile_server*\x05fs-01']

    def test_consecutive_message_parsing(
            self, running_parser_service: dict, test_log_messages: list
    ) -> None:
        """Test consecutive messages with fresh connections."""
        engine_addr = running_parser_service["engine_addr"]
        responses_received = []
        for i, log_message in enumerate(test_log_messages):
            # Use a fresh connection for each message
            with pynng.Pair0(dial=engine_addr, recv_timeout=15000) as socket:
                print(f"DEBUG: Sending log message {i + 1}")
                socket.send(log_message)
                try:
                    response = socket.recv()
                    print(f"DEBUG: Received parser response {i + 1}")
                except pynng.Timeout as e:
                    print(f"DEBUG: Timeout on log message {i + 1}")
>                   raise e

tests/library_integration/test_parser_integration.py:274: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
tests/library_integration/test_parser_integration.py:270: in test_consecutive_message_parsing
    response = socket.recv()
               ^^^^^^^^^^^^^
.venv/lib/python3.12/site-packages/pynng/nng.py:471: in recv
    check_err(ret)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

err = 5

    def check_err(err):
        """
        Raises an exception if the return value of an nng_function is nonzero.
    
        The enum nng_errno_enum is defined in nng.h
    
        """
        # fast path for success
        if not err:
            return
    
        msg = nng.nng_strerror(err)
        string = ffi.string(msg)
        string = string.decode()
        exc = EXCEPTION_MAP.get(err, NNGException)
>       raise exc(string, err)
E       pynng.exceptions.Timeout: Timed out

.venv/lib/python3.12/site-packages/pynng/exceptions.py:202: Timeout
----------------------------- Captured stdout call -----------------------------
DEBUG: Sending log message 1
DEBUG: Received parser response 1
DEBUG: Sending log message 2
DEBUG: Timeout on log message 2
=========================== short test summary info ============================
FAILED tests/library_integration/test_parser_integration.py::TestParserServiceViaEngine::test_consecutive_message_parsing - pynng.exceptions.Timeout: Timed out
================== 1 failed, [11](https://github.com/ait-detectmate/DetectMateService/actions/runs/20271790646/job/58209355728#step:6:12)5 passed in 103.22s (0:01:43) ===================
Error: Process completed with exit code 1.

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions