Enable cache mutation detector in unit tests

Signed-off-by: Monis Khan <mok@vmware.com>
This commit is contained in:
Monis Khan
2020-10-02 22:40:23 -04:00
committed by Matt Moyer
parent 34e6e7567f
commit dc8e7a2f39
2 changed files with 39 additions and 2 deletions

View File

@@ -0,0 +1,29 @@
// Copyright 2020 the Pinniped contributors. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0
package controller
import (
"testing"
"github.com/stretchr/testify/require"
"k8s.io/client-go/tools/cache"
)
func TestCacheMutationDetectorEnabled(t *testing.T) {
// this is a bit of simplistic test to check if we have a real cache mutation detector.
// if we actually start mutating an informer cache in this test, the test will almost
// always fail because the go race detector will see the mutation.
// the cache mutation detector will certainly make certain races more common and thus
// easily detected by the race detector, but its real use is against a compiled binary
// such as pinniped-server running in a pod - that binary has no race detector at runtime.
c := cache.NewCacheMutationDetector("test pinniped")
type isRealCacheMutationDetector interface {
CompareObjects() // this is brittle, but this function name has never changed...
}
_, ok := c.(isRealCacheMutationDetector)
require.Truef(t, ok, "%T is not a real cache mutation detector", c)
}