Skip to content

Commit

Permalink
更新依赖
Browse files Browse the repository at this point in the history
  • Loading branch information
guonaihong committed Nov 6, 2022
1 parent 8a4da60 commit 9f3c434
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 3 deletions.
21 changes: 21 additions & 0 deletions cronex_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package cronex

import (
"fmt"
"sync/atomic"
"testing"
"time"

Expand Down Expand Up @@ -60,6 +61,7 @@ func Test_Cronex(t *testing.T) {
assert.NotEqual(t, count, 1, fmt.Sprintf("callback没有调用"))
}

// 测试下Next函数的时间可正确
func Test_Cronex_ParseNext(t *testing.T) {

var schedule timer.Next
Expand All @@ -82,3 +84,22 @@ func Test_Cronex_ParseNext(t *testing.T) {
}
}
}

// 多次运行的例子
func Test_Multiple(t *testing.T) {
cron := New()
count := int32(0)

cron.Start()
max := int32(10)
for i := int32(0); i < max; i++ {
cron.AddFunc("* * * * * *", func() {
fmt.Printf("Every Second")
atomic.AddInt32(&count, 1)
})
}

time.Sleep(time.Duration(1.1 * float64(time.Second)))
cron.Stop()
assert.Equal(t, max, count)
}
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module github.com/antlabs/cronex
go 1.19

require (
github.com/antlabs/timer v0.0.8
github.com/antlabs/timer v0.0.9
github.com/stretchr/testify v1.6.1
)

Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
github.com/antlabs/stl v0.0.1 h1:TRD3csCrjREeLhLoQ/supaoCvFhNLBTNIwuRGrDIs6Q=
github.com/antlabs/stl v0.0.1/go.mod h1:wvVwP1loadLG3cRjxUxK8RL4Co5xujGaZlhbztmUEqQ=
github.com/antlabs/timer v0.0.8 h1:jXHDhsq04YT8+4G32PAfQzqifhoWsBTHQo93x/K4euc=
github.com/antlabs/timer v0.0.8/go.mod h1:EuoyzCfnpVUmlRwsLvNo/uQuvqUm0CqJhT7FiqHWSdQ=
github.com/antlabs/timer v0.0.9 h1:YW12W4YvwmDUUJ93BiLuSuoxdiXzPhwbJDYXGj0MTE8=
github.com/antlabs/timer v0.0.9/go.mod h1:EuoyzCfnpVUmlRwsLvNo/uQuvqUm0CqJhT7FiqHWSdQ=
github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
Expand Down

0 comments on commit 9f3c434

Please sign in to comment.