Fix deadlock when opening files and update E2E tests

This commit is contained in:
gmp
2026-06-04 13:06:30 -04:00
parent d06f8af0f7
commit ca828569f7
13 changed files with 617 additions and 97 deletions
+19 -4
View File
@@ -4,6 +4,7 @@ package mock
import (
"fmt"
"log"
"os"
"path/filepath"
"sync"
@@ -64,10 +65,11 @@ type notifyEvent struct {
// FileSystem is a thread-safe in-memory filesystem for testing.
type FileSystem struct {
mu sync.RWMutex
files map[string]*File // path -> file
delay time.Duration // uniform delay applied to all operations
changes chan FileChangeEvent // async change notifications (nil = no notifications)
mu sync.RWMutex
files map[string]*File // path -> file
delay time.Duration // uniform delay applied to all operations
changes chan FileChangeEvent // async change notifications (nil = no notifications)
writeError bool // Added to simulate write errors
}
// NewFileSystem creates an empty mock filesystem.
@@ -77,6 +79,13 @@ func NewFileSystem() *FileSystem {
}
}
// SetWriteError simulates I/O errors for Write operations.
func (fs *FileSystem) SetWriteError(err bool) {
fs.mu.Lock()
defer fs.mu.Unlock()
fs.writeError = err
}
// SetDelay sets a uniform delay applied to all IO operations.
func (fs *FileSystem) SetDelay(d time.Duration) {
fs.mu.Lock()
@@ -174,6 +183,12 @@ func (fs *FileSystem) ReadFile(path string) ([]byte, error) {
// WriteFile replaces the content of a file at the given path.
func (fs *FileSystem) WriteFile(path string, content []byte) error {
fs.mu.Lock()
log.Printf("FileSystem: WriteFile to %s, writeError=%v", path, fs.writeError)
if fs.writeError {
fs.mu.Unlock()
return fmt.Errorf("simulated write error")
}
if fs.delay > 0 {
fs.mu.Unlock()
+1
View File
@@ -13,6 +13,7 @@ type Result struct {
Error error `json:"error,omitempty"`
Timestamp time.Time `json:"timestamp"`
DirPath string `json:"dir_path,omitempty"`
FilePath string `json:"file_path,omitempty"` // Added
}
// IsSuccess returns true if the task completed successfully.
+2
View File
@@ -346,12 +346,14 @@ func (t *WriteFileTask) Execute() Result {
TaskType: TypeWriteFile,
Success: false,
Error: err,
FilePath: t.Path, // Set FilePath
}
}
return Result{
TaskID: t.taskID,
TaskType: TypeWriteFile,
Success: true,
FilePath: t.Path, // Set FilePath
}
}