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.
This commit is contained in:
Seebs 2023-02-27 13:10:17 -06:00 committed by seebs
parent 841ef32545
commit 70f92bc038
4 changed files with 11 additions and 10 deletions

View file

@ -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",

View file

@ -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,
}
}

View file

@ -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()

View file

@ -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) {