From 5251bd07308d03721792b61e8b5b11bf32c7b8aa Mon Sep 17 00:00:00 2001 From: Xu Liu Date: Fri, 15 Jul 2022 14:50:27 +0800 Subject: [PATCH] Fix unit test flaky for IPsec controller 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 --- .../ipseccertificate/ipsec_certificate_controller_test.go | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/pkg/agent/controller/ipseccertificate/ipsec_certificate_controller_test.go b/pkg/agent/controller/ipseccertificate/ipsec_certificate_controller_test.go index b01d3e101aa..5682122e726 100644 --- a/pkg/agent/controller/ipseccertificate/ipsec_certificate_controller_test.go +++ b/pkg/agent/controller/ipseccertificate/ipsec_certificate_controller_test.go @@ -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() @@ -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) {