42 lines
1.1 KiB
Go
42 lines
1.1 KiB
Go
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()
|
|
}
|