Merge pull request #114578 from ardaguclu/wrap-ctx-error-until

Embed context deadline exceeded in error to let errors.Is can work
This commit is contained in:
Kubernetes Prow Robot 2022-12-20 08:59:43 -08:00 committed by GitHub
commit b704b96565
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 3 additions and 2 deletions

View File

@ -136,7 +136,7 @@ func UntilWithSync(ctx context.Context, lw cache.ListerWatcher, objType runtime.
if precondition != nil { if precondition != nil {
if !cache.WaitForCacheSync(ctx.Done(), informer.HasSynced) { if !cache.WaitForCacheSync(ctx.Done(), informer.HasSynced) {
return nil, fmt.Errorf("UntilWithSync: unable to sync caches: %v", ctx.Err()) return nil, fmt.Errorf("UntilWithSync: unable to sync caches: %w", ctx.Err())
} }
done, err := precondition(indexer) done, err := precondition(indexer)

View File

@ -19,6 +19,7 @@ package watch
import ( import (
"context" "context"
"errors" "errors"
"fmt"
"reflect" "reflect"
"strings" "strings"
"testing" "testing"
@ -227,7 +228,7 @@ func TestUntilWithSync(t *testing.T) {
conditionFunc: func(e watch.Event) (bool, error) { conditionFunc: func(e watch.Event) (bool, error) {
return true, nil return true, nil
}, },
expectedErr: errors.New("UntilWithSync: unable to sync caches: context deadline exceeded"), expectedErr: fmt.Errorf("UntilWithSync: unable to sync caches: %w", context.DeadlineExceeded),
expectedEvent: nil, expectedEvent: nil,
}, },
{ {