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" "flag"
"fmt" "fmt"
"io" "io"
"io/ioutil"
"math" "math"
"net/http" "net/http"
"os" "os"
@ -174,7 +175,8 @@ func run() error {
return fmt.Errorf("failed to scan source files for modified timestamps: %w", err) 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 build {
if verbose { if verbose {
fmt.Println("CTS needs rebuild:", ctsNeedsRebuild) fmt.Println("CTS needs rebuild:", ctsNeedsRebuild)
@ -491,29 +493,39 @@ func (r *runner) runServer(caseIndices <-chan int, results chan<- result) error
continue continue
} }
var resp Response if postResp.StatusCode == http.StatusOK {
if err := json.NewDecoder(postResp.Body).Decode(&resp); err != nil { var resp Response
res.error = fmt.Errorf("server response decode failure") if err := json.NewDecoder(postResp.Body).Decode(&resp); err != nil {
res.status = fail res.error = fmt.Errorf("server response decode failure")
results <- res res.status = fail
continue results <- res
} continue
}
switch resp.Status { switch resp.Status {
case "pass": case "pass":
res.status = pass res.status = pass
res.message = resp.Message res.message = resp.Message
case "warn": case "warn":
res.status = warn res.status = warn
res.message = resp.Message res.message = resp.Message
case "fail": case "fail":
res.status = fail
res.message = resp.Message
case "skip":
res.status = skip
res.message = resp.Message
default:
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.status = fail
res.message = resp.Message res.error = fmt.Errorf("server error: %v", string(msg))
case "skip":
res.status = skip
res.message = resp.Message
default:
err = fmt.Errorf("unknown status: '%v'", resp.Status)
} }
results <- res results <- res
} }