diff --git a/src/frontend/apiserver/middleware/load_test.go b/src/frontend/apiserver/middleware/load_test.go index c43f08ee..16ba8412 100644 --- a/src/frontend/apiserver/middleware/load_test.go +++ b/src/frontend/apiserver/middleware/load_test.go @@ -5,6 +5,7 @@ import ( "encoding/json" "fmt" "net/http" + "os" "sync" "testing" "time" @@ -21,8 +22,8 @@ type AuthResponse struct { } // login -func login(username, password string) (string, error) { - const loginURL = "http://localhost:8080/xce/v1/auth/logon" //replace with your login url +func login(baseURL, username, password string) (string, error) { + loginURL := baseURL + "/xce/v1/auth/logon" // create login request json data loginData := map[string]string{ @@ -61,13 +62,20 @@ func login(username, password string) (string, error) { } // TestLoadJobs test function +// TestLoadJobs is a manual load test against a running API server; it is +// skipped unless XCE_LOAD_TEST_URL (e.g. http://localhost:8080) is set, with +// the credentials in XCE_LOAD_TEST_USER / XCE_LOAD_TEST_PASSWORD. func TestLoadJobs(t *testing.T) { + baseURL := os.Getenv("XCE_LOAD_TEST_URL") + if baseURL == "" { + t.Skip("load test: set XCE_LOAD_TEST_URL (and XCE_LOAD_TEST_USER/XCE_LOAD_TEST_PASSWORD) to run it against a live API server") + } const numRequests = 100 - const username = "user01" // replace with your username - const password = "Welcome@1212" // replace with your password + username := os.Getenv("XCE_LOAD_TEST_USER") + password := os.Getenv("XCE_LOAD_TEST_PASSWORD") fmt.Println("before login") // login to get token - token, err := login(username, password) + token, err := login(baseURL, username, password) if err != nil { t.Fatalf("Failed to log in: %v", err) } @@ -81,7 +89,7 @@ func TestLoadJobs(t *testing.T) { for i := 0; i < numRequests; i++ { go func() { defer wg.Done() - req, err := http.NewRequest("GET", "http://localhost:8080/xce/v1/jobs", nil) // replace with your actual url + req, err := http.NewRequest("GET", baseURL+"/xce/v1/jobs", nil) if err != nil { t.Error("Error creating request:", err) return