mirror of https://github.com/shunfei/cronsun
Fix cron test
parent
65a16cae70
commit
f4c990cf44
|
@ -9,6 +9,7 @@ install:
|
||||||
- go get github.com/rogpeppe/fastuuid
|
- go get github.com/rogpeppe/fastuuid
|
||||||
- go get golang.org/x/net/context
|
- go get golang.org/x/net/context
|
||||||
- go get gopkg.in/mgo.v2
|
- go get gopkg.in/mgo.v2
|
||||||
|
- go get github.com/smartystreets/goconvey/convey
|
||||||
before_script:
|
before_script:
|
||||||
- go vet -x ./...
|
- go vet -x ./...
|
||||||
script:
|
script:
|
||||||
|
|
|
@ -52,7 +52,7 @@ Building with the source
|
||||||
```
|
```
|
||||||
go get -u github.com/shunfei/cronsun
|
go get -u github.com/shunfei/cronsun
|
||||||
cd $GOPATH/src/github.com/shunfei/cronsun
|
cd $GOPATH/src/github.com/shunfei/cronsun
|
||||||
sh ./build.sh
|
sh build.sh
|
||||||
```
|
```
|
||||||
|
|
||||||
Or install with the binary [releases](https://github.com/shunfei/cronsun/releases)
|
Or install with the binary [releases](https://github.com/shunfei/cronsun/releases)
|
||||||
|
|
|
@ -2,7 +2,9 @@ package cron
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"reflect"
|
||||||
"sync"
|
"sync"
|
||||||
|
"sync/atomic"
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
@ -26,6 +28,10 @@ func TestFuncPanicRecovery(t *testing.T) {
|
||||||
|
|
||||||
type DummyJob struct{}
|
type DummyJob struct{}
|
||||||
|
|
||||||
|
func (d DummyJob) GetID() string {
|
||||||
|
return fmt.Sprintf("pointer[%v]", reflect.ValueOf(&d).Pointer())
|
||||||
|
}
|
||||||
|
|
||||||
func (d DummyJob) Run() {
|
func (d DummyJob) Run() {
|
||||||
panic("YOLO")
|
panic("YOLO")
|
||||||
}
|
}
|
||||||
|
@ -115,12 +121,12 @@ func TestAddWhileRunningWithDelay(t *testing.T) {
|
||||||
cron.Start()
|
cron.Start()
|
||||||
defer cron.Stop()
|
defer cron.Stop()
|
||||||
time.Sleep(5 * time.Second)
|
time.Sleep(5 * time.Second)
|
||||||
var calls = 0
|
var calls int32 = 0
|
||||||
cron.AddFunc("* * * * * *", func() { calls += 1 })
|
cron.AddFunc("* * * * * *", func() { atomic.AddInt32(&calls, 1) })
|
||||||
|
|
||||||
<-time.After(ONE_SECOND)
|
<-time.After(ONE_SECOND)
|
||||||
if calls != 1 {
|
if atomic.LoadInt32(&calls) != 1 {
|
||||||
fmt.Printf("called %d times, expected 1\n", calls)
|
fmt.Printf("called %d times, expected 1\n", atomic.LoadInt32(&calls))
|
||||||
t.Fail()
|
t.Fail()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -276,6 +282,10 @@ type testJob struct {
|
||||||
name string
|
name string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (t testJob) GetID() string {
|
||||||
|
return t.name
|
||||||
|
}
|
||||||
|
|
||||||
func (t testJob) Run() {
|
func (t testJob) Run() {
|
||||||
t.wg.Done()
|
t.wg.Done()
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue