Skip to content

Commit

Permalink
Tolerate slight difference in condition timestamps in tests
Browse files Browse the repository at this point in the history
I just observed a test flake because there was a second difference
between the lastTransitionTime of a desired vs an actual status
condition. This should avoid that by tolerating up to three seconds of
difference.

I imagine other tests might be vulnerable to this flake too, but for now
I'll just address the one I encountered.

Signed-off-by: Nic Cope <nicc@rk0n.org>
  • Loading branch information
negz committed Jan 19, 2023
1 parent 5c3e677 commit f97d2cd
Showing 1 changed file with 3 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,10 @@ package composite
import (
"context"
"testing"
"time"

"github.com/google/go-cmp/cmp"
"github.com/google/go-cmp/cmp/cmpopts"
corev1 "k8s.io/api/core/v1"
kerrors "k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
Expand Down Expand Up @@ -704,7 +706,7 @@ func TestReconcile(t *testing.T) {
if diff := cmp.Diff(tc.want.err, err, test.EquateErrors()); diff != "" {
t.Errorf("\n%s\nr.Reconcile(...): -want error, +got error:\n%s", tc.reason, diff)
}
if diff := cmp.Diff(tc.want.r, got, test.EquateErrors()); diff != "" {
if diff := cmp.Diff(tc.want.r, got, test.EquateErrors(), cmpopts.EquateApproxTime(3*time.Second)); diff != "" {
t.Errorf("\n%s\nr.Reconcile(...): -want, +got:\n%s", tc.reason, diff)
}
})
Expand Down

0 comments on commit f97d2cd

Please sign in to comment.