Skip to content
Draft
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
23 changes: 18 additions & 5 deletions pkg/cmd/roachtest/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"math/rand"
"os"
"os/user"
"path/filepath"
"regexp"
"strings"
"time"
Expand All @@ -25,6 +26,7 @@ import (
"github.com/cockroachdb/cockroach/pkg/cmd/roachtest/testselector"
"github.com/cockroachdb/cockroach/pkg/roachprod"
"github.com/cockroachdb/cockroach/pkg/roachprod/config"
"github.com/cockroachdb/cockroach/pkg/roachprod/logger"
"github.com/cockroachdb/cockroach/pkg/util/randutil"
"github.com/cockroachdb/errors"
_ "github.com/lib/pq" // register postgres driver
Expand Down Expand Up @@ -310,9 +312,12 @@ func testsToRun(
// the test categorization must be complete in 30 seconds
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
defer cancel()
updateSpecForSelectiveTests(ctx, specs, func(format string, args ...interface{}) {
err := updateSpecForSelectiveTests(ctx, specs, func(format string, args ...interface{}) {
fmt.Fprintf(os.Stdout, format, args...)
})
if err != nil {
return nil, err
}
}

var notSkipped []registry.TestSpec
Expand Down Expand Up @@ -377,13 +382,20 @@ func testsToRun(
// 5. All tests that are marked "selected=true" are considered for the test run.
func updateSpecForSelectiveTests(
ctx context.Context, specs []registry.TestSpec, logFunc func(format string, args ...interface{}),
) {
) error {
logPath := filepath.Join(roachtestflags.ArtifactsDir, "selector.log")
selectorLogger, err := logger.RootLogger(logPath, logger.NoTee)
if err != nil {
return err
}
defer selectorLogger.Close()
selectorLogger.Printf("This is the test selector logger")

selectedTestsCount := 0
allTests, err := testselector.CategoriseTests(ctx,
allTests, err := testselector.CategoriseTests(ctx, selectorLogger,
testselector.NewDefaultSelectTestsReq(roachtestflags.Cloud, roachtestflags.Suite))
if err != nil {
logFunc("running all tests! error selecting tests: %v\n", err)
return
return errors.Wrap(err, "running all tests! error selecting tests")
}

// successfulTests are the tests considered by snowflake to not run, but, part of the testSpecs.
Expand Down Expand Up @@ -436,6 +448,7 @@ func updateSpecForSelectiveTests(
}
}
logFunc("%d out of %d tests selected for the run!\n", selectedTestsCount, len(specs))
return nil
}

// testShouldBeSkipped decides whether a test should be skipped based on test details and suite
Expand Down
1 change: 1 addition & 0 deletions pkg/cmd/roachtest/testselector/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ go_library(
visibility = ["//visibility:public"],
deps = [
"//pkg/cmd/roachtest/spec",
"//pkg/roachprod/logger",
"@com_github_snowflakedb_gosnowflake//:gosnowflake",
],
)
Expand Down
36 changes: 31 additions & 5 deletions pkg/cmd/roachtest/testselector/selector.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (
"strconv"

"github.com/cockroachdb/cockroach/pkg/cmd/roachtest/spec"
"github.com/cockroachdb/cockroach/pkg/roachprod/logger"
sf "github.com/snowflakedb/gosnowflake"
)

Expand Down Expand Up @@ -91,7 +92,27 @@ func NewDefaultSelectTestsReq(cloud spec.Cloud, suite string) *SelectTestsReq {
// 3. the test has not been run for a while
// It returns all the tests. The selected tests have the value TestDetails.Selected as true
// The tests are sorted by the last run and is used for further test selection criteria. So, the order should not be modified.
func CategoriseTests(ctx context.Context, req *SelectTestsReq) ([]*TestDetails, error) {
func CategoriseTests(
ctx context.Context, logger *logger.Logger, req *SelectTestsReq,
) ([]*TestDetails, error) {
currentBranch := os.Getenv("TC_BUILD_BRANCH")
if currentBranch == "" {
currentBranch = "master"
}

// Can't do this because the literal `%V exists in the query bc `like `%VMs ....``
//debugQuery := strings.ReplaceAll(PreparedQuery, "?", "%v")
//logger.Printf(debugQuery)
//logger.Printf(debugQuery, req.ForPastDays*-1, currentBranch,
// fmt.Sprintf("%%%s - %s%%", suites[req.Suite], req.Cloud),
// req.FirstRunOn*-1, req.LastRunOn*-1)

// Print Query & Query Params

logger.Printf("Query Params:\n%d\n%s\n%s\n%d\n%d", req.ForPastDays*-1, currentBranch,
fmt.Sprintf("%%%s - %s%%", suites[req.Suite], req.Cloud),
req.FirstRunOn*-1, req.LastRunOn*-1)

db, err := getConnect(ctx)
if err != nil {
return nil, err
Expand All @@ -103,10 +124,10 @@ func CategoriseTests(ctx context.Context, req *SelectTestsReq) ([]*TestDetails,
}
defer func() { _ = statement.Close() }()
// get the current branch from the teamcity environment
currentBranch := os.Getenv("TC_BUILD_BRANCH")
if currentBranch == "" {
currentBranch = "master"
}
//currentBranch := os.Getenv("TC_BUILD_BRANCH")
//if currentBranch == "" {
// currentBranch = "master"
//}
// add the parameters in sequence
rows, err := statement.QueryContext(ctx, req.ForPastDays*-1, currentBranch,
fmt.Sprintf("%%%s - %s%%", suites[req.Suite], req.Cloud),
Expand All @@ -115,6 +136,11 @@ func CategoriseTests(ctx context.Context, req *SelectTestsReq) ([]*TestDetails,
return nil, err
}
defer func() { _ = rows.Close() }()
//debugQuery := strings.ReplaceAll(PreparedQuery, "?", "%v")
//logger.Printf(debugQuery, req.ForPastDays*-1, currentBranch,
// fmt.Sprintf("%%%s - %s%%", suites[req.Suite], req.Cloud),
// req.FirstRunOn*-1, req.LastRunOn*-1)

// All the column headers
colHeaders, err := rows.Columns()
if err != nil {
Expand Down
Loading