Skip to content

Commit

Permalink
Merge pull request robfig#52 from tdterry/master
Browse files Browse the repository at this point in the history
Correctly schedule new entries
  • Loading branch information
robfig committed Mar 28, 2016
2 parents 32d9c27 + 1e80ac5 commit 124a4d2
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
2 changes: 1 addition & 1 deletion cron.go
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ func (c *Cron) run() {

case newEntry := <-c.add:
c.entries = append(c.entries, newEntry)
newEntry.Next = newEntry.Schedule.Next(now)
newEntry.Next = newEntry.Schedule.Next(time.Now().Local())

case <-c.snapshot:
c.snapshot <- c.entrySnapshot()
Expand Down
16 changes: 16 additions & 0 deletions cron_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,22 @@ func TestAddWhileRunning(t *testing.T) {
}
}

// Test for #34. Adding a job after calling start results in multiple job invocations
func TestAddWhileRunningWithDelay(t *testing.T) {
cron := New()
cron.Start()
defer cron.Stop()
time.Sleep(5 * time.Second)
var calls = 0
cron.AddFunc("* * * * * *", func() { calls += 1 });

<- time.After(ONE_SECOND)
if calls != 1 {
fmt.Printf("called %d times, expected 1\n", calls)
t.Fail()
}
}

// Test timing with Entries.
func TestSnapshotEntries(t *testing.T) {
wg := &sync.WaitGroup{}
Expand Down

0 comments on commit 124a4d2

Please sign in to comment.