2
0
mirror of https://github.com/hibiken/asynq.git synced 2024-12-26 07:42:17 +08:00

Fix tests

This commit is contained in:
Ken Hibino 2022-02-16 06:51:09 -08:00
parent ebd7a32c0f
commit 5490d2c625
2 changed files with 22 additions and 11 deletions

View File

@ -6,6 +6,7 @@ package context
import (
"context"
"fmt"
"testing"
"time"
@ -60,9 +61,22 @@ func TestCreateContextWithBaseContext(t *testing.T) {
var value ctxValue = "value"
tests := []struct {
baseCtx context.Context
baseCtx context.Context
validate func(ctx context.Context, t *testing.T) error
}{
{context.WithValue(context.Background(), key, value)},
{
baseCtx: context.WithValue(context.Background(), key, value),
validate: func(ctx context.Context, t *testing.T) error {
got, ok := ctx.Value(key).(ctxValue)
if !ok {
return fmt.Errorf("ctx.Value().(ctxValue) returned false, expected to be true")
}
if want := value; got != want {
return fmt.Errorf("ctx.Value().(ctxValue) returned unknown value (%v), expected to be %s", got, value)
}
return nil
},
},
}
for _, tc := range tests {
@ -76,18 +90,13 @@ func TestCreateContextWithBaseContext(t *testing.T) {
defer cancel()
select {
case <-ctx.Done():
case x := <-ctx.Done():
t.Errorf("<-ctx.Done() == %v, want nothing (it should block)", x)
default:
t.Errorf("ctx.Done() blocked, want it to be non-blocking")
}
v, ok := ctx.Value(key).(ctxValue)
original, _ := tc.baseCtx.Value(key).(ctxValue)
if !ok {
t.Errorf("ctx.Value().(ctxValue) returned false, expected to be true")
}
if v != original {
t.Errorf("ctx.Value().(ctxValue) returned unknown value (%v), expected to be %s", v, value)
if err := tc.validate(ctx, t); err != nil {
t.Errorf("%v", err)
}
}
}

View File

@ -61,6 +61,7 @@ func newProcessorForTest(t *testing.T, r *rdb.RDB, h Handler) *processor {
p := newProcessor(processorParams{
logger: testLogger,
broker: r,
baseCtxFn: context.Background,
retryDelayFunc: DefaultRetryDelayFunc,
isFailureFunc: defaultIsFailureFunc,
syncCh: syncCh,
@ -592,6 +593,7 @@ func TestProcessorWithStrictPriority(t *testing.T) {
p := newProcessor(processorParams{
logger: testLogger,
broker: rdbClient,
baseCtxFn: context.Background,
retryDelayFunc: DefaultRetryDelayFunc,
isFailureFunc: defaultIsFailureFunc,
syncCh: syncCh,