Fix Thunderbird deselection and review test synchronization

This commit is contained in:
ak47 committed 2026-11-07 15:57:33 -05:00
1 parent e7d02b1f62
commit 7752c4e566
4 files changed
+115 -20

No files matched your search

+35 -18
View File
@@ -197,30 +197,47 @@ func TestWorkerUsesNewestFocusAfterConcurrentCapture(t *testing.T) {
}
func TestWorkerRecapturesAndRepairsStaleCursor(t *testing.T) {
capturer := &fakeCapturer{calls: make(chan captureCall, 2)}
worker, cancel := startWorker(t, capturer, time.Second)
defer cancel()
capturer := &fakeCapturer{calls: make(chan captureCall, 1)}
worker, err := NewWorker(capturer, time.Second)
if err != nil {
t.Fatal(err)
}
firstTree := threeNodeTree(t)
worker.SyncFocus(objectID("/first"))
if err := worker.Move(NextSibling); err != nil {
cursor, err := NewCursor(firstTree)
if err != nil {
t.Fatal(err)
}
firstCall := <-capturer.calls
firstCall.result <- captureResult{tree: firstTree}
if result := waitResult(t, worker); result.Err != nil || result.Position.Current.Name != "Second" {
t.Fatalf("initial result = %#v", result)
focus := objectID("/first")
worker.SyncFocus(focus)
if _, err := cursor.SyncFocus(focus); err != nil {
t.Fatal(err)
}
if position, moved, err := cursor.Move(NextSibling); err != nil || !moved || position.Current.Name != "Second" {
t.Fatalf("initial move = %#v, %v, %v", position, moved, err)
}
// Establish stale state before starting the move. A pending wakeFocus in
// a running worker can otherwise repair this cursor during invalidation,
// so the queued move legitimately needs no capture and the test hangs.
firstTree.Invalidate(objectID("/second"))
if err := worker.Move(NextSibling); err != nil {
t.Fatal(err)
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
results := make(chan moveResult, 1)
go func() { results <- worker.move(ctx, cursor, NextSibling) }()
select {
case call := <-capturer.calls:
call.result <- captureResult{tree: threeNodeTree(t)}
case result := <-results:
t.Fatalf("stale cursor did not recapture: %#v", result)
case <-time.After(time.Second):
t.Fatal("timed out waiting for stale cursor capture")
}
secondCall := <-capturer.calls
secondCall.result <- captureResult{tree: threeNodeTree(t)}
result := waitResult(t, worker)
if result.Err != nil || !result.Moved || result.Position.Current.Name != "Second" {
t.Fatalf("recovered result = %#v, want Second", result)
select {
case result := <-results:
if result.Err != nil || !result.Moved || result.Position.Current.Name != "Second" {
t.Fatalf("recovered result = %#v, want Second", result)
}
case <-time.After(time.Second):
t.Fatal("timed out waiting for recovered move")
}
}