From e0f0d10672db2d1a9786df294dbaac8b1c97f6e4 Mon Sep 17 00:00:00 2001 From: Christine Dodrill Date: Wed, 16 Jun 2021 14:57:11 -0400 Subject: [PATCH] tstest/integration/vms: log to t.Logf directly (#2147) Previously we used t.Logf indirectly via package log. This worked, but it was not ideal for our needs. It could cause the streams of output to get crossed. This change uses a logger.FuncWriter every place log.Output was previously used, which will more correctly write log information to the right test output stream. Signed-off-by: Christine Dodrill --- tstest/integration/vms/vms_test.go | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/tstest/integration/vms/vms_test.go b/tstest/integration/vms/vms_test.go index 1a7664035..69e38b697 100644 --- a/tstest/integration/vms/vms_test.go +++ b/tstest/integration/vms/vms_test.go @@ -43,6 +43,7 @@ import ( "tailscale.com/tstest" "tailscale.com/tstest/integration" "tailscale.com/tstest/integration/testcontrol" + "tailscale.com/types/logger" ) const ( @@ -299,8 +300,8 @@ func run(t *testing.T, dir, prog string, args ...string) { tstest.FixLogs(t) cmd := exec.Command(prog, args...) - cmd.Stdout = log.Writer() - cmd.Stderr = log.Writer() + cmd.Stdout = logger.FuncWriter(t.Logf) + cmd.Stderr = logger.FuncWriter(t.Logf) cmd.Dir = dir if err := cmd.Run(); err != nil { t.Fatal(err) @@ -444,8 +445,8 @@ func mkVM(t *testing.T, n int, d Distro, sshKey, hostURL, tdir string) func() { t.Logf("running: qemu-system-x86_64 %s", strings.Join(args, " ")) cmd := exec.Command("qemu-system-x86_64", args...) - cmd.Stdout = log.Writer() - cmd.Stderr = log.Writer() + cmd.Stdout = logger.FuncWriter(t.Logf) + cmd.Stderr = logger.FuncWriter(t.Logf) err = cmd.Start() if err != nil { @@ -557,9 +558,6 @@ func TestVMIntegrationEndToEnd(t *testing.T) { loginServer := fmt.Sprintf("http://%s", ln.Addr()) t.Logf("loginServer: %s", loginServer) - tstest.FixLogs(t) - defer tstest.UnfixLogs(t) - ramsem := semaphore.NewWeighted(int64(*vmRamLimit)) bins := integration.BuildTestBinaries(t) @@ -651,11 +649,11 @@ func testDistro(t *testing.T, loginServer string, d Distro, signer ssh.Signer, i e, _, err := expect.SpawnSSH(cli, timeout, expect.Verbose(true), - expect.VerboseWriter(log.Writer()), + expect.VerboseWriter(logger.FuncWriter(t.Logf)), // // NOTE(Xe): if you get a timeout, uncomment this line to have the raw // output be sent to the test log quicker. - //expect.Tee(nopWriteCloser{log.Writer()}), + //expect.Tee(nopWriteCloser{logger.FuncWriter(t.Logf)}), ) if err != nil { t.Fatalf("%d: can't register a shell session: %v", port, err)