Add pause resume and abort controls
This commit is contained in:
@@ -59,3 +59,34 @@ func TestClearHistoryKeepsActiveAndPendingRuns(t *testing.T) {
|
||||
q.Stop()
|
||||
close(release)
|
||||
}
|
||||
|
||||
func TestPauseAndResumeActiveRun(t *testing.T) {
|
||||
started := make(chan struct{})
|
||||
release := make(chan struct{})
|
||||
q := New(func(_ context.Context, run model.Run) model.Run {
|
||||
close(started)
|
||||
<-release
|
||||
run.Status = "success"
|
||||
return run
|
||||
}, nil)
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
defer cancel()
|
||||
go q.Run(ctx)
|
||||
if err := q.Enqueue(model.Run{ID: "run", JobID: "job"}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
<-started
|
||||
if !q.SetPaused("run", true) {
|
||||
t.Fatal("active run could not be paused")
|
||||
}
|
||||
if runs := q.Snapshot(); len(runs) != 1 || runs[0].Status != "paused" {
|
||||
t.Fatalf("paused runs = %#v", runs)
|
||||
}
|
||||
if !q.SetPaused("run", false) {
|
||||
t.Fatal("paused run could not be resumed")
|
||||
}
|
||||
if runs := q.Snapshot(); len(runs) != 1 || runs[0].Status != "running" {
|
||||
t.Fatalf("resumed runs = %#v", runs)
|
||||
}
|
||||
close(release)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user