mirror of
https://github.com/navidrome/navidrome.git
synced 2026-07-09 17:18:45 +00:00
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.
51 lines
1 KiB
Go
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)
|
|
})
|
|
})
|