|
| 1 | +# ******************************************************************************* |
| 2 | +# Copyright (c) 2025 Contributors to the Eclipse Foundation |
| 3 | +# |
| 4 | +# See the NOTICE file(s) distributed with this work for additional |
| 5 | +# information regarding copyright ownership. |
| 6 | +# |
| 7 | +# This program and the accompanying materials are made available under the |
| 8 | +# terms of the Apache License Version 2.0 which is available at |
| 9 | +# https://www.apache.org/licenses/LICENSE-2.0 |
| 10 | +# |
| 11 | +# SPDX-License-Identifier: Apache-2.0 |
| 12 | +# ******************************************************************************* |
| 13 | + |
| 14 | +"""DataRouter robustness tests: detached-app logging and delayed DR start.""" |
| 15 | + |
| 16 | +import logging |
| 17 | +import time |
| 18 | + |
| 19 | +from logging_plugin import download_dlt |
| 20 | + |
| 21 | +LOGGER = logging.getLogger(__name__) |
| 22 | + |
| 23 | +APP_ID = "LGGG" |
| 24 | +DEFAULT_MESSAGE = "default message text for example log generating application" |
| 25 | + |
| 26 | +_DETACHED_FLUSH_WAIT_S = 5 |
| 27 | +_DR_START_DELAY_S = 2 |
| 28 | +_DR_FLUSH_WAIT_S = 5 |
| 29 | +_APP_HOLD_AFTER_LOG_MS = 8000 |
| 30 | + |
| 31 | + |
| 32 | +def test_logging_detached_logs(target, datarouter_on_target, dlt_capture): |
| 33 | + """DataRouter must recover logs from an app that exits before DR syncs.""" |
| 34 | + with dlt_capture() as receiver: |
| 35 | + target.execute( |
| 36 | + "cd /opt/test_apps/dlt_generator && ./bin/dlt_generator" |
| 37 | + " -i 10 -s 0 -f true -w 0" |
| 38 | + ) |
| 39 | + time.sleep(_DETACHED_FLUSH_WAIT_S) |
| 40 | + |
| 41 | + record = download_dlt(target, receiver.dlt_file) |
| 42 | + messages = record.find(query=dict(apid=APP_ID)) |
| 43 | + LOGGER.info("Received %d messages from detached app", len(messages)) |
| 44 | + |
| 45 | + assert len(messages) > 0, "DataRouter failed to recover detached app logs" |
| 46 | + payloads = "\n".join(str(m.payload) for m in messages) |
| 47 | + assert DEFAULT_MESSAGE in payloads, "Expected log content not found" |
| 48 | + |
| 49 | + |
| 50 | +def test_logging_after_delayed_dr_start(target, datarouter_manager, dlt_capture): |
| 51 | + """Messages buffered in shared memory must not be lost when DR starts late.""" |
| 52 | + with dlt_capture() as receiver: |
| 53 | + proc = target.execute_async( |
| 54 | + "/opt/test_apps/dlt_generator/bin/dlt_generator", |
| 55 | + args=[ |
| 56 | + "-i", |
| 57 | + "10", |
| 58 | + "-s", |
| 59 | + "0", |
| 60 | + "-f", |
| 61 | + "true", |
| 62 | + "-w", |
| 63 | + str(_APP_HOLD_AFTER_LOG_MS), |
| 64 | + ], |
| 65 | + cwd="/opt/test_apps/dlt_generator", |
| 66 | + ) |
| 67 | + time.sleep(_DR_START_DELAY_S) |
| 68 | + datarouter_manager.start() |
| 69 | + proc.wait(timeout_s=30) |
| 70 | + time.sleep(_DR_FLUSH_WAIT_S) |
| 71 | + |
| 72 | + record = download_dlt(target, receiver.dlt_file) |
| 73 | + messages = record.find(query=dict(apid=APP_ID)) |
| 74 | + LOGGER.info("Received %d messages after delayed DR start", len(messages)) |
| 75 | + |
| 76 | + assert len(messages) > 0, "Messages logged before DR started were lost" |
| 77 | + payloads = "\n".join(str(m.payload) for m in messages) |
| 78 | + assert DEFAULT_MESSAGE in payloads, "Expected log content not found" |
0 commit comments