Skip to content

Commit

Permalink
Fix unit test flaky for IPsec controller (#4016)
Browse files Browse the repository at this point in the history
Wait one second as the fake clientset doesn't support watching with specific resourceVersion.
Otherwise the update event would be missed by the watcher used in csrutil.WaitForCertificate()
if it happens to be generated in-between the List and Watch calls.

Fixes: #3851

Signed-off-by: Xu Liu <xliu2@vmware.com>
  • Loading branch information
xliuxu authored Jul 27, 2022
1 parent 580ef30 commit 684dca3
Showing 1 changed file with 7 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -353,6 +353,12 @@ func signCSR(t *testing.T, controller *fakeController,
assert.Empty(t, remain)
req, err := x509.ParseCertificateRequest(block.Bytes)
assert.NoError(t, err)

// Wait one second as the fake clientset doesn't support watching with specific resourceVersion.
// Otherwise the update event would be missed by the watcher used in csrutil.WaitForCertificate()
// if it happens to be generated in-between the List and Watch calls.
time.Sleep(1 * time.Second)

newCert := createCertificate(t, req.Subject.CommonName, controller.caCert,
controller.caKey, req.PublicKey, csr.CreationTimestamp.Time, expirationDuration)
toUpdate := csr.DeepCopy()
Expand All @@ -369,6 +375,7 @@ func signCSR(t *testing.T, controller *fakeController,
_, err = controller.kubeClient.CertificatesV1().CertificateSigningRequests().
UpdateStatus(context.TODO(), toUpdate, metav1.UpdateOptions{})
assert.NoError(t, err)
t.Logf("Sign CSR %q successfully", csr.Name)
}

func Test_jitteryDuration(t *testing.T) {
Expand Down

0 comments on commit 684dca3

Please sign in to comment.