increase test coverage over memory backend

This commit is contained in:
Adriano Caloiaro 2023-03-09 11:03:37 -07:00
parent 1a9db7c00e
commit 784ea57578
No known key found for this signature in database
GPG key ID: C2BC56DE73CE3F75

View file

@ -24,6 +24,8 @@ const (
queue = "testing"
)
var errPeriodicTimeout = errors.New("timed out waiting for periodic job")
// TestBasicJobProcessing tests that the memory backend is able to process the most basic jobs with the
// most basic configuration.
func TestBasicJobProcessing(t *testing.T) {
@ -189,3 +191,42 @@ func TestFutureJobScheduling(t *testing.T) {
t.Error(err)
}
}
func TestCron(t *testing.T) {
const cron = "* * * * * *"
ctx := context.TODO()
nq, err := neoq.New(ctx, neoq.WithBackend(memory.Backend))
if err != nil {
t.Fatal(err)
}
defer nq.Shutdown(ctx)
var done = make(chan bool)
h := handler.New(func(ctx context.Context) (err error) {
done <- true
return
})
h.WithOptions(
handler.Deadline(500*time.Millisecond),
handler.Concurrency(1),
)
err = nq.StartCron(ctx, cron, h)
if err != nil {
t.Error(err)
}
// allow time for listener to start
time.Sleep(5 * time.Millisecond)
select {
case <-time.After(1 * time.Second):
err = errPeriodicTimeout
case <-done:
}
if err != nil {
t.Error(err)
}
}