Skip to content
Merged
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
38 changes: 36 additions & 2 deletions acceptance/acceptance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,25 @@ const (
ReplsEnvVar = "ACC_REPLS"
)

var ApplyCITimeoutMultipler = os.Getenv("GITHUB_WORKFLOW") != ""
var IsRunningOnCI = os.Getenv("GITHUB_WORKFLOW") != ""

// MaxLogLines caps how many lines of each LOG.* file the harness echoes into the test
// log. Some invariant tests write very large LOG.planjson files that otherwise drown out
// the rest of the logs and overflow log viewers. Override with DATABRICKS_CLI_TEST_MAX_LOG;
// a value <= 0 disables the limit.
var MaxLogLines = func() int {
if v := os.Getenv("DATABRICKS_CLI_TEST_MAX_LOG"); v != "" {
n, err := strconv.Atoi(v)
if err != nil {
panic("invalid DATABRICKS_CLI_TEST_MAX_LOG=" + v + ": " + err.Error())
}
return n
}
if IsRunningOnCI {
return 100
}
return 1000
}()

var exeSuffix = func() string {
if runtime.GOOS == "windows" {
Expand Down Expand Up @@ -862,7 +880,7 @@ func runTest(t *testing.T,
timeout = max(timeout, config.TimeoutCloud)
}

if ApplyCITimeoutMultipler {
if IsRunningOnCI {
timeout = time.Duration(float64(timeout) * config.TimeoutCIMultiplier)
}

Expand Down Expand Up @@ -1048,6 +1066,7 @@ func runTest(t *testing.T,
prefix := relPath + ": "
messages := testutil.ReadFile(t, filepath.Join(tmpDir, relPath))
messages = strings.TrimRight(messages, "\r\n \t")
messages = truncateLines(messages, MaxLogLines)
messages = prefix + strings.ReplaceAll(messages, "\n", "\n"+prefix)
if strings.Contains(messages, "\n") {
messages = "\n" + messages
Expand All @@ -1068,6 +1087,21 @@ func runTest(t *testing.T,
}
}

// truncateLines keeps at most maxLines lines of s, appending a note about how many were
// dropped. maxLines <= 0 disables truncation.
func truncateLines(s string, maxLines int) string {
if maxLines <= 0 {
return s
}
lines := strings.Split(s, "\n")
if len(lines) <= maxLines {
return s
}
dropped := len(lines) - maxLines
kept := strings.Join(lines[:maxLines], "\n")
return fmt.Sprintf("%s\n... (%d more lines truncated, raise DATABRICKS_CLI_TEST_MAX_LOG to see more)", kept, dropped)
}

// checkEnvFilters skips the test if any env filter doesn't match testEnv. Filters that
// share a key are alternatives, so INPUT_CONFIG=a together with INPUT_CONFIG=b runs both
// variants rather than neither (see selection.MatchesFilters).
Expand Down
Loading