mirror of
https://github.com/acaloiaro/neoq
synced 2026-07-21 10:12:18 +00:00
chore: Add test coverage over postgres future jobs
This commit is contained in:
parent
c16dd3d580
commit
9a555f1407
1 changed files with 52 additions and 0 deletions
|
|
@ -773,3 +773,55 @@ func Test_ConnectionTimeout(t *testing.T) {
|
|||
t.Error(err)
|
||||
}
|
||||
}
|
||||
|
||||
// TestBasicJobProcessing tests that the postgres backend is able to process the most basic jobs with the
|
||||
// most basic configuration.
|
||||
func TestFutureJobProcessing(t *testing.T) {
|
||||
connString, _ := prepareAndCleanupDB(t)
|
||||
const queue = "testing"
|
||||
done := make(chan bool)
|
||||
defer close(done)
|
||||
|
||||
timeoutTimer := time.After(5 * time.Second)
|
||||
|
||||
ctx := context.Background()
|
||||
nq, err := neoq.New(ctx, neoq.WithBackend(postgres.Backend), postgres.WithConnectionString(connString))
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
defer nq.Shutdown(ctx)
|
||||
|
||||
h := handler.New(queue, func(_ context.Context) (err error) {
|
||||
done <- true
|
||||
return
|
||||
})
|
||||
|
||||
err = nq.Start(ctx, h)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
job := &jobs.Job{
|
||||
Queue: queue,
|
||||
Payload: map[string]interface{}{
|
||||
"message": "hello world",
|
||||
},
|
||||
RunAfter: time.Now().Add(time.Second * 1),
|
||||
}
|
||||
jid, e := nq.Enqueue(ctx, job)
|
||||
if e != nil || jid == jobs.DuplicateJobID {
|
||||
t.Error(e)
|
||||
}
|
||||
|
||||
select {
|
||||
case <-timeoutTimer:
|
||||
err = jobs.ErrJobTimeout
|
||||
case <-done:
|
||||
}
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
if time.Now().Before(job.RunAfter) {
|
||||
t.Error("job ran before RunAfter")
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue