fix: park human runs atomically before slow notification work

This commit is contained in:
2026-10-20 16:35:30 +01:00
parent a049b552f6
commit d92fa60259
3 changed files with 56 additions and 4 deletions
+41
View File
@@ -0,0 +1,41 @@
package server
import (
"context"
"path/filepath"
"testing"
"git.a-wan.net/alan/pipelines/internal/pipeline"
)
func TestParkedLaunchCannotRemoveResumedExecution(t *testing.T) {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
store, err := pipeline.Open(filepath.Join(t.TempDir(), "generation.db"))
if err != nil {
t.Fatal(err)
}
defer store.Close()
r := &runner{ctx: ctx, store: store, active: map[int64]activeRun{}}
firstCtx := make(chan context.Context, 1)
firstRelease := make(chan struct{})
r.mu.Lock()
r.launch(1, "/work", func(ctx context.Context) { firstCtx <- ctx; <-firstRelease })
r.mu.Unlock()
old := <-firstCtx
r.mu.Lock()
delete(r.active, 1) // human-stage park transition
r.launch(1, "/work", func(ctx context.Context) { <-ctx.Done() })
resumed := r.active[1]
r.mu.Unlock()
close(firstRelease)
<-old.Done() // registry cleanup precedes launch's deferred cancel
r.mu.Lock()
current, ok := r.active[1]
r.mu.Unlock()
if !ok || current.generation != resumed.generation {
t.Fatal("parked launch removed the resumed execution reservation")
}
cancel()
r.wg.Wait()
}