Skip to content

Commit

Permalink
Skip versions newer than version under test for upgrade tests (#3169)
Browse files Browse the repository at this point in the history
## What does this PR do?

This PR filters out versions that too new from agent upgrade integration
tests, allowing backport of those test on release branches.

This PR needs to backported together with #2955 onto 8.9 branch

## Why is it important?

We want to have working upgrade tests with relevant versions also on
release branches

(cherry picked from commit 3de585e)

# Conflicts:
#	testing/integration/upgrade_test.go
  • Loading branch information
pchila authored and mergify[bot] committed Aug 3, 2023
1 parent d1a7b29 commit 949b833
Showing 1 changed file with 96 additions and 0 deletions.
96 changes: 96 additions & 0 deletions testing/integration/upgrade_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,103 @@ func TestStandaloneUpgrade(t *testing.T) {
buildFragments[1],
)

<<<<<<< HEAD
t.Logf("Upgrading to version %q", upgradeInputVersion)
=======
t.Logf("Targeting upgrade to version %+v", upgradeInputVersion)
parsedFromVersion, err := version.ParseVersion(define.Version())
require.NoErrorf(t, err, "define.Version() %q cannot be parsed as agent version", define.Version())
testStandaloneUpgrade(ctx, t, agentFixture, parsedFromVersion, upgradeInputVersion, expectedAgentHashAfterUpgrade, false)

}

func getUpgradableVersions(ctx context.Context, t *testing.T, upgradeToVersion string) (upgradableVersions []*version.ParsedSemVer) {
t.Helper()

const currentMajorVersions = 2
const previousMajorVersions = 1

aac := tools.NewArtifactAPIClient()
vList, err := aac.GetVersions(ctx)
require.NoError(t, err, "error retrieving versions from Artifact API")
require.NotEmpty(t, vList)

parsedUpgradeToVersion, err := version.ParseVersion(upgradeToVersion)
require.NoErrorf(t, err, "upgradeToVersion %q is not a valid version string", upgradeToVersion)
currentMajor := parsedUpgradeToVersion.Major()
var currentMajorSelected, previousMajorSelected int

sortedParsedVersions := make(version.SortableParsedVersions, 0, len(vList.Versions))
for _, v := range vList.Versions {
pv, err := version.ParseVersion(v)
require.NoErrorf(t, err, "invalid version retrieved from artifact API: %q", v)
sortedParsedVersions = append(sortedParsedVersions, pv)
}

require.NotEmpty(t, sortedParsedVersions)

// normally the output of the versions returned by artifact API is already sorted in ascending order,
// we want to sort in descending orders, so we sort them
sort.Sort(sort.Reverse(sortedParsedVersions))

for _, parsedVersion := range sortedParsedVersions {
if currentMajorSelected == currentMajorVersions && previousMajorSelected == previousMajorVersions {
// we got all the versions we need, break the loop
break
}

if !parsedVersion.Less(*parsedUpgradeToVersion) {
// skip upgrade from newer versions than the one under test
t.Logf("Skipping version %q since it's newer or equal to version after upgrade %q", parsedVersion, parsedUpgradeToVersion)
continue
}

if parsedVersion.IsSnapshot() {
// skip all snapshots
continue
}

if parsedVersion.Major() == currentMajor && currentMajorSelected < currentMajorVersions {
upgradableVersions = append(upgradableVersions, parsedVersion)
currentMajorSelected++
continue
}

if parsedVersion.Major() < currentMajor && previousMajorSelected < previousMajorVersions {
upgradableVersions = append(upgradableVersions, parsedVersion)
previousMajorSelected++
continue
}

}
return
}

func testStandaloneUpgrade(
ctx context.Context,
t *testing.T,
f *atesting.Fixture,
parsedFromVersion *version.ParsedSemVer,
parsedUpgradeVersion *version.ParsedSemVer,
expectedAgentHashAfterUpgrade string,
allowLocalPackage bool,
) {

var nonInteractiveFlag bool
if version_8_2_0.Less(*parsedFromVersion) {
nonInteractiveFlag = true
}
installOpts := atesting.InstallOpts{
NonInteractive: nonInteractiveFlag,
Force: true,
}

output, err := tools.InstallAgent(installOpts, f)
t.Logf("Agent installation output: %q", string(output))
require.NoError(t, err)

c := f.Client()
>>>>>>> 3de585e784 (Skip versions newer than version under test for upgrade tests (#3169))

err = c.Connect(ctx)
require.NoError(t, err, "error connecting client to agent")
Expand Down

0 comments on commit 949b833

Please sign in to comment.