MCPcopy
hub / github.com/robfig/cron / TestAddWhileRunningWithDelay

Function TestAddWhileRunningWithDelay

cron_test.go:151–163  ·  cron_test.go::TestAddWhileRunningWithDelay

Test for #34. Adding a job after calling start results in multiple job invocations

(t *testing.T)

Source from the content-addressed store, hash-verified

149
150// Test for #34. Adding a job after calling start results in multiple job invocations
151func TestAddWhileRunningWithDelay(t *testing.T) {
152 cron := newWithSeconds()
153 cron.Start()
154 defer cron.Stop()
155 time.Sleep(5 * time.Second)
156 var calls int64
157 cron.AddFunc("* * * * * *", func() { atomic.AddInt64(&calls, 1) })
158
159 <-time.After(OneSecond)
160 if atomic.LoadInt64(&calls) != 1 {
161 t.Errorf("called %d times, expected 1\n", calls)
162 }
163}
164
165// Add a job, remove a job, start cron, expect nothing runs.
166func TestRemoveBeforeRunning(t *testing.T) {

Callers

nothing calls this directly

Calls 4

newWithSecondsFunction · 0.85
StartMethod · 0.80
StopMethod · 0.80
AddFuncMethod · 0.80

Tested by

no test coverage detected