Skip to content

Commit 91cb0b0

Browse files
rfyiamcooladhocore
authored andcommitted
feat: add stop for tasker
Signed-off-by: rfyiamcool <[email protected]>
1 parent 4a0cf00 commit 91cb0b0

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

pkg/tasker/tasker_test.go

+23
Original file line numberDiff line numberDiff line change
@@ -200,3 +200,26 @@ func TestConcurrency(t *testing.T) {
200200
}
201201
})
202202
}
203+
204+
func TestStopTasker(t *testing.T) {
205+
t.Run("Run", func(t *testing.T) {
206+
taskr := New(Option{Verbose: true, Out: "../../test/tasker.out"})
207+
208+
var incr int
209+
taskr.Task("* * * * * *", func(ctx context.Context) (int, error) {
210+
incr++
211+
return 0, nil
212+
}, false)
213+
214+
go func() {
215+
time.Sleep(2 * time.Second)
216+
taskr.Stop()
217+
}()
218+
taskr.Run()
219+
fmt.Println(incr)
220+
221+
if incr != 1 {
222+
t.Errorf("the task should run 1x, not %dx", incr)
223+
}
224+
})
225+
}

0 commit comments

Comments
 (0)