Skip to content

Commit

Permalink
Fix unit test flaky for IPsec controller
Browse files Browse the repository at this point in the history
Wait one second before updating the CSR to mitigate the issue
that the CSR update event might be missed in WaitForCertificate().

Fixes: #3851

Signed-off-by: Xu Liu <[email protected]>
  • Loading branch information
xliuxu committed Jul 21, 2022
1 parent 4b788e7 commit 9cb00ed
Showing 1 changed file with 6 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -353,6 +353,11 @@ 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.
// The update event may be missed by the watcher used in csrutil.WaitForCertificate()
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 +374,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 9cb00ed

Please sign in to comment.