MCPcopy Create free account
hub / github.com/TheThingsNetwork/lorawan-stack / TestTaskQueue

Function TestTaskQueue

pkg/redis/redis_test.go:364–488  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

362}
363
364func 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)

Callers

nothing calls this directly

Calls 15

InitMethod · 0.95
CloseMethod · 0.95
DispatchMethod · 0.95
PopMethod · 0.95
AddMethod · 0.95
NewFunction · 0.92
NewRedisFunction · 0.92
IsCanceledFunction · 0.92
FormatErrorFunction · 0.92
MustNewTFromContextFunction · 0.92
AllTrueFunction · 0.92
DoneMethod · 0.80

Tested by

no test coverage detected