mirror of
https://github.com/comfyanonymous/ComfyUI.git
synced 2026-10-24 02:49:04 +03:00
* review-stack 1/4: code (37 files, +3217/-3958) Review-and-land stack for synap5e/feat/asset-record-content-split, generated by review-stack.py. Once approved, merges DOWN into the layer below (a fast-forward); only the bottom layer squash-merges into the real base. See ~/adocs/review-stack.md. Rule: path not under tests-unit/ or tests/ Question: Is the logic change right? Source tip:7007d18582Merge-base:783545f689* review-stack 2/4: tests-removed (24 files, +274/-8220) Review-and-land stack for synap5e/feat/asset-record-content-split, generated by review-stack.py. Once approved, merges DOWN into the layer below (a fast-forward); only the bottom layer squash-merges into the real base. See ~/adocs/review-stack.md. Rule: test file deleted, or modified with deleted/(added+deleted) >= 0.9 Question: For each dropped assertion: obsolete by a ruling, or covered by a tests-new test? Source tip:7007d18582Merge-base:783545f689* review-stack 3/4: tests-changed (13 files, +1043/-1218) Review-and-land stack for synap5e/feat/asset-record-content-split, generated by review-stack.py. Once approved, merges DOWN into the layer below (a fast-forward); only the bottom layer squash-merges into the real base. See ~/adocs/review-stack.md. Rule: remaining modified test files (incl. conftest.py / helpers) Question: Did the edits weaken an existing check? Source tip:7007d18582Merge-base:783545f689* review-stack 4/4: tests-new (46 files, +8601/-0) Review-and-land stack for synap5e/feat/asset-record-content-split, generated by review-stack.py. Once approved, merges DOWN into the layer below (a fast-forward); only the bottom layer squash-merges into the real base. See ~/adocs/review-stack.md. Rule: test file added Question: Is the code layer well covered? Source tip:7007d18582Merge-base:783545f689* review-stack 5/6: code (13 files, +351/-104) Review-and-land stack for synap5e/feat/assets-di, generated by review-stack.py. Once approved, merges DOWN into the layer below (a fast-forward); only the bottom layer squash-merges into the real base. See ~/adocs/review-stack.md. Rule: path not under tests-unit/ or tests/ Question: Is the logic change right? Source tip:eca2c74bffMerge-base:20d59d2a5f* review-stack 6/6: tests (8 files, +753/-238) Review-and-land stack for synap5e/feat/assets-di, generated by review-stack.py. Once approved, merges DOWN into the layer below (a fast-forward); only the bottom layer squash-merges into the real base. See ~/adocs/review-stack.md. Rule: every changed file under tests-unit/ or tests/ (added, modified, or deleted) Question: Is the code layer well covered, and did any edit weaken an existing check? Source tip:eca2c74bffMerge-base:20d59d2a5f* review-stack 7/8: ported-fixes (42 files, +1361/-180) Review-and-land stack for synap5e/feat/assets-di-v2, generated by review-stack.py conventions (hand-built continuation layer; see the PR body). Once approved, merges DOWN into the layer below (a fast-forward); only the bottom layer squash-merges into the real base. See ~/adocs/review-stack.md. Rule: the 11 base-branch fix/docs commits 595cd6e4..94d7185b cherry-picked across the DI refactor (7efdd1d7excluded, superseded by layer 8) Question: was each base fix ported faithfully across the DI refactor? Source tip: 6841881069284803b902b4a9e33bdcda13126771 Merge-base:7fdfb40f4b* review-stack 8/8: defensive-parity (4 files, +36/-3) Review-and-land stack for synap5e/feat/assets-di-v2, generated by review-stack.py conventions (hand-built continuation layer; see the PR body). Once approved, merges DOWN into the layer below (a fast-forward); only the bottom layer squash-merges into the real base. See ~/adocs/review-stack.md. Rule: match-or-improve master's dependency defenses — NoAssets selection when DB deps unavailable (7efdd1d7's outcome via the DI seam), requirements warning before assets imports, blake3 in the guarded dependency set Question: does each degradation path now match or improve master's behavior? Source tip:ebc2cfeebcMerge-base:7fdfb40f4b* fix(assets): only discard content rows this operation actually inserted CR-9: Enumerated all six create_content call sites. Only scanner seeding and the three ingest registration paths track IDs for failure cleanup. * fix(assets): reject hash-only uploads with FEATURE_DISABLED when hashing is off CodeRabbit finding CR-2: reject hash-only multipart uploads before create_from_hash when hashing is disabled. * fix(assets): seed persists the stat it verified CR-7: persist the fresh seed-time restat instead of walk-time spec values. * fix(assets): route database lock failures to the lock guidance CR-16: route file-lock startup failures through the existing lock guidance and exit path. * fix(assets): drop the inaccurate temp-cleanup claim from the shutdown warning References CR-10. * fix(assets): walk the output root after execution so undeclared outputs register promptly Custom nodes that write files into the output directory without declaring them in output_ui only became assets when the next full walk happened - a frontend GET /object_info or a restart. Headless and API-only sessions never trigger either, so those files never converged into the asset database. The post-execution hook now requests a FULL scan of the output root instead of an enrich-only pass. The seeder's pending-request queue was generalised from enrich-specific to carrying a scan phase, so the request starts immediately when the seeder is idle and coalesces (escalating to FULL on a phase mismatch) when a scan is already running. queue_output_enrichment is renamed to queue_output_scan across the protocol, the NoAssets no-op and the call site. References FIX-6. * chore(assets): remove seeder paths orphaned by the output-scan change 45c2f96e rerouted both former enrich call sites to start()/enqueue_scan(), leaving two seeder methods that look live but are not. Review round F2 raised this along with four smaller items; the user's disposition was to fix all six here. - Delete start_enrich: zero callers repo-wide after 45c2f96e. - Delete enqueue_enrich: no production callers; its ~18 call sites in tests/test_asset_seeder.py move to enqueue_scan(phase=ScanPhase.ENRICH) with their semantics unchanged. The deletion forces the half-done class renames (TestEnqueueEnrich* -> TestEnqueueScan*, consistent with the already-renamed TestPendingScanDrain) and restores the module docstring that was dropped rather than reworded. - Document at manager.queue_output_scan that ScanPhase.FULL per debounce window is the deliberate, user-ratified trade, so it is not optimised back to ENRICH without revisiting the decision. - Document that SeedAssetSpec.size_bytes/mtime_ns are walk-time diagnostics only - production persists the seed-time restat since CR-7. - Export create_content_reporting_insert from the queries facade and fold scanner.py's direct-module import into the existing facade block. - Harden test_queue_output_scan_does_not_duplicate_declared_output against a vacuous pass: it now asserts the seeder finished without errors and that an undeclared sibling written into the same directory WAS registered by the same scan, proving the walk actually ran. No production behaviour changes beyond the two deletions. References F2-cleanup. * chore: comment cleanup Comment-Gate: 18 quarantined * fix(assets): preserve pause across the seeder's pending-scan drain pause() runs before every prompt, while pending-scan enqueue and resume only run inside the debounced gc-interval gate. If the active scan finishes just after the next prompt's pause, its finally block resets the seeder to idle and the pending drain starts a replacement with the run gate open, so resume becomes a no-op. Capture pausedness under the lock before resetting to idle, then start the drained scan already paused. Setting the state and gate before launching the thread avoids the start-then-reclear window and lets resume release the existing scan checkpoints. Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-openagent) Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai> * test(assets): pin job_id absence for scan-discovered assets Owner ruling, recorded 2026-09-03 in the stack-9-hardening planning notepad: scan-discovered assets — including undeclared outputs found by the post-execution walk — carry job_id = None, always; only emission-time registration (output_ui declaration) attributes a job; attributing walk finds to the most recent prompt would be a temporal-correlation guess that is wrong exactly when prompts interleave; None is honest provenance. Do NOT add proximity-based attribution heuristics to the scanner. Ratified against Jacob Segal's cross-job-attribution concern (2026-09-08 review meeting) — a wrongly-attributed asset could mean one user's cloud job sees another user's asset. Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-openagent) Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai> * [review-stack 10/10] assets-tests (#16218) * test(execution): run the battery with assets enabled and assert asset-system health at teardown * test(execution): cover list-shaped outputs registering assets Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-openagent) Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai> --------- Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai> * [review-stack 11/11] review-fixes (#16261) * fix(assets): only exit on database file-lock timeout when assets are enabled * test(assets): pin live_contents_under_prefixes path-filtering semantics * perf(assets): push live-content prefix filtering into SQL * test(assets): declare per-entry intent in the path-prefix corpus * test(assets): normalize POSIX-literal path expectations for Windows * test(assets): force observable stat changes and close-before-mutate on Windows-sensitive rewrites * test(assets): force an observable mtime change in the hash-mode split test --------- Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai> Co-authored-by: guill <jacob.e.segal@gmail.com>
405 lines
15 KiB
Python
405 lines
15 KiB
Python
|
||
import threading
|
||
from typing import Any
|
||
from unittest.mock import call, patch
|
||
|
||
import pytest
|
||
|
||
from app.assets.seeder import Progress, ScanPhase, _AssetSeeder, State
|
||
|
||
|
||
@pytest.fixture()
|
||
def seeder():
|
||
"""Fresh seeder instance for each test."""
|
||
return _AssetSeeder()
|
||
|
||
|
||
class TestEventSink:
|
||
def test_delivers_event_and_payload_to_sink(self, seeder):
|
||
received: list[tuple[str, dict[str, Any]]] = []
|
||
|
||
def record_event(event_type: str, data: dict[str, Any]) -> None:
|
||
received.append((event_type, data))
|
||
|
||
event_type = "assets.seed.started"
|
||
payload = {"roots": ["models"], "total": 1, "phase": "fast"}
|
||
seeder.set_event_sink(record_event)
|
||
|
||
seeder._emit_event(event_type, payload)
|
||
|
||
assert received == [(event_type, payload)]
|
||
|
||
def test_noop_when_no_sink_is_set(self, seeder):
|
||
assert seeder._emit_event("assets.seed.resumed", {}) is None
|
||
|
||
def test_swallows_raising_sink_exception(self, seeder):
|
||
def raise_from_sink(event_type: str, data: dict[str, Any]) -> None:
|
||
raise RuntimeError("boom")
|
||
|
||
seeder.set_event_sink(raise_from_sink)
|
||
|
||
assert seeder._emit_event("assets.seed.error", {"message": "failure"}) is None
|
||
|
||
|
||
# ---------------------------------------------------------------------------
|
||
# _reset_to_idle
|
||
# ---------------------------------------------------------------------------
|
||
|
||
|
||
class TestResetToIdle:
|
||
def test_sets_idle_and_clears_progress(self, seeder):
|
||
"""_reset_to_idle should move state to IDLE and snapshot progress."""
|
||
progress = Progress(scanned=10, total=20, created=5, skipped=3)
|
||
seeder._state = State.RUNNING
|
||
seeder._progress = progress
|
||
|
||
with seeder._lock:
|
||
seeder._reset_to_idle()
|
||
|
||
assert seeder._state is State.IDLE
|
||
assert seeder._progress is None
|
||
assert seeder._last_progress is progress
|
||
|
||
def test_noop_when_progress_already_none(self, seeder):
|
||
"""_reset_to_idle should handle None progress gracefully."""
|
||
seeder._state = State.CANCELLING
|
||
seeder._progress = None
|
||
|
||
with seeder._lock:
|
||
seeder._reset_to_idle()
|
||
|
||
assert seeder._state is State.IDLE
|
||
assert seeder._progress is None
|
||
assert seeder._last_progress is None
|
||
|
||
|
||
# ---------------------------------------------------------------------------
|
||
# enqueue_scan – immediate start when idle
|
||
# ---------------------------------------------------------------------------
|
||
|
||
|
||
class TestEnqueueScanStartsImmediately:
|
||
def test_starts_when_idle(self, seeder):
|
||
with patch.object(seeder, "start", return_value=True) as mock:
|
||
assert (
|
||
seeder.enqueue_scan(
|
||
roots=("output",), phase=ScanPhase.ENRICH, compute_hashes=True
|
||
)
|
||
is True
|
||
)
|
||
mock.assert_called_once_with(
|
||
roots=("output",),
|
||
phase=ScanPhase.ENRICH,
|
||
prune_first=False,
|
||
compute_hashes=True,
|
||
)
|
||
|
||
def test_no_pending_when_started_immediately(self, seeder):
|
||
with patch.object(seeder, "start", return_value=True):
|
||
seeder.enqueue_scan(roots=("output",), phase=ScanPhase.ENRICH)
|
||
assert seeder._pending_scan is None
|
||
|
||
|
||
# ---------------------------------------------------------------------------
|
||
# enqueue_scan – queuing when busy
|
||
# ---------------------------------------------------------------------------
|
||
|
||
|
||
class TestEnqueueScanQueuesWhenBusy:
|
||
def test_queues_when_busy(self, seeder):
|
||
with patch.object(seeder, "start", return_value=False):
|
||
result = seeder.enqueue_scan(
|
||
roots=("models",), phase=ScanPhase.ENRICH, compute_hashes=False
|
||
)
|
||
|
||
assert result is False
|
||
assert seeder._pending_scan == {
|
||
"roots": ("models",),
|
||
"phase": ScanPhase.ENRICH,
|
||
"compute_hashes": False,
|
||
}
|
||
|
||
def test_queues_preserves_compute_hashes_true(self, seeder):
|
||
with patch.object(seeder, "start", return_value=False):
|
||
seeder.enqueue_scan(
|
||
roots=("input",), phase=ScanPhase.ENRICH, compute_hashes=True
|
||
)
|
||
|
||
assert seeder._pending_scan["compute_hashes"] is True
|
||
|
||
|
||
# ---------------------------------------------------------------------------
|
||
# enqueue_scan – merging when a pending request already exists
|
||
# ---------------------------------------------------------------------------
|
||
|
||
|
||
class TestEnqueueScanMergesPending:
|
||
def _make_busy(self, seeder):
|
||
return patch.object(seeder, "start", return_value=False)
|
||
|
||
def test_merges_roots(self, seeder):
|
||
"""A second enqueue should merge roots with the existing pending request."""
|
||
with self._make_busy(seeder):
|
||
seeder.enqueue_scan(roots=("models",), phase=ScanPhase.ENRICH)
|
||
seeder.enqueue_scan(roots=("output",), phase=ScanPhase.FAST)
|
||
|
||
merged = set(seeder._pending_scan["roots"])
|
||
assert merged == {"models", "output"}
|
||
assert seeder._pending_scan["phase"] is ScanPhase.FULL
|
||
|
||
def test_merges_overlapping_roots(self, seeder):
|
||
"""Duplicate roots should be deduplicated."""
|
||
with self._make_busy(seeder):
|
||
seeder.enqueue_scan(roots=("models", "input"), phase=ScanPhase.ENRICH)
|
||
seeder.enqueue_scan(roots=("input", "output"), phase=ScanPhase.ENRICH)
|
||
|
||
merged = set(seeder._pending_scan["roots"])
|
||
assert merged == {"models", "input", "output"}
|
||
|
||
def test_compute_hashes_sticky_true(self, seeder):
|
||
"""Once compute_hashes is True it should stay True after merging."""
|
||
with self._make_busy(seeder):
|
||
seeder.enqueue_scan(
|
||
roots=("models",), phase=ScanPhase.ENRICH, compute_hashes=True
|
||
)
|
||
seeder.enqueue_scan(
|
||
roots=("output",), phase=ScanPhase.ENRICH, compute_hashes=False
|
||
)
|
||
|
||
assert seeder._pending_scan["compute_hashes"] is True
|
||
|
||
def test_compute_hashes_upgrades_to_true(self, seeder):
|
||
"""A later enqueue with compute_hashes=True should upgrade the pending request."""
|
||
with self._make_busy(seeder):
|
||
seeder.enqueue_scan(
|
||
roots=("models",), phase=ScanPhase.ENRICH, compute_hashes=False
|
||
)
|
||
seeder.enqueue_scan(
|
||
roots=("output",), phase=ScanPhase.ENRICH, compute_hashes=True
|
||
)
|
||
|
||
assert seeder._pending_scan["compute_hashes"] is True
|
||
|
||
def test_compute_hashes_stays_false(self, seeder):
|
||
"""If both enqueues have compute_hashes=False it stays False."""
|
||
with self._make_busy(seeder):
|
||
seeder.enqueue_scan(
|
||
roots=("models",), phase=ScanPhase.ENRICH, compute_hashes=False
|
||
)
|
||
seeder.enqueue_scan(
|
||
roots=("output",), phase=ScanPhase.ENRICH, compute_hashes=False
|
||
)
|
||
|
||
assert seeder._pending_scan["compute_hashes"] is False
|
||
|
||
def test_triple_merge(self, seeder):
|
||
"""Three successive enqueues should all merge correctly."""
|
||
with self._make_busy(seeder):
|
||
seeder.enqueue_scan(
|
||
roots=("models",), phase=ScanPhase.ENRICH, compute_hashes=False
|
||
)
|
||
seeder.enqueue_scan(
|
||
roots=("input",), phase=ScanPhase.ENRICH, compute_hashes=False
|
||
)
|
||
seeder.enqueue_scan(
|
||
roots=("output",), phase=ScanPhase.ENRICH, compute_hashes=True
|
||
)
|
||
|
||
merged = set(seeder._pending_scan["roots"])
|
||
assert merged == {"models", "input", "output"}
|
||
assert seeder._pending_scan["compute_hashes"] is True
|
||
|
||
|
||
class TestPendingScanDrain:
|
||
@patch("app.assets.seeder.dependencies_available", return_value=True)
|
||
@patch("app.assets.seeder.get_owned_prefixes", return_value=[])
|
||
@patch("app.assets.seeder.sync_root_safely", return_value=set())
|
||
@patch("app.assets.seeder.collect_paths_for_roots", return_value=[])
|
||
@patch("app.assets.seeder.build_asset_specs", return_value=([], {}, 0))
|
||
def test_pending_scan_starts_after_scan(self, *_mocks):
|
||
seeder = _AssetSeeder()
|
||
|
||
seeder._pending_scan = {
|
||
"roots": ("output",),
|
||
"phase": ScanPhase.FULL,
|
||
"compute_hashes": True,
|
||
}
|
||
|
||
real_start = seeder.start
|
||
with patch.object(seeder, "start", wraps=real_start) as mock_start:
|
||
seeder.start_fast(roots=("models",))
|
||
seeder.wait(timeout=5)
|
||
seeder.wait(timeout=5)
|
||
|
||
assert mock_start.call_args_list[-1] == call(
|
||
roots=("output",),
|
||
phase=ScanPhase.FULL,
|
||
prune_first=False,
|
||
compute_hashes=True,
|
||
_start_paused=False,
|
||
)
|
||
|
||
assert seeder._pending_scan is None
|
||
|
||
@patch("app.assets.seeder.dependencies_available", return_value=True)
|
||
def test_pause_is_preserved_when_pending_scan_drains(self, _dependencies):
|
||
seeder = _AssetSeeder()
|
||
phase_ready = threading.Event()
|
||
allow_phase_return = threading.Event()
|
||
drained_phase_calls: list[tuple[str, ...]] = []
|
||
|
||
def gated_enrich(roots):
|
||
if roots == ("models",):
|
||
phase_ready.set()
|
||
allow_phase_return.wait(timeout=5)
|
||
allow_phase_return.clear()
|
||
else:
|
||
drained_phase_calls.append(roots)
|
||
phase_ready.set()
|
||
allow_phase_return.wait(timeout=5)
|
||
return False, 0
|
||
|
||
seeder._pending_scan = {
|
||
"roots": ("output",),
|
||
"phase": ScanPhase.ENRICH,
|
||
"compute_hashes": False,
|
||
}
|
||
real_start = seeder.start
|
||
|
||
def start_and_signal(**kwargs):
|
||
started = real_start(**kwargs)
|
||
if started and kwargs["roots"] == ("output",):
|
||
if seeder._state is State.PAUSED:
|
||
phase_ready.set()
|
||
else:
|
||
phase_ready.wait(timeout=5)
|
||
return started
|
||
|
||
observed = {}
|
||
with (
|
||
patch.object(seeder, "_log_scan_config"),
|
||
patch.object(seeder, "_run_enrich_phase", side_effect=gated_enrich),
|
||
patch.object(seeder, "start", side_effect=start_and_signal),
|
||
):
|
||
try:
|
||
assert seeder.start(
|
||
roots=("models",), phase=ScanPhase.ENRICH
|
||
) is True
|
||
assert phase_ready.wait(timeout=5)
|
||
assert seeder.pause() is True
|
||
phase_ready.clear()
|
||
allow_phase_return.set()
|
||
assert phase_ready.wait(timeout=5)
|
||
|
||
with seeder._lock:
|
||
state_before_resume = seeder._state
|
||
gate_set_before_resume = seeder._run_gate.is_set()
|
||
calls_before_resume = len(drained_phase_calls)
|
||
|
||
phase_ready.clear()
|
||
resume_return = seeder.resume()
|
||
if calls_before_resume == 0:
|
||
assert phase_ready.wait(timeout=5)
|
||
allow_phase_return.set()
|
||
assert seeder.wait(timeout=5)
|
||
|
||
observed = {
|
||
"state_before_resume": state_before_resume,
|
||
"gate_set_before_resume": gate_set_before_resume,
|
||
"resume_return": resume_return,
|
||
"drained_phase_calls_before_resume": calls_before_resume,
|
||
"drained_phase_calls_after_resume": len(drained_phase_calls),
|
||
}
|
||
finally:
|
||
allow_phase_return.set()
|
||
seeder.resume()
|
||
seeder.wait(timeout=5)
|
||
|
||
assert observed == {
|
||
"state_before_resume": State.PAUSED,
|
||
"gate_set_before_resume": False,
|
||
"resume_return": True,
|
||
"drained_phase_calls_before_resume": 0,
|
||
"drained_phase_calls_after_resume": 1,
|
||
}, (
|
||
f"state_before_resume={observed['state_before_resume']!r}, "
|
||
f"gate_set_before_resume={observed['gate_set_before_resume']!r}, "
|
||
f"resume_return={observed['resume_return']!r}, "
|
||
"drained_phase_calls_before_resume="
|
||
f"{observed['drained_phase_calls_before_resume']!r}, "
|
||
"drained_phase_calls_after_resume="
|
||
f"{observed['drained_phase_calls_after_resume']!r}"
|
||
)
|
||
|
||
@patch("app.assets.seeder.dependencies_available", return_value=True)
|
||
@patch("app.assets.seeder.get_owned_prefixes", return_value=[])
|
||
@patch("app.assets.seeder.sync_root_safely", return_value=set())
|
||
@patch("app.assets.seeder.collect_paths_for_roots", return_value=[])
|
||
@patch("app.assets.seeder.build_asset_specs", return_value=([], {}, 0))
|
||
def test_pending_cleared_even_when_start_fails(self, *_mocks):
|
||
seeder = _AssetSeeder()
|
||
seeder._pending_scan = {
|
||
"roots": ("output",),
|
||
"phase": ScanPhase.ENRICH,
|
||
"compute_hashes": False,
|
||
}
|
||
|
||
real_start = seeder.start
|
||
|
||
def start_initial_scan_only(**kwargs):
|
||
if kwargs["roots"] == ("models",):
|
||
return real_start(**kwargs)
|
||
return False
|
||
|
||
with patch.object(seeder, "start", side_effect=start_initial_scan_only):
|
||
seeder.start_fast(roots=("models",))
|
||
seeder.wait(timeout=5)
|
||
|
||
assert seeder._pending_scan is None
|
||
|
||
@patch("app.assets.seeder.dependencies_available", return_value=True)
|
||
@patch("app.assets.seeder.get_owned_prefixes", return_value=[])
|
||
@patch("app.assets.seeder.sync_root_safely", return_value=set())
|
||
@patch("app.assets.seeder.collect_paths_for_roots", return_value=[])
|
||
@patch("app.assets.seeder.build_asset_specs", return_value=([], {}, 0))
|
||
def test_no_drain_when_no_pending(self, *_mocks):
|
||
seeder = _AssetSeeder()
|
||
assert seeder._pending_scan is None
|
||
|
||
real_start = seeder.start
|
||
with patch.object(seeder, "start", wraps=real_start) as mock_start:
|
||
seeder.start_fast(roots=("models",))
|
||
seeder.wait(timeout=5)
|
||
|
||
assert mock_start.call_count == 1
|
||
|
||
|
||
# ---------------------------------------------------------------------------
|
||
# Thread-safety of enqueue_scan
|
||
# ---------------------------------------------------------------------------
|
||
|
||
|
||
class TestEnqueueScanThreadSafety:
|
||
def test_concurrent_enqueues(self, seeder):
|
||
"""Multiple threads enqueuing should not lose roots."""
|
||
with patch.object(seeder, "start", return_value=False):
|
||
barrier = threading.Barrier(3)
|
||
|
||
def enqueue(root):
|
||
barrier.wait()
|
||
seeder.enqueue_scan(
|
||
roots=(root,), phase=ScanPhase.ENRICH, compute_hashes=False
|
||
)
|
||
|
||
threads = [
|
||
threading.Thread(target=enqueue, args=(r,))
|
||
for r in ("models", "input", "output")
|
||
]
|
||
for t in threads:
|
||
t.start()
|
||
for t in threads:
|
||
t.join(timeout=5)
|
||
|
||
merged = set(seeder._pending_scan["roots"])
|
||
assert merged == {"models", "input", "output"}
|