aboutsummaryrefslogtreecommitdiff
path: root/gui/internal/model/plan_test.go
diff options
context:
space:
mode:
authorLukasz Kasprzak <lukas@labunix.xyz>2026-09-17 14:19:23 +0200
committerLukasz Kasprzak <lukas@labunix.xyz>2026-09-17 14:19:23 +0200
commit40dbf18893c33bc40c8617d0f3e8de16ce2947e2 (patch)
tree01f9d77818c2dbfce1684895f562ae3dc865d44c /gui/internal/model/plan_test.go
parentb66850cc8c584cc00bcd796eb3aa238bcf87394a (diff)
downloadkrino-40dbf18893c33bc40c8617d0f3e8de16ce2947e2.tar.gz
krino-40dbf18893c33bc40c8617d0f3e8de16ce2947e2.zip
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.
Diffstat (limited to 'gui/internal/model/plan_test.go')
-rw-r--r--gui/internal/model/plan_test.go20
1 files changed, 12 insertions, 8 deletions
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")
}
}