From 70f92bc038f243af13a594089a3302ac5c48661e Mon Sep 17 00:00:00 2001 From: Seebs Date: Mon, 27 Feb 2023 13:10:17 -0600 Subject: [PATCH] actually yield checksums to caller While fixing a bug that log messages were ending up in the output buffer for backups, we fixed up a bunch of things to do with log messages and output for various commands. Due to a subtle oversight, this means that since we did that, executor_test's `chkSumCluster` has been dutifully printing `hash:blahblahblah` to os.Stdout, and returning an empty string. This also, indirectly, fixes a very strange behavior we've had ever since then, which is that a lot of test output silently disappears. The reason is probably, although I haven't found the right code path, that we were ending up closing os.Stdout. --- cmd/chksum.go | 4 +++- ctl/chksum.go | 5 ++--- ctl/chksum_test.go | 3 +-- executor_test.go | 9 +++++---- 4 files changed, 11 insertions(+), 10 deletions(-) diff --git a/cmd/chksum.go b/cmd/chksum.go index 01306f9f7..4160114f4 100644 --- a/cmd/chksum.go +++ b/cmd/chksum.go @@ -3,13 +3,15 @@ package cmd import ( + "os" + "github.com/featurebasedb/featurebase/v3/ctl" "github.com/featurebasedb/featurebase/v3/logger" "github.com/spf13/cobra" ) func newChkSumCommand(logdest logger.Logger) *cobra.Command { - cmd := ctl.NewChkSumCommand(logdest) + cmd := ctl.NewChkSumCommand(logdest, os.Stdout) ccmd := &cobra.Command{ Use: "chksum", Short: "Digital signature of FeatureBase data", diff --git a/ctl/chksum.go b/ctl/chksum.go index 643a9fca0..6dc67e5c8 100644 --- a/ctl/chksum.go +++ b/ctl/chksum.go @@ -7,7 +7,6 @@ import ( "crypto/tls" "fmt" "io" - "os" "github.com/cespare/xxhash" pilosa "github.com/featurebasedb/featurebase/v3" @@ -38,9 +37,9 @@ func (cmd *ChkSumCommand) Logger() logger.Logger { } // NewChkSumCommand returns a new instance of BackupCommand. -func NewChkSumCommand(logdest logger.Logger) *ChkSumCommand { +func NewChkSumCommand(logdest logger.Logger, stdout io.Writer) *ChkSumCommand { return &ChkSumCommand{ - stdout: os.Stdout, + stdout: stdout, logDest: logdest, } } diff --git a/ctl/chksum_test.go b/ctl/chksum_test.go index f4b7e9236..994f558b3 100644 --- a/ctl/chksum_test.go +++ b/ctl/chksum_test.go @@ -13,9 +13,8 @@ import ( func TestChkSumCommand_Run(t *testing.T) { cmLog := logger.NewStandardLogger(os.Stderr) - cm := NewChkSumCommand(cmLog) buf := &bytes.Buffer{} - cm.stdout = buf + cm := NewChkSumCommand(cmLog, buf) cluster := test.MustRunCluster(t, 1) defer cluster.Close() diff --git a/executor_test.go b/executor_test.go index ee3f8d979..309d5baa7 100644 --- a/executor_test.go +++ b/executor_test.go @@ -7447,15 +7447,16 @@ func backupTarTest(t *testing.T, c *test.Cluster, index string) { func chkSumCluster(t *testing.T, c *test.Cluster) string { t.Helper() - buf := &bytes.Buffer{} - chkSumLog := logger.NewStandardLogger(buf) - chkSum := ctl.NewChkSumCommand(chkSumLog) + errBuf := &bytes.Buffer{} + outBuf := &bytes.Buffer{} + chkSumLog := logger.NewStandardLogger(errBuf) + chkSum := ctl.NewChkSumCommand(chkSumLog, outBuf) chkSum.Host = c.Nodes[len(c.Nodes)-1].URL() if err := chkSum.Run(context.Background()); err != nil { t.Fatalf("running checksum: %v", err) } - return buf.String() + return outBuf.String() } func backupCluster(t *testing.T, c *test.Cluster, index string) (backupDir string) {