Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add logging for failing tests in CI #14821

Merged
merged 1 commit into from
Dec 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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))
}
}
}
Loading