Skip to content

Commit 0b6baeb

Browse files
committed
test(robot): close the real cache connection before simulating corruption
The two corruption-recovery tests replaced the live connection with a fake one but never closed the real one. On Windows the orphaned handle kept cache.db open, so the rebuild could not delete the file and reopened the stale data, failing the assertions (read returned an entry, clear_all returned 1). POSIX hid this because deleting an open file is allowed. Closing the real connection first mirrors what _rebuild does in production, where self._conn is always the real connection it closes before purging.
1 parent 2ec7a9c commit 0b6baeb

1 file changed

Lines changed: 6 additions & 1 deletion

File tree

tests/robotcode/robot/diagnostics/test_data_cache.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -320,7 +320,10 @@ def execute(self, *args: object, **kwargs: object) -> object:
320320
def close(self) -> None:
321321
pass
322322

323-
# Simulate the live connection turning corrupt mid-session.
323+
# Simulate the live connection turning corrupt mid-session. Close the real one
324+
# first: otherwise it keeps cache.db open and _rebuild's purge cannot delete the
325+
# file on Windows (production always closes the real connection in _rebuild).
326+
cache._conn.close()
324327
cache._conn = _BoomConnection() # type: ignore[assignment]
325328

326329
# The read must not raise: _run detects the error, rebuilds, and retries.
@@ -346,6 +349,8 @@ def execute(self, *args: object, **kwargs: object) -> object:
346349
def close(self) -> None:
347350
pass
348351

352+
# Close the real connection first so the corrupt file is not held open on Windows.
353+
cache._conn.close()
349354
cache._conn = _BoomConnection() # type: ignore[assignment]
350355

351356
# clear_all is the path the "Clear Cache" command hits; it must recover, not raise.

0 commit comments

Comments
 (0)