mirror of
https://github.com/HKUDS/nanobot.git
synced 2026-08-17 01:26:40 +03:00
fix(session): serialize canonical file access (#5383)
This commit is contained in:
@@ -6,7 +6,7 @@ import errno
|
||||
import os
|
||||
import sys
|
||||
from pathlib import Path
|
||||
from unittest.mock import patch
|
||||
from unittest.mock import call, patch
|
||||
|
||||
import pytest
|
||||
|
||||
@@ -65,6 +65,7 @@ class TestSaveFsync:
|
||||
session.add_message("user", "hello")
|
||||
directory_fd = 987654
|
||||
with (
|
||||
manager.locked_session_files(),
|
||||
patch("nanobot.session.manager.os.open", return_value=directory_fd) as open_dir,
|
||||
patch(
|
||||
"nanobot.session.manager.os.fsync",
|
||||
@@ -76,7 +77,7 @@ class TestSaveFsync:
|
||||
|
||||
assert manager._get_session_path(session.key).exists()
|
||||
open_dir.assert_called_once_with(str(manager.sessions_dir), os.O_RDONLY)
|
||||
close_dir.assert_called_once_with(directory_fd)
|
||||
assert close_dir.call_args_list.count(call(directory_fd)) == 1
|
||||
|
||||
def test_save_propagates_other_directory_fsync_errors(
|
||||
self, manager: SessionManager
|
||||
@@ -85,6 +86,7 @@ class TestSaveFsync:
|
||||
session = manager.get_or_create("test:directory-fsync-io-error")
|
||||
directory_fd = 987654
|
||||
with (
|
||||
manager.locked_session_files(),
|
||||
patch("nanobot.session.manager.os.open", return_value=directory_fd),
|
||||
patch(
|
||||
"nanobot.session.manager.os.fsync",
|
||||
@@ -95,7 +97,7 @@ class TestSaveFsync:
|
||||
):
|
||||
manager.save(session, fsync=True)
|
||||
|
||||
close_dir.assert_called_once_with(directory_fd)
|
||||
assert close_dir.call_args_list.count(call(directory_fd)) == 1
|
||||
|
||||
|
||||
class TestFlushAll:
|
||||
|
||||
Reference in New Issue
Block a user