Fix deadlock when opening files and update E2E tests
This commit is contained in:
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user