cmd/testwrapper: Use testwrapper output in github workflows

Fixes #8493

Signed-off-by: Claire Wang <claire@tailscale.com>
clairew/test-wrapper-write-file
Claire Wang 2023-06-30 16:48:12 -04:00
parent 1ca5dcce15
commit 0bde93060c
2 changed files with 23 additions and 9 deletions

View File

@ -93,6 +93,13 @@ jobs:
run: PATH=$PWD/tool:$PATH /tmp/testwrapper ./... ${{matrix.buildflags}} run: PATH=$PWD/tool:$PATH /tmp/testwrapper ./... ${{matrix.buildflags}}
env: env:
GOARCH: ${{ matrix.goarch }} GOARCH: ${{ matrix.goarch }}
- name: upload test output
uses: actions/upload-artifact@v3
with:
name: ${{ github.job }}-${{ runner.os }}-${{ matrix.goarch }}-test-attempts.json
path: test_attempts.json
- name: remove upload test output
run: rm test_attempts.json
- name: bench all - name: bench all
run: PATH=$PWD/tool:$PATH /tmp/testwrapper ./... ${{matrix.buildflags}} -bench=. -benchtime=1x -run=^$ run: PATH=$PWD/tool:$PATH /tmp/testwrapper ./... ${{matrix.buildflags}} -bench=. -benchtime=1x -run=^$
env: env:

View File

@ -28,18 +28,21 @@ import (
const maxAttempts = 3 const maxAttempts = 3
// testAttempt keeps track of the test name, outcome, logs, and if the test is flakey.
// After running the tests, each testAttempt is written to a json file.
type testAttempt struct { type testAttempt struct {
name testName name testName `json:"testName,omitempty"`
outcome string // "pass", "fail", "skip" outcome string `json:"outcome,omitempty"` // "pass", "fail", "skip"
logs bytes.Buffer logs bytes.Buffer
isMarkedFlaky bool // set if the test is marked as flaky isMarkedFlaky bool // set if the test is marked as flaky
pkgFinished bool pkgFinished bool
} }
// testName keeps track of the test name and its package.
type testName struct { type testName struct {
pkg string // "tailscale.com/types/key" Pkg string `json:"pkg,omitempty"` // "tailscale.com/types/key"
name string // "TestFoo" Name string `json:"name,omitempty"` // "TestFoo"
} }
type packageTests struct { type packageTests struct {
@ -120,11 +123,11 @@ func runTests(ctx context.Context, attempt int, pt *packageTests, otherArgs []st
continue continue
} }
name := testName{ name := testName{
pkg: goOutput.Package, Pkg: goOutput.Package,
name: goOutput.Test, Name: goOutput.Test,
} }
if test, _, isSubtest := strings.Cut(goOutput.Test, "/"); isSubtest { if test, _, isSubtest := strings.Cut(goOutput.Test, "/"); isSubtest {
name.name = test name.Name = test
if goOutput.Action == "output" { if goOutput.Action == "output" {
resultMap[name].logs.WriteString(goOutput.Output) resultMap[name].logs.WriteString(goOutput.Output)
} }
@ -135,19 +138,23 @@ func runTests(ctx context.Context, attempt int, pt *packageTests, otherArgs []st
// ignore // ignore
case "run": case "run":
resultMap[name] = &testAttempt{ resultMap[name] = &testAttempt{
name: name, Name: name,
} }
case "skip", "pass", "fail": case "skip", "pass", "fail":
resultMap[name].outcome = goOutput.Action resultMap[name].outcome = goOutput.Action
ch <- resultMap[name] ch <- resultMap[name]
case "output": case "output":
if strings.TrimSpace(goOutput.Output) == flakytest.FlakyTestLogMessage { if strings.TrimSpace(goOutput.Output) == flakytest.FlakyTestLogMessage {
resultMap[name].isMarkedFlaky = true resultMap[name].IsMarkedFlaky = true
} else { } else {
resultMap[name].logs.WriteString(goOutput.Output) resultMap[name].logs.WriteString(goOutput.Output)
} }
} }
} }
for _, result := range resultMap {
testAttemptJson, _ := json.Marshal(result)
f.Write(testAttemptJson)
}
<-done <-done
} }