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

Function TestNonLocalTimezone

cron_test.go:325–356  ·  view source on GitHub ↗

Test that the cron is run in the given time zone (as opposed to local).

(t *testing.T)

Source from the content-addressed store, hash-verified

323
324// Test that the cron is run in the given time zone (as opposed to local).
325func TestNonLocalTimezone(t *testing.T) {
326 wg := &sync.WaitGroup{}
327 wg.Add(2)
328
329 loc, err := time.LoadLocation("Atlantic/Cape_Verde")
330 if err != nil {
331 fmt.Printf("Failed to load time zone Atlantic/Cape_Verde: %+v", err)
332 t.Fail()
333 }
334
335 now := time.Now().In(loc)
336 // FIX: Issue #205
337 // This calculation doesn't work in seconds 58 or 59.
338 // Take the easy way out and sleep.
339 if now.Second() >= 58 {
340 time.Sleep(2 * time.Second)
341 now = time.Now().In(loc)
342 }
343 spec := fmt.Sprintf("%d,%d %d %d %d %d ?",
344 now.Second()+1, now.Second()+2, now.Minute(), now.Hour(), now.Day(), now.Month())
345
346 cron := New(WithLocation(loc), WithParser(secondParser))
347 cron.AddFunc(spec, func() { wg.Done() })
348 cron.Start()
349 defer cron.Stop()
350
351 select {
352 case <-time.After(OneSecond * 2):
353 t.Error("expected job fires 2 times")
354 case <-wait(wg):
355 }
356}
357
358// Test that calling stop before start silently returns without
359// blocking the stop channel.

Callers

nothing calls this directly

Calls 9

NewFunction · 0.85
WithLocationFunction · 0.85
WithParserFunction · 0.85
waitFunction · 0.85
AddFuncMethod · 0.80
DoneMethod · 0.80
StartMethod · 0.80
StopMethod · 0.80
ErrorMethod · 0.65

Tested by

no test coverage detected