Skip to content

Commit

Permalink
fix: test2json: detect test timeouts and other package-level errors
Browse files Browse the repository at this point in the history
This was ignoring all non-test events, unfortunately this means if there
is a panic or a test timeout we may not detect the failure.

Signed-off-by: Brian Goff <[email protected]>
  • Loading branch information
cpuguy83 committed Dec 20, 2024
1 parent 6767e06 commit fcf1720
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ jobs:
- name: download deps
run: go mod download
- name: Run integration tests
run: go test -v -json ./test | go run ./cmd/test2json2gha
run: go test -v -timeout=30m -json ./test | go run ./cmd/test2json2gha
- name: dump logs
if: failure()
run: sudo journalctl -u docker
Expand Down
9 changes: 6 additions & 3 deletions cmd/test2json2gha/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ func do(in io.Reader, out io.Writer, modName string) (bool, error) {
return tr, nil
}

var anyFail bool
for {
*te = TestEvent{}
if err := dec.Decode(te); err != nil {
Expand All @@ -115,20 +116,22 @@ func do(in io.Reader, out io.Writer, modName string) (bool, error) {
if te.Test == "" {
// Don't bother processing events that aren't specifically for a test
// Go adds extra events in for package level info that we don't need.
if te.Action == "fail" {
anyFail = true
}
continue
}

tr, err := getOutputStream()
if err != nil {
return false, err
}
if err := handlEvent(te, tr); err != nil {
if err := handleEvent(te, tr); err != nil {
slog.Error("Error handing event test event", "error", err)
}
}

buf := bufio.NewWriter(out)
var anyFail bool

for _, tr := range outs {
if tr.failed {
Expand All @@ -148,7 +151,7 @@ func do(in io.Reader, out io.Writer, modName string) (bool, error) {
return anyFail, nil
}

func handlEvent(te *TestEvent, tr *TestResult) error {
func handleEvent(te *TestEvent, tr *TestResult) error {
if te.Output != "" {
_, err := tr.output.Write([]byte(te.Output))
if err != nil {
Expand Down

0 comments on commit fcf1720

Please sign in to comment.