Skip to content

Commit

Permalink
increase test coverage over memory backend
Browse files Browse the repository at this point in the history
  • Loading branch information
acaloiaro committed Mar 9, 2023
1 parent 1a9db7c commit 784ea57
Showing 1 changed file with 41 additions and 0 deletions.
41 changes: 41 additions & 0 deletions backends/memory/memory_backend_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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)
}
}

0 comments on commit 784ea57

Please sign in to comment.