deer-flow/backend/tests/test_file_io.py
AnoobFeng 5acd0b3ba8
fix(gateway): offload gateway upload file IO (#3935)
* fix(gateway): offload gateway upload file IO

Move Gateway upload router filesystem work off the asyncio event loop by
using a dedicated ContextVar-preserving file IO executor. Use async sandbox
acquisition for non-mounted sandbox uploads and offload remote sandbox sync
together with host file reads.

Add blocking-IO regression coverage for upload, list, delete, and remote
sandbox sync paths.

* fix(gateway): align file IO worker env var prefix

Rename the file IO executor worker-count environment variable from
DEERFLOW_FILE_IO_WORKERS to DEER_FLOW_FILE_IO_WORKERS to match the repo's
existing runtime configuration prefix convention.
2026-07-04 21:31:01 +08:00

30 lines
842 B
Python

from __future__ import annotations
import contextvars
import threading
import pytest
from deerflow.utils.file_io import run_file_io
@pytest.mark.anyio
async def test_run_file_io_propagates_contextvars_to_worker() -> None:
marker: contextvars.ContextVar[str] = contextvars.ContextVar("marker", default="missing")
marker.set("owner-1")
def read_marker() -> tuple[str, str]:
return marker.get(), threading.current_thread().name
value, thread_name = await run_file_io(read_marker)
assert value == "owner-1"
assert thread_name.startswith("file-io")
@pytest.mark.anyio
async def test_run_file_io_passes_args_and_kwargs() -> None:
def join_values(prefix: str, *, suffix: str) -> str:
return f"{prefix}:{suffix}"
assert await run_file_io(join_values, "left", suffix="right") == "left:right"