2
0
mirror of https://github.com/hibiken/asynq.git synced 2026-07-31 20:03:39 +08:00

test: add coverage for BatchEnqueue error paths

Add tests for all uncovered BatchEnqueueContext error paths: nil task,
empty/blank typename, invalid options, group rejection, unique rejection,
and broker-down (sleeping broker). Add pipeline error test for rdb.BatchEnqueue
via cancelled context, and TestTaskOptions/TestTaskOptionsNil for the
new Options() accessor on Task.
This commit is contained in:
Erik Nilsen
2026-04-10 10:14:01 -07:00
parent 68f03688e3
commit a32ac05d09
3 changed files with 127 additions and 0 deletions

View File

@@ -293,6 +293,21 @@ func TestBatchEnqueue(t *testing.T) {
t.Errorf("state for scheduled task %s = %q, want %q", s1.ID, state, "scheduled")
}
})
t.Run("pipeline error from cancelled context", func(t *testing.T) {
h.FlushDB(t, r.client)
msg := h.NewTaskMessage("pipeline_error_task", nil)
items := []base.BatchEnqueueItem{{Msg: msg}}
ctx, cancel := context.WithCancel(context.Background())
cancel()
_, err := r.BatchEnqueue(ctx, items)
if err == nil {
t.Error("BatchEnqueue with cancelled context returned nil error, want non-nil")
}
})
}
func TestEnqueueQueueCache(t *testing.T) {