Skip to content

Commit

Permalink
Fixed utils_test.go in {iclient|imgr}/{iclient|imgr}pkg/utils_test.go…
Browse files Browse the repository at this point in the history
… to not "race" during startup

Previously, we were just lucky that iswift and imgr came up faster than test code's first attempt to talk to them
  • Loading branch information
edmc-ss committed Jul 22, 2022
1 parent 27ead91 commit 4069bd4
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 13 deletions.
29 changes: 21 additions & 8 deletions iclient/iclientpkg/utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ const (
testVolume = "testvol"
testRPCDeadlineIO = "60s"
testRPCKeepAlivePeriod = "60s"
testStartupDelay = 100 * time.Millisecond
)

type testGlobalsStruct struct {
Expand Down Expand Up @@ -82,8 +83,8 @@ func testSetup(t *testing.T) {
caKeyFile: tempDir + "/caKeyFile",
endpointCertFile: tempDir + "/endpoingCertFile",
endpointKeyFile: tempDir + "/endpointKeyFile",
imgrHTTPServerURL: fmt.Sprintf("http://%s:%d", testIPAddr, testMgrHTTPServerPort),
authURL: fmt.Sprintf("http://%s:%d/auth/v1.0", testIPAddr, testSwiftProxyTCPPort),
imgrHTTPServerURL: "http://" + net.JoinHostPort(testIPAddr, fmt.Sprintf("%d", testMgrHTTPServerPort)),
authURL: "http://" + net.JoinHostPort(testIPAddr, fmt.Sprintf("%d", testSwiftProxyTCPPort)) + "/auth/v1.0",
}

testGlobals.caCertPEMBlock, testGlobals.caKeyPEMBlock, err = icertpkg.GenCACert(
Expand Down Expand Up @@ -244,14 +245,18 @@ func testSetup(t *testing.T) {
t.Fatalf("iswiftpkg.Start(testGlobals.confMap) failed: %v", err)
}

authRequestHeaders = make(http.Header)
for {
authRequestHeaders = make(http.Header)

authRequestHeaders["X-Auth-User"] = []string{testSwiftAuthUser}
authRequestHeaders["X-Auth-Key"] = []string{testSwiftAuthKey}
authRequestHeaders["X-Auth-User"] = []string{testSwiftAuthUser}
authRequestHeaders["X-Auth-Key"] = []string{testSwiftAuthKey}

authResponseHeaders, _, err = testDoHTTPRequest("GET", testGlobals.authURL, authRequestHeaders, nil)
if nil != err {
t.Fatalf("testDoHTTPRequest(\"GET\", testGlobals.authURL, authRequestHeaders, nil) failed: %v", err)
authResponseHeaders, _, err = testDoHTTPRequest("GET", testGlobals.authURL, authRequestHeaders, nil)
if nil == err {
break
}

time.Sleep(testStartupDelay)
}

testGlobals.authToken = authResponseHeaders.Get("X-Auth-Token")
Expand Down Expand Up @@ -288,6 +293,14 @@ func testSetup(t *testing.T) {
t.Fatalf("imgrpkg.Start(testGlobals.confMap) failed: %v", err)
}

for {
_, _, err = testDoHTTPRequest("GET", testGlobals.imgrHTTPServerURL+"/version", nil, nil)
if nil == err {
break
}
time.Sleep(testStartupDelay)
}

postAndPutVolumePayload = fmt.Sprintf("{\"StorageURL\":\"%s\",\"AuthToken\":\"%s\"}", testGlobals.containerURL, testGlobals.authToken)

_, _, err = testDoHTTPRequest("POST", testGlobals.imgrHTTPServerURL+"/volume", nil, strings.NewReader(postAndPutVolumePayload))
Expand Down
22 changes: 17 additions & 5 deletions imgr/imgrpkg/utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ const (
testVolume = "testVolume"
testRPCDeadlineIO = "60s"
testRPCKeepAlivePeriod = "60s"
testStartupDelay = 100 * time.Millisecond
)

type testGlobalsStruct struct {
Expand Down Expand Up @@ -76,8 +77,8 @@ func testSetup(t *testing.T, overrideConfStrings []string, retryrpcCallbacks int
caKeyFile: tempDir + "/caKeyFile",
endpointCertFile: tempDir + "/endpoingCertFile",
endpointKeyFile: tempDir + "/endpointKeyFile",
httpServerURL: fmt.Sprintf("http://%s:%d", testIPAddr, testHTTPServerPort),
authURL: fmt.Sprintf("http://%s:%d/auth/v1.0", testIPAddr, testSwiftProxyTCPPort),
httpServerURL: "http://" + net.JoinHostPort(testIPAddr, fmt.Sprintf("%d", testHTTPServerPort)),
authURL: "http://" + net.JoinHostPort(testIPAddr, fmt.Sprintf("%d", testSwiftProxyTCPPort)) + "/auth/v1.0",
}

testGlobals.caCertPEMBlock, testGlobals.caKeyPEMBlock, err = icertpkg.GenCACert(
Expand Down Expand Up @@ -194,9 +195,12 @@ func testSetup(t *testing.T, overrideConfStrings []string, retryrpcCallbacks int
t.Fatalf("iswiftpkg.Start(testGlobals.confMap) failed: %v", err)
}

err = testDoAuth()
if nil != err {
t.Fatalf("testDoAuth() failed: %v", err)
for {
err = testDoAuth()
if nil == err {
break
}
time.Sleep(testStartupDelay)
}

testGlobals.containerURL = testGlobals.accountURL + "/" + testContainer
Expand Down Expand Up @@ -224,6 +228,14 @@ func testSetup(t *testing.T, overrideConfStrings []string, retryrpcCallbacks int
t.Fatalf("Start(testGlobals.confMap) failed: %v", err)
}

for {
_, _, err = testDoHTTPRequest("GET", testGlobals.httpServerURL+"/version", nil, nil, http.StatusOK)
if nil == err {
break
}
time.Sleep(testStartupDelay)
}

retryrpcDeadlineIO, err = time.ParseDuration(testRPCDeadlineIO)
if nil != err {
t.Fatalf("time.ParseDuration(\"%s\") failed: %v", testRPCDeadlineIO, err)
Expand Down

0 comments on commit 4069bd4

Please sign in to comment.