Skip to content

Commit 684dca3

Browse files
authored
Fix unit test flaky for IPsec controller (#4016)
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 <[email protected]>
1 parent 580ef30 commit 684dca3

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

pkg/agent/controller/ipseccertificate/ipsec_certificate_controller_test.go

+7
Original file line numberDiff line numberDiff line change
@@ -353,6 +353,12 @@ func signCSR(t *testing.T, controller *fakeController,
353353
assert.Empty(t, remain)
354354
req, err := x509.ParseCertificateRequest(block.Bytes)
355355
assert.NoError(t, err)
356+
357+
// Wait one second as the fake clientset doesn't support watching with specific resourceVersion.
358+
// Otherwise the update event would be missed by the watcher used in csrutil.WaitForCertificate()
359+
// if it happens to be generated in-between the List and Watch calls.
360+
time.Sleep(1 * time.Second)
361+
356362
newCert := createCertificate(t, req.Subject.CommonName, controller.caCert,
357363
controller.caKey, req.PublicKey, csr.CreationTimestamp.Time, expirationDuration)
358364
toUpdate := csr.DeepCopy()
@@ -369,6 +375,7 @@ func signCSR(t *testing.T, controller *fakeController,
369375
_, err = controller.kubeClient.CertificatesV1().CertificateSigningRequests().
370376
UpdateStatus(context.TODO(), toUpdate, metav1.UpdateOptions{})
371377
assert.NoError(t, err)
378+
t.Logf("Sign CSR %q successfully", csr.Name)
372379
}
373380

374381
func Test_jitteryDuration(t *testing.T) {

0 commit comments

Comments
 (0)