mirror of
https://github.com/vmware-tanzu/pinniped.git
synced 2026-09-06 16:17:08 +00:00
test/integration: add test helper to avoid race conditions
We were seeing a race in this test code since the require.NoError() and require.Eventually() would write to the same testing.T state on separate goroutines. Hopefully this helper function should cover the cases when we want to require.NoError() inside a require.Eventually() without causing a race. Signed-off-by: Andrew Keesler <akeesler@vmware.com> Co-authored-by: Margo Crawford <margaretc@vmware.com> Co-authored-by: Monis Khan <i@monis.app>
This commit is contained in:
co-authored by
Margo Crawford
Monis Khan
parent
a0546942b8
commit
8a916ce8ae
@@ -258,16 +258,15 @@ func hasOwnerRef(t *testing.T, obj metav1.Object, ref metav1.OwnerReference) {
|
||||
func isEventuallyDeleted(t *testing.T, f func() error) {
|
||||
t.Helper()
|
||||
|
||||
require.Eventually(t, func() bool {
|
||||
library.RequireEventuallyWithoutError(t, func() (bool, error) {
|
||||
err := f()
|
||||
switch {
|
||||
case err == nil:
|
||||
return false
|
||||
return false, nil
|
||||
case errors.IsNotFound(err):
|
||||
return true
|
||||
return true, nil
|
||||
default:
|
||||
require.NoError(t, err)
|
||||
return false
|
||||
return false, err
|
||||
}
|
||||
}, time.Minute, time.Second)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user