Skip to content

Test support: return error if Ray API response code doesn't match #244

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 23, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 17 additions & 4 deletions test/support/ray_cluster_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package support
import (
"bytes"
"encoding/json"
"fmt"
"io"
"net/http"
"net/url"
Expand Down Expand Up @@ -77,13 +78,17 @@ func (client *rayClusterClient) CreateJob(job *RayJobSetup) (response *RayJobRes
return
}

if resp.StatusCode != 200 {
return nil, fmt.Errorf("incorrect response code: %d for creating Ray Job, response body: %s", resp.StatusCode, respData)
}

err = json.Unmarshal(respData, &response)
return
}

func (client *rayClusterClient) GetJobDetails(jobID string) (response *RayJobDetailsResponse, err error) {
createJobURL := client.endpoint.String() + "/api/jobs/" + jobID
resp, err := http.Get(createJobURL)
getJobDetailsURL := client.endpoint.String() + "/api/jobs/" + jobID
resp, err := http.Get(getJobDetailsURL)
if err != nil {
return
}
Expand All @@ -93,13 +98,17 @@ func (client *rayClusterClient) GetJobDetails(jobID string) (response *RayJobDet
return
}

if resp.StatusCode != 200 {
return nil, fmt.Errorf("incorrect response code: %d for retrieving Ray Job details, response body: %s", resp.StatusCode, respData)
}

err = json.Unmarshal(respData, &response)
return
}

func (client *rayClusterClient) GetJobLogs(jobID string) (logs string, err error) {
createJobURL := client.endpoint.String() + "/api/jobs/" + jobID + "/logs"
resp, err := http.Get(createJobURL)
getJobLogsURL := client.endpoint.String() + "/api/jobs/" + jobID + "/logs"
resp, err := http.Get(getJobLogsURL)
if err != nil {
return
}
Expand All @@ -109,6 +118,10 @@ func (client *rayClusterClient) GetJobLogs(jobID string) (logs string, err error
return
}

if resp.StatusCode != 200 {
return "", fmt.Errorf("incorrect response code: %d for retrieving Ray Job logs, response body: %s", resp.StatusCode, respData)
}

jobLogs := RayJobLogsResponse{}
err = json.Unmarshal(respData, &jobLogs)
return jobLogs.Logs, err
Expand Down