Frame now carries view state (scale/focus/query) to the main goroutine, which reads only the frame-receiver-stored snapshot. Renderer owns Gio widget editors (registered by ID) and the draw scale. Autosave timer sends a token to the logic goroutine instead of touching state; Shutdown waits for the owner to exit before FlushAll. Tests access state only through owner-side Inspect/WithState helpers (harness + in-package). Fixed double-Harness.Run race in two e2e tests, made TestWorkerPool_PriorityPreemption deterministic, and raised the lazy-loading test timeout that was too short under -race. go test -race ./... is now green.
54 lines
1.1 KiB
Go
54 lines
1.1 KiB
Go
package editor
|
|
|
|
import (
|
|
"testing"
|
|
"time"
|
|
|
|
"pad/internal/io/pool/mock"
|
|
)
|
|
|
|
func TestOpenFileIntegration(t *testing.T) {
|
|
// 1. Setup Logic
|
|
mockFS := mock.NewFileSystem()
|
|
filename := "/README.md"
|
|
content := "Hello World"
|
|
mockFS.AddFile(filename, []byte(content), time.Now())
|
|
|
|
l := NewLogic(mockFS, "/", func(string) {})
|
|
go l.Run()
|
|
defer l.Shutdown()
|
|
|
|
// Drain frameChan to prevent deadlocks
|
|
go func() {
|
|
for range l.FrameChan() {
|
|
}
|
|
}()
|
|
|
|
// Initialize global state on the owner
|
|
withState(t, l, func(st *State) {
|
|
TheState = st
|
|
})
|
|
|
|
// 2. Open File
|
|
// OpenFile dispatches the task to openFileChan, which Run() will consume
|
|
OpenFile(filename)
|
|
|
|
// 3. Process the Result
|
|
// We wait for the state to update, which happens when ReadChunkTask completes
|
|
success := false
|
|
for i := 0; i < 20; i++ {
|
|
v, ok := l.Inspect(func(st *State) any { return st.Editor.GetBuffer() })
|
|
if ok && v.(string) == content {
|
|
success = true
|
|
break
|
|
}
|
|
time.Sleep(100 * time.Millisecond)
|
|
}
|
|
|
|
// 4. Assert
|
|
if !success {
|
|
got, _ := l.Inspect(func(st *State) any { return st.Editor.Buffer })
|
|
t.Errorf("Expected content %q, got %q", content, got)
|
|
}
|
|
}
|