Skip to content

Commit

Permalink
feat: add stop for tasker
Browse files Browse the repository at this point in the history
Signed-off-by: rfyiamcool <[email protected]>
  • Loading branch information
rfyiamcool authored and adhocore committed Mar 10, 2024
1 parent 4a0cf00 commit 91cb0b0
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions pkg/tasker/tasker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -200,3 +200,26 @@ func TestConcurrency(t *testing.T) {
}
})
}

func TestStopTasker(t *testing.T) {
t.Run("Run", func(t *testing.T) {
taskr := New(Option{Verbose: true, Out: "../../test/tasker.out"})

var incr int
taskr.Task("* * * * * *", func(ctx context.Context) (int, error) {
incr++
return 0, nil
}, false)

go func() {
time.Sleep(2 * time.Second)
taskr.Stop()
}()
taskr.Run()
fmt.Println(incr)

if incr != 1 {
t.Errorf("the task should run 1x, not %dx", incr)
}
})
}

0 comments on commit 91cb0b0

Please sign in to comment.