Skip to content

Commit

Permalink
aetest: Redirect stderr to be visible to the user (#208)
Browse files Browse the repository at this point in the history
Previously, all stderr after the admin/API server lines was lost as the
StderrPipe continued to consume it without redirecting once the scanner
went out of scope. It also had the side effect of hanging a program in
which the devserver emitted too much data to stderr, since the pipe
would block once it reached cap.

This replaces the TeeReader (which would go out of scope before stderr
was done) by printing the output while processing and copying it once
processing finishes.
  • Loading branch information
roffjulie committed Aug 28, 2019
1 parent fb139bd commit 5f2a595
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions aetest/instance_vm.go
Expand Up @@ -215,9 +215,7 @@ func (i *instance) startChild() (err error) {
if err != nil {
return err
}
if !(i.opts != nil && i.opts.SuppressDevAppServerLog) {
stderr = io.TeeReader(stderr, os.Stderr)
}

if err = i.child.Start(); err != nil {
return err
}
Expand All @@ -227,6 +225,10 @@ func (i *instance) startChild() (err error) {
go func() {
s := bufio.NewScanner(stderr)
for s.Scan() {
// Pass stderr along as we go so the user can see it.
if !(i.opts != nil && i.opts.SuppressDevAppServerLog) {
fmt.Fprintln(os.Stderr, s.Text())
}
if match := apiServerAddrRE.FindStringSubmatch(s.Text()); match != nil {
u, err := url.Parse(match[1])
if err != nil {
Expand All @@ -239,6 +241,10 @@ func (i *instance) startChild() (err error) {
i.adminURL = match[1]
}
if i.adminURL != "" && i.apiURL != nil {
// Pass along stderr to the user after we're done with it.
if !(i.opts != nil && i.opts.SuppressDevAppServerLog) {
go io.Copy(os.Stderr, stderr)
}
break
}
}
Expand Down

0 comments on commit 5f2a595

Please sign in to comment.