Skip to content

Commit

Permalink
Add logging for failing tests in CI (#14821)
Browse files Browse the repository at this point in the history
Signed-off-by: Manan Gupta <[email protected]>
  • Loading branch information
GuptaManan100 authored Dec 20, 2023
1 parent 4200295 commit cfa2079
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 3 deletions.
13 changes: 10 additions & 3 deletions go/cmd/vttestserver/cli/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import (

"vitess.io/vitess/go/mysql"
"vitess.io/vitess/go/sqltypes"
"vitess.io/vitess/go/test/endtoend/cluster"
"vitess.io/vitess/go/vt/log"
"vitess.io/vitess/go/vt/logutil"
"vitess.io/vitess/go/vt/tlstest"
Expand Down Expand Up @@ -189,11 +190,17 @@ func TestCanGetKeyspaces(t *testing.T) {
conf := config
defer resetConfig(conf)

cluster, err := startCluster()
clusterInstance, err := startCluster()
assert.NoError(t, err)
defer cluster.TearDown()
defer clusterInstance.TearDown()

assertGetKeyspaces(t, cluster)
defer func() {
if t.Failed() {
cluster.PrintFiles(t, clusterInstance.Env.Directory(), "vtcombo.INFO", "error.log")
}
}()

assertGetKeyspaces(t, clusterInstance)
}

func TestExternalTopoServerConsul(t *testing.T) {
Expand Down
45 changes: 45 additions & 0 deletions go/test/endtoend/cluster/cluster_util.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import (
"google.golang.org/grpc"

"vitess.io/vitess/go/vt/grpcclient"
"vitess.io/vitess/go/vt/log"
"vitess.io/vitess/go/vt/vtgate/grpcvtgateconn"

"github.com/buger/jsonparser"
Expand Down Expand Up @@ -498,3 +499,47 @@ func DialVTGate(ctx context.Context, name, addr, username, password string) (*vt
vtgateconn.RegisterDialer(dialerName, dialerFunc)
return vtgateconn.DialProtocol(ctx, dialerName, addr)
}

// PrintFiles prints the files that are asked for. If no file is specified, all the files are printed.
func PrintFiles(t *testing.T, dir string, files ...string) {
var directories []string
directories = append(directories, dir)

// Go over the remaining directories to check
for len(directories) > 0 {
// Get one of the directories, and read its contents.
dir = directories[0]
directories = directories[1:]
entries, err := os.ReadDir(dir)
if err != nil {
log.Errorf("Couldn't read directory - %v", dir)
continue
}
for _, entry := range entries {
name := path.Join(dir, entry.Name())
// For a directory, we add it to our list of directories to check.
if entry.IsDir() {
directories = append(directories, name)
continue
}
// Check if this file should be printed or not.
if len(files) != 0 {
fileFound := false
for _, file := range files {
if strings.EqualFold(entry.Name(), file) {
fileFound = true
break
}
}
if !fileFound {
continue
}
}
// Read and print the file.
res, err := os.ReadFile(name)
require.NoError(t, err)
log.Errorf("READING FILE - %v", name)
log.Errorf("%v", string(res))
}
}
}

0 comments on commit cfa2079

Please sign in to comment.