diff --git a/.travis.yml b/.travis.yml index ba678db..1d4b500 100644 --- a/.travis.yml +++ b/.travis.yml @@ -9,6 +9,7 @@ install: - go get github.com/rogpeppe/fastuuid - go get golang.org/x/net/context - go get gopkg.in/mgo.v2 +- go get github.com/smartystreets/goconvey/convey before_script: - go vet -x ./... script: diff --git a/README.md b/README.md index 63ce14c..cb1a760 100644 --- a/README.md +++ b/README.md @@ -52,7 +52,7 @@ Building with the source ``` go get -u 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) diff --git a/node/cron/cron_test.go b/node/cron/cron_test.go index f74c9b3..87fc93a 100644 --- a/node/cron/cron_test.go +++ b/node/cron/cron_test.go @@ -2,7 +2,9 @@ package cron import ( "fmt" + "reflect" "sync" + "sync/atomic" "testing" "time" ) @@ -26,6 +28,10 @@ func TestFuncPanicRecovery(t *testing.T) { type DummyJob struct{} +func (d DummyJob) GetID() string { + return fmt.Sprintf("pointer[%v]", reflect.ValueOf(&d).Pointer()) +} + func (d DummyJob) Run() { panic("YOLO") } @@ -115,12 +121,12 @@ func TestAddWhileRunningWithDelay(t *testing.T) { cron.Start() defer cron.Stop() time.Sleep(5 * time.Second) - var calls = 0 - cron.AddFunc("* * * * * *", func() { calls += 1 }) + var calls int32 = 0 + cron.AddFunc("* * * * * *", func() { atomic.AddInt32(&calls, 1) }) <-time.After(ONE_SECOND) - if calls != 1 { - fmt.Printf("called %d times, expected 1\n", calls) + if atomic.LoadInt32(&calls) != 1 { + fmt.Printf("called %d times, expected 1\n", atomic.LoadInt32(&calls)) t.Fail() } } @@ -276,6 +282,10 @@ type testJob struct { name string } +func (t testJob) GetID() string { + return t.name +} + func (t testJob) Run() { t.wg.Done() }