|
| 1 | +# Copyright (c) Microsoft Corporation. |
| 2 | +# Licensed under the MIT License. |
| 3 | + |
| 4 | +from pathlib import Path |
| 5 | + |
| 6 | +import pytest |
| 7 | + |
| 8 | +from ._harness import FunctionApp |
| 9 | + |
| 10 | + |
| 11 | +@pytest.mark.parametrize("message", [ |
| 12 | + "Starting new 'activity_chain' instance with ID = 'test-instance'.", |
| 13 | + "test-instance: Orchestration activity_chain completed with status: COMPLETED", |
| 14 | +]) |
| 15 | +@pytest.mark.parametrize(("before", "after"), [ |
| 16 | + ("", ""), |
| 17 | + ("", "[2026-11-02T19:42:58.870Z] Request GET http://127.0.0.1:10002/"), |
| 18 | + ("[2026-11-02T19:42:58.869Z] Previous record", ""), |
| 19 | + ("[2026-11-02T19:42:58.869Z] Previous record", |
| 20 | + "[2026-11-02T19:42:58.871Z] Next record"), |
| 21 | + ("[2026-11-02T19:42:58Z] Previous record", |
| 22 | + "[2026-11-02T19:42:58.8701234Z] Next record"), |
| 23 | + ("[2026-11-02T19:42:58.869Z] Previous record\n", |
| 24 | + "\n[2026-11-02T19:42:58.871Z] Next record"), |
| 25 | + ("[2026-11-02T19:42:58.869Z] Previous record\r\n", |
| 26 | + "\r\n[2026-11-02T19:42:58.871Z] Next record"), |
| 27 | +]) |
| 28 | +def test_wait_for_host_log_extracts_timestamped_record( |
| 29 | + tmp_path: Path, monkeypatch: pytest.MonkeyPatch, |
| 30 | + message: str, before: str, after: str) -> None: |
| 31 | + app = FunctionApp("dtask_style") |
| 32 | + log_path = tmp_path / "host.log" |
| 33 | + monkeypatch.setattr(app, "_log_path", log_path) |
| 34 | + expected = f"[2026-11-02T19:42:58.870Z] {message}" |
| 35 | + log_path.write_text(before + expected + after, encoding="utf-8") |
| 36 | + |
| 37 | + record = app.wait_for_host_log(message, timeout=0) |
| 38 | + |
| 39 | + assert record == expected |
| 40 | + |
| 41 | + |
| 42 | +@pytest.mark.parametrize("output", [ |
| 43 | + "SDK message", |
| 44 | + "[2026-11-02T19:42:58.870Z]\nSDK message", |
| 45 | + "[2026-11-02T19:42:58.870Z] Unrelated record SDK message", |
| 46 | + "[2026-11-02T19:42:58.870Z] SDK message unexpected suffix", |
| 47 | +]) |
| 48 | +def test_wait_for_host_log_preserves_nonmatching_records( |
| 49 | + tmp_path: Path, monkeypatch: pytest.MonkeyPatch, output: str) -> None: |
| 50 | + app = FunctionApp("dtask_style") |
| 51 | + log_path = tmp_path / "host.log" |
| 52 | + monkeypatch.setattr(app, "_log_path", log_path) |
| 53 | + log_path.write_text(output, encoding="utf-8") |
| 54 | + |
| 55 | + record = app.wait_for_host_log("SDK message", timeout=0) |
| 56 | + |
| 57 | + assert record == output.splitlines()[-1] |
0 commit comments