Skip to content

Commit

Permalink
chore: Add test coverage over postgres future jobs
Browse files Browse the repository at this point in the history
  • Loading branch information
acaloiaro committed Mar 2, 2024
1 parent c16dd3d commit 9a555f1
Showing 1 changed file with 52 additions and 0 deletions.
52 changes: 52 additions & 0 deletions backends/postgres/postgres_backend_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
}

0 comments on commit 9a555f1

Please sign in to comment.