Skip to content

Commit ed6537b

Browse files
committed
cmd/coordinator: parse "header" instead of "banner"
In preparation of supporting a longer test header, change parseOutputAndBanner to parseOutputAndHeader which returns the full human-readable header. The only behavior change is that output with only a banner and no trailing newline will still return the banner as part of the header. For golang/go#50146 Change-Id: Ie34fe3891e9bc29a3da79fddacd4829a89d2dbfb Reviewed-on: https://go-review.googlesource.com/c/build/+/372537 Reviewed-by: Alex Rakoczy <[email protected]> Trust: Michael Pratt <[email protected]> Run-TryBot: Michael Pratt <[email protected]> TryBot-Result: Gopher Robot <[email protected]>
1 parent 4c800c5 commit ed6537b

File tree

2 files changed

+41
-30
lines changed

2 files changed

+41
-30
lines changed

cmd/coordinator/buildstatus.go

Lines changed: 26 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1400,7 +1400,7 @@ func (st *buildStatus) runTests(helpers <-chan buildlet.Client) (remoteErr, err
14001400
close(buildletsGone)
14011401
}()
14021402

1403-
var lastBanner string
1403+
var lastHeader string
14041404
var serialDuration time.Duration
14051405
for _, ti := range set.items {
14061406
AwaitDone:
@@ -1420,10 +1420,10 @@ func (st *buildStatus) runTests(helpers <-chan buildlet.Client) (remoteErr, err
14201420

14211421
serialDuration += ti.execDuration
14221422
if len(ti.output) > 0 {
1423-
banner, out := parseOutputAndBanner(ti.output)
1424-
if banner != lastBanner {
1425-
lastBanner = banner
1426-
fmt.Fprintf(st, "\n##### %s\n", banner)
1423+
header, out := parseOutputAndHeader(ti.output)
1424+
if header != lastHeader {
1425+
lastHeader = header
1426+
fmt.Fprintf(st, "\n%s\n", header)
14271427
}
14281428
if pool.NewGCEConfiguration().InStaging() {
14291429
out = bytes.TrimSuffix(out, nl)
@@ -1454,20 +1454,32 @@ func (st *buildStatus) runTests(helpers <-chan buildlet.Client) (remoteErr, err
14541454
const (
14551455
banner = "XXXBANNERXXX:" // flag passed to dist
14561456
bannerPrefix = "\n" + banner // with the newline added by dist
1457+
1458+
outputBanner = "##### " // banner to display in output.
14571459
)
14581460

14591461
var bannerPrefixBytes = []byte(bannerPrefix)
14601462

1461-
func parseOutputAndBanner(b []byte) (banner string, out []byte) {
1462-
if bytes.HasPrefix(b, bannerPrefixBytes) {
1463-
b = b[len(bannerPrefixBytes):]
1464-
nl := bytes.IndexByte(b, '\n')
1465-
if nl != -1 {
1466-
banner = string(b[:nl])
1467-
b = b[nl+1:]
1468-
}
1463+
// parseOutputAndHeader parses b and returns the test display header (e.g.,
1464+
// "##### Testing packages.") and the following output.
1465+
func parseOutputAndHeader(b []byte) (header string, out []byte) {
1466+
if !bytes.HasPrefix(b, bannerPrefixBytes) {
1467+
return "", b
1468+
}
1469+
1470+
b = b[1:] // skip newline
1471+
nl := bytes.IndexByte(b, '\n')
1472+
if nl == -1 {
1473+
header = string(b)
1474+
b = nil
1475+
} else {
1476+
header = string(b[:nl])
1477+
b = b[nl+1:]
14691478
}
1470-
return banner, b
1479+
// Replace internal marker banner with the human-friendly
1480+
// version.
1481+
header = strings.ReplaceAll(header, banner, outputBanner)
1482+
return header, b
14711483
}
14721484

14731485
// maxTestExecError is the number of test execution failures at which

cmd/coordinator/buildstatus_test.go

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,12 @@ import (
1212
"testing"
1313
)
1414

15-
// TestParseOutputAndBanner tests banner parsing by parseOutputAndBanner.
16-
func TestParseOutputAndBanner(t *testing.T) {
15+
// TestParseOutputAndHeader tests header parsing by parseOutputAndHeader.
16+
func TestParseOutputAndHeader(t *testing.T) {
1717
for _, tc := range []struct {
1818
name string
1919
input []byte
20-
wantBanner string
20+
wantHeader string
2121
wantOut []byte
2222
}{
2323
{
@@ -28,35 +28,34 @@ ok archive/tar 0.015s
2828
ok archive/zip 0.406s
2929
ok bufio 0.075s
3030
`),
31-
wantBanner: "Testing packages.",
31+
wantHeader: "##### Testing packages.",
3232
wantOut: []byte(`ok archive/tar 0.015s
3333
ok archive/zip 0.406s
3434
ok bufio 0.075s
3535
`),
3636
},
3737
{
38-
name: "banner only",
38+
name: "header only",
3939
input: []byte(`
4040
XXXBANNERXXX:Testing packages.
4141
`),
42-
wantBanner: "Testing packages.",
42+
wantHeader: "##### Testing packages.",
4343
wantOut: []byte(``),
4444
},
4545
{
46-
// TODO(prattmic): This is likely not desirable behavior.
47-
name: "banner only missing trailing newline",
46+
name: "header only missing trailing newline",
4847
input: []byte(`
4948
XXXBANNERXXX:Testing packages.`),
50-
wantBanner: "",
51-
wantOut: []byte(`Testing packages.`),
49+
wantHeader: "##### Testing packages.",
50+
wantOut: []byte(``),
5251
},
5352
{
5453
name: "no banner",
5554
input: []byte(`ok archive/tar 0.015s
5655
ok archive/zip 0.406s
5756
ok bufio 0.075s
5857
`),
59-
wantBanner: "",
58+
wantHeader: "",
6059
wantOut: []byte(`ok archive/tar 0.015s
6160
ok archive/zip 0.406s
6261
ok bufio 0.075s
@@ -69,7 +68,7 @@ ok archive/tar 0.015s
6968
ok archive/zip 0.406s
7069
ok bufio 0.075s
7170
`),
72-
wantBanner: "",
71+
wantHeader: "",
7372
wantOut: []byte(`XXXBANNERXXX:Testing packages.
7473
ok archive/tar 0.015s
7574
ok archive/zip 0.406s
@@ -84,7 +83,7 @@ ok archive/tar 0.015s
8483
ok archive/zip 0.406s
8584
ok bufio 0.075s
8685
`),
87-
wantBanner: "",
86+
wantHeader: "",
8887
wantOut: []byte(`
8988
##### Testing packages.
9089
ok archive/tar 0.015s
@@ -94,9 +93,9 @@ ok bufio 0.075s
9493
},
9594
} {
9695
t.Run(tc.name, func(t *testing.T) {
97-
gotBanner, gotOut := parseOutputAndBanner(tc.input)
98-
if gotBanner != tc.wantBanner {
99-
t.Errorf("parseOutputAndBanner(%q) got banner %q want banner %q", string(tc.input), gotBanner, tc.wantBanner)
96+
gotHeader, gotOut := parseOutputAndHeader(tc.input)
97+
if gotHeader != tc.wantHeader {
98+
t.Errorf("parseOutputAndBanner(%q) got banner %q want banner %q", string(tc.input), gotHeader, tc.wantHeader)
10099
}
101100
if string(gotOut) != string(tc.wantOut) {
102101
t.Errorf("parseOutputAndBanner(%q) got out %q want out %q", string(tc.input), string(gotOut), string(tc.wantOut))

0 commit comments

Comments
 (0)