Skip to content

Commit 1512c9e

Browse files
committed
Adding polling wait time for content Lib to sync
1 parent 5ee8107 commit 1512c9e

File tree

2 files changed

+26
-3
lines changed

2 files changed

+26
-3
lines changed

tests/e2e/util.go

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1543,10 +1543,21 @@ func checkVcenterServicesRunning(
15431543
// httpRequest takes client and http Request as input and performs GET operation
15441544
// and returns bodybytes
15451545
func httpRequest(client *http.Client, req *http.Request) ([]byte, int) {
1546+
var bodyBytes []byte
15461547
resp, err := client.Do(req)
15471548
gomega.Expect(err).NotTo(gomega.HaveOccurred())
15481549
defer resp.Body.Close()
1549-
bodyBytes, err := io.ReadAll(resp.Body)
1550+
1551+
maxRetries := 3
1552+
for attempt := 1; attempt <= maxRetries; attempt++ {
1553+
framework.Logf("Attempt %d of httpRequest ", attempt)
1554+
// Create the request
1555+
bodyBytes, err = io.ReadAll(resp.Body)
1556+
if err == nil {
1557+
break
1558+
}
1559+
time.Sleep(pollTimeoutShort)
1560+
}
15501561
framework.Logf("API Response status %d", resp.StatusCode)
15511562
gomega.Expect(err).NotTo(gomega.HaveOccurred())
15521563

tests/e2e/vmservice_utils.go

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -331,12 +331,24 @@ func invokeVCRestAPIGetRequest(vcRestSessionId string, url string) ([]byte, int)
331331

332332
// invokeVCRestAPIPostRequest invokes POST on given VC REST URL using the passed session token and request body
333333
func invokeVCRestAPIPostRequest(vcRestSessionId string, url string, reqBody string) ([]byte, int) {
334+
var err error
335+
var req *http.Request
336+
334337
transCfg := &http.Transport{
335338
TLSClientConfig: &tls.Config{InsecureSkipVerify: true},
336339
}
337340
httpClient := &http.Client{Transport: transCfg}
338-
framework.Logf("Invoking POST on url: %s", url)
339-
req, err := http.NewRequest("POST", url, strings.NewReader(reqBody))
341+
342+
maxRetries := 3
343+
for attempt := 1; attempt <= maxRetries; attempt++ {
344+
framework.Logf("Attempt %d: Invoking POST on URL: %s", attempt, url)
345+
346+
req, err = http.NewRequest("POST", url, strings.NewReader(reqBody))
347+
if err == nil {
348+
break
349+
}
350+
time.Sleep(pollTimeoutShort)
351+
}
340352
gomega.Expect(err).NotTo(gomega.HaveOccurred())
341353
req.Header.Add(vcRestSessionIdHeaderName, vcRestSessionId)
342354
req.Header.Add("Content-type", "application/json")

0 commit comments

Comments
 (0)