facebookarchive / contest

Run continuous and on-demand system testing for real and virtual hardware
MIT License
32 stars 15 forks source link

cli: Fix output in case of server error + report timeout properly #268

Closed tfg13 closed 3 years ago

tfg13 commented 3 years ago

If the server returned any error, the client would not print it, but instead say "invalid JSON response", because it tried to unmarshal the empty response data.

Also fixing a minor problem where it did not report the correct timeout in the error message.

Test Plan: (provoking a timeout error in the server) Before:

> contest % go run ./cmds/clients/contestcli status 14
Requesting URL http://localhost:8080/status with requestor ID 'contestcli-http'
  with params:
    jobID: [14]
    requestor: [contestcli-http]

The server responded with status 400 Bad Request
cannot decode json response: unexpected end of JSON input
exit status 1

Now:

> contest % go run ./cmds/clients/contestcli status 14
Requesting URL http://localhost:8080/status with requestor ID 'contestcli-http'
  with params:
    jobID: [14]
    requestor: [contestcli-http]

The server responded with status 400 Bad Request
{
 "ServerID": "",
 "Data": {
  "Status": null
 },
 "Err": "Status failed: time out waiting for response after 3s"
}
codecov[bot] commented 3 years ago

Codecov Report

Merging #268 (28a920b) into master (307dfa0) will increase coverage by 0.05%. The diff coverage is 26.31%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #268      +/-   ##
==========================================
+ Coverage   66.45%   66.50%   +0.05%     
==========================================
  Files         125      125              
  Lines        5959     5965       +6     
==========================================
+ Hits         3960     3967       +7     
+ Misses       1531     1525       -6     
- Partials      468      473       +5     
Flag Coverage Δ
e2e 45.23% <26.31%> (-0.06%) :arrow_down:
integration 60.24% <0.00%> (+0.32%) :arrow_up:
unittests 43.48% <0.00%> (+0.08%) :arrow_up:

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
pkg/api/api.go 69.92% <0.00%> (ø)
pkg/transport/http/http.go 48.95% <27.77%> (-3.27%) :arrow_down:
pkg/runner/test_runner.go 93.19% <0.00%> (+0.70%) :arrow_up:
plugins/storage/rdbms/init.go 58.46% <0.00%> (+1.53%) :arrow_up:
pkg/jobmanager/jobmanager.go 78.74% <0.00%> (+1.57%) :arrow_up:
pkg/cerrors/cerrors.go 33.33% <0.00%> (+16.66%) :arrow_up:

Continue to review full report at Codecov.

Legend - Click here to learn more Δ = absolute <relative> (impact), ø = not affected, ? = missing data Powered by Codecov. Last update 307dfa0...28a920b. Read the comment docs.