dawn_node: Improve error handling for run-cts

Rebuild if the `out-node` directory is missing.
Actually check the server's status code.
Fix error handling for bad statuses.

Change-Id: I2164bba528036d39f10852f4ffd8ace76f145dba
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/67780
Reviewed-by: Antonio Maiorano <amaiorano@google.com>
Commit-Queue: Ben Clayton <bclayton@google.com>
This commit is contained in:
Ben Clayton 2021-11-01 22:06:12 +00:00 committed by Dawn LUCI CQ
parent 38e7ce09a0
commit 32e9dd2dfd
1 changed files with 34 additions and 22 deletions

View File

@ -23,6 +23,7 @@ import (
"flag"
"fmt"
"io"
"io/ioutil"
"math"
"net/http"
"os"
@ -174,7 +175,8 @@ func run() error {
return fmt.Errorf("failed to scan source files for modified timestamps: %w", err)
}
ctsNeedsRebuild := mostRecentSourceChange.After(cache.BuildTimestamp)
ctsNeedsRebuild := mostRecentSourceChange.After(cache.BuildTimestamp) ||
!isDir(filepath.Join(r.cts, "out-node"))
if build {
if verbose {
fmt.Println("CTS needs rebuild:", ctsNeedsRebuild)
@ -491,6 +493,7 @@ func (r *runner) runServer(caseIndices <-chan int, results chan<- result) error
continue
}
if postResp.StatusCode == http.StatusOK {
var resp Response
if err := json.NewDecoder(postResp.Body).Decode(&resp); err != nil {
res.error = fmt.Errorf("server response decode failure")
@ -513,7 +516,16 @@ func (r *runner) runServer(caseIndices <-chan int, results chan<- result) error
res.status = skip
res.message = resp.Message
default:
err = fmt.Errorf("unknown status: '%v'", resp.Status)
res.status = fail
res.error = fmt.Errorf("unknown status: '%v'", resp.Status)
}
} else {
msg, err := ioutil.ReadAll(postResp.Body)
if err != nil {
msg = []byte(err.Error())
}
res.status = fail
res.error = fmt.Errorf("server error: %v", string(msg))
}
results <- res
}