(t *testing.T)
| 362 | } |
| 363 | |
| 364 | func TestTaskQueue(t *testing.T) { |
| 365 | a, ctx := test.New(t) |
| 366 | |
| 367 | cl, flush := test.NewRedis(ctx, "redis_test") |
| 368 | defer flush() |
| 369 | defer cl.Close() |
| 370 | |
| 371 | q := &TaskQueue{ |
| 372 | Redis: cl, |
| 373 | MaxLen: 16384, |
| 374 | Group: "testGroup", |
| 375 | Key: cl.Key("test"), |
| 376 | StreamBlockLimit: testStreamBlockLimit(), |
| 377 | } |
| 378 | |
| 379 | err := q.Init(ctx) |
| 380 | a.So(err, should.BeNil) |
| 381 | defer func() { |
| 382 | err := q.Close(ctx) |
| 383 | a.So(err, should.BeNil) |
| 384 | }() |
| 385 | |
| 386 | errCh := make(chan error, 1) |
| 387 | cancelCtx, cancel := context.WithCancel(ctx) |
| 388 | go func() { |
| 389 | errCh <- q.Dispatch(cancelCtx, "testID", nil) |
| 390 | }() |
| 391 | defer func() { |
| 392 | cancel() |
| 393 | |
| 394 | select { |
| 395 | case <-ctx.Done(): |
| 396 | t.Error("Timed out while waiting for Dispatch to finish running") |
| 397 | case err := <-errCh: |
| 398 | if !a.So(errors.IsCanceled(err), should.BeTrue) { |
| 399 | t.Errorf("DispatchTask failed with: %s", test.FormatError(err)) |
| 400 | } |
| 401 | } |
| 402 | }() |
| 403 | |
| 404 | assertPop := func(ctx context.Context, expectedPayload string, expectedStartAt time.Time) bool { |
| 405 | t, a := test.MustNewTFromContext(ctx) |
| 406 | t.Helper() |
| 407 | |
| 408 | type popFuncReq struct { |
| 409 | Pipeliner redis.Pipeliner |
| 410 | Payload string |
| 411 | Time time.Time |
| 412 | Response chan<- error |
| 413 | } |
| 414 | |
| 415 | var called bool |
| 416 | errCh := make(chan error, 1) |
| 417 | go func() { |
| 418 | errCh <- q.Pop(ctx, "testID", nil, func(p redis.Pipeliner, payload string, startAt time.Time) error { |
| 419 | p.Ping(ctx) |
| 420 | a.So(called, should.BeFalse) |
| 421 | a.So(payload, should.Equal, expectedPayload) |
nothing calls this directly
no test coverage detected