mirror of
https://github.com/acaloiaro/neoq
synced 2026-07-21 18:29:08 +00:00
increase test coverage over memory backend
This commit is contained in:
parent
1a9db7c00e
commit
784ea57578
1 changed files with 41 additions and 0 deletions
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue