Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 8 additions & 15 deletions dkron/scheduler_test.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
package dkron

import (
"fmt"
"testing"
"time"

"github.com/distribworks/dkron/v4/extcron"
"github.com/robfig/cron/v3"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
Expand Down Expand Up @@ -95,29 +92,25 @@ func TestScheduleStop(t *testing.T) {
log := getTestLogger()
sched := NewScheduler(log)

sched.Cron = cron.New(cron.WithParser(extcron.NewParser()))
_, err := sched.Cron.AddFunc("@every 2s", func() {
time.Sleep(time.Second * 5)
fmt.Println("function done")
})
require.NoError(t, err)
sched.Cron.Start()
sched.started = true

testJob1 := &Job{
Name: "cron_job",
Schedule: "@every 2s",
Schedule: "@every 10m",
Executor: "shell",
ExecutorConfig: map[string]string{"command": "echo 'test1'", "shell": "true"},
Owner: "John Dough",
OwnerEmail: "foo@bar.com",
}

// Start the scheduler with a real job
err := sched.Start([]*Job{testJob1}, &Agent{})
require.NoError(t, err)

// Starting again while already started should return an error
err = sched.Start([]*Job{testJob1}, &Agent{})
assert.Error(t, err)

// Wait for the job to start
time.Sleep(time.Second * 2)
<-sched.Stop().Done()

err = sched.Start([]*Job{testJob1}, &Agent{})
assert.NoError(t, err)

Expand Down
Loading