Skip to content

Commit

Permalink
roachtest/mixed-versions-compat: use corpus for master
Browse files Browse the repository at this point in the history
Fixes: #91350

The CI build scripts take advantage of the branch name
to uplaod the corpus to GCS. Unfortunately, we have
no way of know if the current build is master inside
the roachtest. To address this, this patch supports
fetching the master corpus as a fallback.

Release note: None
  • Loading branch information
fqazi committed Jan 20, 2023
1 parent f27fa9d commit 137e0c0
Showing 1 changed file with 35 additions and 16 deletions.
51 changes: 35 additions & 16 deletions pkg/cmd/roachtest/tests/mixed_version_decl_schemachange_compat.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,11 @@ func registerDeclSchemaChangeCompatMixedVersions(r registry.Registry) {

// fetchCorpusToTmp fetches corpus for a given version to tmp
func fetchCorpusToTmpDir(
ctx context.Context, t test.Test, c cluster.Cluster, versionNumber string,
ctx context.Context,
t test.Test,
c cluster.Cluster,
versionNumber string,
alternateVersion string,
) (corpusFilePath string, cleanupFn func()) {
tmpDir, err := os.MkdirTemp("", "corpus")
if err != nil {
Expand All @@ -55,15 +59,29 @@ func fetchCorpusToTmpDir(
t.L().Printf("failed to clean up tmp directory %v", err)
}
}
err = c.RunE(ctx, c.Node(1),
fmt.Sprintf(" gsutil cp gs://cockroach-corpus/corpus-%s/corpus %s",
versionNumber,
corpusFilePath))
versionsToCheck := []string{versionNumber}
if len(alternateVersion) > 0 {
versionsToCheck = []string{versionNumber, alternateVersion}
}
for i, version := range versionsToCheck {
err = c.RunE(ctx, c.Node(1),
fmt.Sprintf(" gsutil cp gs://cockroach-corpus/corpus-%s/corpus %s",
version,
corpusFilePath))
if err != nil && i != len(versionsToCheck)-1 {
t.L().Printf("Failed to fetch corpus %s with error %v, trying the next one",
version,
err)
}
if err == nil {
t.L().Printf("Fetched validation corpus for %v", version)
break
}
}
if err != nil {
cleanupFn()
t.Fatalf("Missing validation corpus for %v (%v)", versionNumber, err)
}
t.L().Printf("Fetched validation corpus for %v", versionNumber)
return corpusFilePath, cleanupFn
}

Expand Down Expand Up @@ -117,19 +135,20 @@ func runDeclSchemaChangeCompatMixedVersions(
t.Fatal(err)
}
// Test definitions which indicates which version of the corpus to fetch,
// and the bianry to validate against.
// and the binary to validate against.
compatTests := []struct {
testName string
binaryVersion string
corpusVersion string
testName string
binaryVersion string
corpusVersion string
alternateCorpusVersion string
}{
{"backwards compatibility", predecessorVersion, fmt.Sprintf("mixed-release-%d.%d", buildVersion.Major(), buildVersion.Minor())},
{"forwards compatibility", "", fmt.Sprintf("release-%s", versionRegex.FindStringSubmatch(predecessorVersion)[0])},
{"same version", "", fmt.Sprintf("release-%s", versionRegex.FindStringSubmatch(buildVersion.String())[0])},
{"backwards compatibility", predecessorVersion, fmt.Sprintf("mixed-release-%d.%d", buildVersion.Major(), buildVersion.Minor()), "mixed-master"},
{"forwards compatibility", "", fmt.Sprintf("release-%s", versionRegex.FindStringSubmatch(predecessorVersion)[0]), ""},
{"same version", "", fmt.Sprintf("release-%s", versionRegex.FindStringSubmatch(buildVersion.String())[0]), "master"},
}
for _, test := range compatTests {
binaryName := uploadVersion(ctx, t, c, c.All(), test.binaryVersion)
corpusPath, cleanupFn := fetchCorpusToTmpDir(ctx, t, c, test.corpusVersion)
for _, testInfo := range compatTests {
binaryName := uploadVersion(ctx, t, c, c.All(), testInfo.binaryVersion)
corpusPath, cleanupFn := fetchCorpusToTmpDir(ctx, t, c, testInfo.corpusVersion, testInfo.alternateCorpusVersion)
func() {
defer cleanupFn()
validateCorpusFile(ctx, t, c, binaryName, corpusPath)
Expand Down

0 comments on commit 137e0c0

Please sign in to comment.