Skip to content
This repository has been archived by the owner on Nov 8, 2022. It is now read-only.

Commit

Permalink
Fixing error PANIC: close of closed channelfor task.Stop()
Browse files Browse the repository at this point in the history
  • Loading branch information
tiffanyfay committed Oct 23, 2015
1 parent d937264 commit c1cbdbc
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
6 changes: 6 additions & 0 deletions mgmt/rest/client/client_func_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -457,6 +457,9 @@ func TestPulseClient(t *testing.T) {
p3 := c.CreateTask(&Schedule{Type: "simple", Interval: "1s"}, getWMFromSample("1.json"), "baron", true)
p4 := c.StartTask(p3.ID)
So(p4.Err.Error(), ShouldEqual, "error 0: Task is already running. ")

p5 := c.StartTask(p3.ID)
So(p5.Err.Error(), ShouldEqual, "error 0: Task is already running. ")
})
Convey("do returns err!=nil", func() {
port := -1
Expand Down Expand Up @@ -496,6 +499,9 @@ func TestPulseClient(t *testing.T) {
So(p3.Err, ShouldBeNil)
So(p4.ID, ShouldEqual, p3.ID)

p5 := c.StopTask(p3.ID)
So(p5.Err.Error(), ShouldEqual, "error 0: Task is already stopped. ")

b := make([]byte, 5)
rsp, err := c.do("PUT", fmt.Sprintf("/tasks/%v/stop", p1.ID), ContentTypeJSON, b)
So(rsp, ShouldNotBeNil)
Expand Down
2 changes: 2 additions & 0 deletions scheduler/task.go
Original file line number Diff line number Diff line change
Expand Up @@ -314,8 +314,10 @@ func (t *task) spin() {
}
case <-t.killChan:
// Only here can it truly be stopped
t.Lock()
t.state = core.TaskStopped
t.lastFireTime = time.Time{}
t.Unlock()
return
}
}
Expand Down

0 comments on commit c1cbdbc

Please sign in to comment.