Skip to content

Commit b903b53

Browse files
cpugopherbot
authored andcommitted
acme: capture pebble test subprocess stdout/stderr
When spawning the pebble and pebble-challtestserv processes redirect stdout/stderr to bytes.Buffer instances and print their content at test end as appropriate. The stdout/stderr content for each process is printed if the test failed, or if testing is being done in verbose mode. Otherwise the output is swallowed. This makes debugging test failures much easier as output from the subprocesses from independent tests isn't intermingled. Updates golang/go#74437 Cq-Include-Trybots: luci.golang.try:x_crypto-gotip-linux-amd64-longtest Change-Id: Ia79a3609ce3522ef6248442de247554c39367162 Reviewed-on: https://go-review.googlesource.com/c/crypto/+/686935 Auto-Submit: Daniel McCarney <[email protected]> Reviewed-by: Roland Shoemaker <[email protected]> Reviewed-by: Carlos Amedee <[email protected]> LUCI-TryBot-Result: Go LUCI <[email protected]>
1 parent 459a9db commit b903b53

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

acme/pebble_test.go

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -776,14 +776,28 @@ func prepareBinaries(t *testing.T, pebbleDir string) string {
776776
func spawnServerProcess(t *testing.T, dir string, cmd string, args ...string) {
777777
t.Helper()
778778

779+
var stdout, stderr bytes.Buffer
780+
779781
cmdInstance := exec.Command("./"+cmd, args...)
780782
cmdInstance.Dir = dir
781-
cmdInstance.Stdout = os.Stdout
782-
cmdInstance.Stderr = os.Stderr
783+
cmdInstance.Stdout = &stdout
784+
cmdInstance.Stderr = &stderr
785+
783786
if err := cmdInstance.Start(); err != nil {
784787
t.Fatalf("failed to start %s: %v", cmd, err)
785788
}
789+
786790
t.Cleanup(func() {
787791
cmdInstance.Process.Kill()
792+
793+
if t.Failed() || testing.Verbose() {
794+
t.Logf("=== %s output ===", cmd)
795+
if stdout.Len() > 0 {
796+
t.Logf("stdout:\n%s", strings.TrimSpace(stdout.String()))
797+
}
798+
if stderr.Len() > 0 {
799+
t.Logf("stderr:\n%s", strings.TrimSpace(stderr.String()))
800+
}
801+
}
788802
})
789803
}

0 commit comments

Comments
 (0)