Skip to content

Commit 9a555f1

Browse files
committed
chore: Add test coverage over postgres future jobs
1 parent c16dd3d commit 9a555f1

File tree

1 file changed

+52
-0
lines changed

1 file changed

+52
-0
lines changed

backends/postgres/postgres_backend_test.go

+52
Original file line numberDiff line numberDiff line change
@@ -773,3 +773,55 @@ func Test_ConnectionTimeout(t *testing.T) {
773773
t.Error(err)
774774
}
775775
}
776+
777+
// TestBasicJobProcessing tests that the postgres backend is able to process the most basic jobs with the
778+
// most basic configuration.
779+
func TestFutureJobProcessing(t *testing.T) {
780+
connString, _ := prepareAndCleanupDB(t)
781+
const queue = "testing"
782+
done := make(chan bool)
783+
defer close(done)
784+
785+
timeoutTimer := time.After(5 * time.Second)
786+
787+
ctx := context.Background()
788+
nq, err := neoq.New(ctx, neoq.WithBackend(postgres.Backend), postgres.WithConnectionString(connString))
789+
if err != nil {
790+
t.Fatal(err)
791+
}
792+
defer nq.Shutdown(ctx)
793+
794+
h := handler.New(queue, func(_ context.Context) (err error) {
795+
done <- true
796+
return
797+
})
798+
799+
err = nq.Start(ctx, h)
800+
if err != nil {
801+
t.Error(err)
802+
}
803+
job := &jobs.Job{
804+
Queue: queue,
805+
Payload: map[string]interface{}{
806+
"message": "hello world",
807+
},
808+
RunAfter: time.Now().Add(time.Second * 1),
809+
}
810+
jid, e := nq.Enqueue(ctx, job)
811+
if e != nil || jid == jobs.DuplicateJobID {
812+
t.Error(e)
813+
}
814+
815+
select {
816+
case <-timeoutTimer:
817+
err = jobs.ErrJobTimeout
818+
case <-done:
819+
}
820+
if err != nil {
821+
t.Error(err)
822+
}
823+
824+
if time.Now().Before(job.RunAfter) {
825+
t.Error("job ran before RunAfter")
826+
}
827+
}

0 commit comments

Comments
 (0)