runner: gate stage handoff on settled verified session export
This commit is contained in:
@@ -0,0 +1,62 @@
|
||||
package pipeline
|
||||
|
||||
import (
|
||||
"context"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"git.a-wan.net/alan/pipelines/internal/protocol"
|
||||
)
|
||||
|
||||
func TestSessionExportGateCheckpointAndSuccessorAreAtomic(t *testing.T) {
|
||||
s, id, _ := exportJobFixture(t)
|
||||
ctx := context.Background()
|
||||
step := protocol.RunStep{Sequence: 1, Stage: "one", Status: "completed", Outcome: "success", Target: "two", Output: map[string]any{"markdown": "actual result"}, SessionExport: &protocol.SessionExport{Status: "failed", SessionID: "ses_original", Backend: "v2", Diagnostic: "offline"}}
|
||||
if err := s.FinishStepExportBlocked(ctx, id, step); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := s.BeginStep(ctx, id, 2, "two", nil); err == nil {
|
||||
t.Fatal("successor started while export was incomplete")
|
||||
}
|
||||
if err := s.FinishRun(ctx, id, "failed", "error", "export gate", step.Output); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
job, _ := s.SessionExportJob(ctx, id, 1)
|
||||
claimed, err := s.ClaimSessionExportJob(ctx, time.UnixMilli(job.NextAt), time.Minute)
|
||||
if err != nil || claimed == nil {
|
||||
t.Fatalf("missing export-only retry: %v", err)
|
||||
}
|
||||
if err := s.RecordSessionExportRepair(ctx, id, 1, &protocol.SessionExport{Status: "complete", SessionID: claimed.SessionID, Backend: claimed.Backend, Directory: claimed.Directory, Messages: 2, HTML: "session-repair-1-test.html", HTMLBytes: 100}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := s.FinishSessionExportJob(ctx, claimed, time.Now(), ""); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := s.ResumeSessionExportGate(ctx, id, 1); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := s.ResumeSessionExportGate(ctx, id, 1); err == nil {
|
||||
t.Fatal("duplicate continuation admitted")
|
||||
}
|
||||
// A crash after reserving the continuation but before starting its next
|
||||
// executor must retain the checkpoint for startup's interrupted run.
|
||||
if _, err := s.db.Exec(`UPDATE pipeline_runs SET status='interrupted' WHERE id=?`, id); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
ready, err := s.ReadySessionExportGates(ctx)
|
||||
if err != nil || ready[id] != 1 {
|
||||
t.Fatalf("lost restart checkpoint: %v %v", ready, err)
|
||||
}
|
||||
if err := s.ResumeSessionExportGate(ctx, id, 1); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := s.BeginStep(ctx, id, 2, "two", nil); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if blocked, err := s.SessionExportBlocked(ctx, id); err != nil || blocked {
|
||||
t.Fatalf("successor did not consume checkpoint: %v %v", blocked, err)
|
||||
}
|
||||
if err := s.BeginStep(ctx, id, 2, "two", nil); err == nil {
|
||||
t.Fatal("successor started twice")
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user