Test that the cron is run in the given time zone (as opposed to local).
(t *testing.T)
| 323 | |
| 324 | // Test that the cron is run in the given time zone (as opposed to local). |
| 325 | func 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. |
nothing calls this directly
no test coverage detected