Skip to content

testing: add integration tests with real time #211

@CybotTM

Description

@CybotTM

Description

Most tests use mock time, but integration tests with real time would catch timing-related bugs.

Current Approach

Tests use mock clocks for deterministic results:

c := newWithSeconds()
c.clock = clockwork.NewFakeClockAt(time.Now())

Recommended Addition

// integration_test.go (with build tag)
// +build integration

func TestRealTimeScheduling(t *testing.T) {
    if testing.Short() {
        t.Skip("skipping integration test")
    }
    
    c := cron.New()
    c.Start()
    defer c.Stop()
    
    executed := make(chan struct{})
    c.AddFunc("@every 2s", func() {
        close(executed)
    })
    
    select {
    case <-executed:
        // Success
    case <-time.After(5 * time.Second):
        t.Fatal("job not executed within expected time")
    }
}

Benefits

  • Catch real-world timing issues
  • Verify actual system clock behavior
  • Test DST transitions (when they occur)
  • Validate in CI environments

Severity

🟢 Low - Testing improvement

Found By

Pre-1.0 release code review with Zen/Gemini

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions