Skip to content

Commit

Permalink
test(cron): adding test for IsRunning function
Browse files Browse the repository at this point in the history
Adds a test to validate the IsRunning function
  • Loading branch information
sc250024 committed Jun 22, 2023
1 parent a1ce701 commit 7d80021
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions cron_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -687,6 +687,25 @@ func wait(wg *sync.WaitGroup) chan bool {
return ch
}

func TestIsRunning(t *testing.T) {
wg := &sync.WaitGroup{}
wg.Add(1)
cron := New()
cron.AddFunc("* * * * * ?", func() { wg.Done() })

cron.Start()
time.Sleep(1 * time.Second)
if !cron.IsRunning() {
t.Error("cron is reporting as not running when it should be running")
}

cron.Stop()
time.Sleep(1 * time.Second)
if cron.IsRunning() {
t.Error("cron is reporting as running when it should be not running")
}
}

func stop(cron *Cron) chan bool {
ch := make(chan bool)
go func() {
Expand Down

0 comments on commit 7d80021

Please sign in to comment.