Skip to content

Commit 9b6551b

Browse files
authored
Fix unable to cancel scheduled and non-scheduled builds (#234)
* Fix unable to cancel scheduled and non-scheduled builds * Removed no longer valid test case
1 parent ed1ca01 commit 9b6551b

File tree

2 files changed

+2
-45
lines changed

2 files changed

+2
-45
lines changed

workers/scheduler/scheduler.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -350,8 +350,8 @@ func (s *Scheduler) StopPipelineRun(p *gaia.Pipeline, runID int) error {
350350
if err != nil {
351351
return err
352352
}
353-
if pr.Status != gaia.RunRunning {
354-
return errors.New("pipeline is not in running state")
353+
if pr.Status == gaia.RunFailed || pr.Status == gaia.RunCancelled || pr.Status == gaia.RunSuccess {
354+
return errors.New("pipeline is not in a cancellable state")
355355
}
356356

357357
pr.Status = gaia.RunCancelled

workers/scheduler/scheduler_test.go

-43
Original file line numberDiff line numberDiff line change
@@ -532,49 +532,6 @@ func TestSetPipelineJobs(t *testing.T) {
532532
}
533533
}
534534

535-
func TestStopPipelineRunFailIfPipelineNotInRunningState(t *testing.T) {
536-
gaia.Cfg = &gaia.Config{}
537-
storeInstance := store.NewBoltStore()
538-
tmp, _ := ioutil.TempDir("", "TestStopPipelineRunFailIfPipelineNotInRunningState")
539-
gaia.Cfg.DataPath = tmp
540-
gaia.Cfg.WorkspacePath = filepath.Join(tmp, "tmp")
541-
gaia.Cfg.Bolt.Mode = 0600
542-
gaia.Cfg.Logger = hclog.New(&hclog.LoggerOptions{
543-
Level: hclog.Trace,
544-
Output: hclog.DefaultOutput,
545-
Name: "Gaia",
546-
})
547-
gaia.Cfg.Worker = 2
548-
if err := storeInstance.Init(tmp); err != nil {
549-
t.Fatal(err)
550-
}
551-
p, _ := prepareTestData()
552-
_ = storeInstance.PipelinePut(&p)
553-
s, err := NewScheduler(storeInstance, &MemDBFake{}, &PluginFakeFailed{}, &CAFake{}, &VaultFake{})
554-
if err != nil {
555-
t.Fatal(err)
556-
}
557-
_, err = s.SchedulePipeline(&p, prepareArgs())
558-
if err != nil {
559-
t.Fatal(err)
560-
}
561-
s.schedule()
562-
r, err := storeInstance.PipelineGetRunByPipelineIDAndID(p.ID, 1)
563-
if err != nil {
564-
t.Fatal(err)
565-
}
566-
if r.Status != gaia.RunScheduled {
567-
t.Fatalf("run has status %s but should be %s\n", r.Status, string(gaia.RunScheduled))
568-
}
569-
err = s.StopPipelineRun(&p, 1)
570-
if err == nil {
571-
t.Fatal("error was nil. should have failed")
572-
}
573-
if err.Error() != "pipeline is not in running state" {
574-
t.Fatal("error was not what was expected 'pipeline is not in running state'. got: ", err.Error())
575-
}
576-
}
577-
578535
func TestStopPipelineRun(t *testing.T) {
579536
gaia.Cfg = &gaia.Config{}
580537
storeInstance := store.NewBoltStore()

0 commit comments

Comments
 (0)