navidrome/scheduler/scheduler_test.go
Deluan 52099ce91f test: fix flaky watcher and scheduler tests on Windows CI
Replace timing-sensitive time.Sleep synchronization with proper
Eventually/Consistently assertions in watcher tests, and increase
Eventually timeouts from 200ms to 500ms. Add FlakeAttempts(3) to the
inherently timing-dependent tests. For the scheduler test, increase
the Eventually timeout from 1s to 5s for the cron job execution check.
2026-05-03 11:26:07 -04:00

51 lines
1 KiB
Go

package scheduler
import (
"testing"
"time"
"github.com/navidrome/navidrome/log"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
"github.com/robfig/cron/v3"
)
func TestScheduler(t *testing.T) {
log.SetLevel(log.LevelFatal)
RegisterFailHandler(Fail)
RunSpecs(t, "Scheduler Suite")
}
var _ = Describe("Scheduler", func() {
var s *scheduler
BeforeEach(func() {
c := cron.New(cron.WithLogger(&logger{}))
s = &scheduler{c: c}
s.c.Start() // Start the scheduler for tests
})
AfterEach(func() {
s.c.Stop() // Stop the scheduler after tests
})
It("adds and executes a job", FlakeAttempts(3), func() {
done := make(chan struct{})
id, err := s.Add("@every 50ms", func() {
close(done)
})
Expect(err).ToNot(HaveOccurred())
Expect(id).ToNot(BeZero())
Eventually(done, 5*time.Second).Should(BeClosed())
})
It("adds a job with random ~ syntax", func() {
id, err := s.Add("0~59 * * * *", func() {})
Expect(err).ToNot(HaveOccurred())
Expect(id).ToNot(BeZero())
s.Remove(id)
})
})