From 40dbf18893c33bc40c8617d0f3e8de16ce2947e2 Mon Sep 17 00:00:00 2001 From: Lukasz Kasprzak Date: Thu, 17 Sep 2026 14:19:23 +0200 Subject: the applying flag is atomic; its test waits instead of polling The race detector found my own new flag: Apply writes it on a worker and Close reads it from the main loop. The test was polling a plain field too, where the real window hears about the apply on the main loop, which orders the writes. --- gui/internal/model/plan_test.go | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) (limited to 'gui/internal/model/plan_test.go') diff --git a/gui/internal/model/plan_test.go b/gui/internal/model/plan_test.go index 241a049..3b3d7b9 100644 --- a/gui/internal/model/plan_test.go +++ b/gui/internal/model/plan_test.go @@ -487,9 +487,10 @@ func TestCloseDuringApplyIsRefused(t *testing.T) { // Hold the apply open while Close is attempted. <-done } - var applyErr error + finished := make(chan error, 1) go func() { - _, applyErr = tab.Apply(context.Background()) + _, err := tab.Apply(context.Background()) + finished <- err }() <-started @@ -497,12 +498,15 @@ func TestCloseDuringApplyIsRefused(t *testing.T) { t.Error("Close during an apply was allowed: the lock and the log go out from under it") } close(done) - // Let the apply finish before the sandbox is torn down. - for i := 0; i < 200 && !tab.Applied; i++ { - time.Sleep(10 * time.Millisecond) - } - if applyErr != nil { - t.Errorf("the apply itself failed: %v", applyErr) + // Wait for the apply rather than polling its fields: the real window + // hears about it on the main loop, which orders the writes. + select { + case err := <-finished: + if err != nil { + t.Errorf("the apply itself failed: %v", err) + } + case <-time.After(30 * time.Second): + t.Fatal("the apply never finished") } } -- cgit v1.3