Fix cron test

pull/19/head
miraclesu 8 years ago
parent 65a16cae70
commit f4c990cf44

@ -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:

@ -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)

@ -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()
}

Loading…
Cancel
Save