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 failing test for bug in GetLatestMaskedVersion #77

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
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
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
<NeutralLanguage>en-US</NeutralLanguage>
<Copyright>Copyright © Octopus Deploy 2017</Copyright>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
<!-- nuget packages with security warnings should not break the build -->
<WarningsNotAsErrors>CS0618,NU1901,NU1902,NU1903</WarningsNotAsErrors>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\Octopus.Versioning\Octopus.Versioning.csproj" />
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.Linq;
using NUnit.Framework;
using Octopus.Versioning.Octopus;
using Octopus.Versioning.Semver;
Expand Down Expand Up @@ -220,5 +221,34 @@ public void GetLatestVersionMask(string version, string latestVersion, string ex
Assert.AreEqual(expected, latestMaskedVersionNewImplementationPrefix?.ToString());
}
}

[Test]
public void GetLatestMaskedVersionShouldNotBeOrderDependent()
{
var mask = OctopusVersionMaskParser.Parse("0.0.7+branchA.c.c.i");
var versionParser = new OctopusVersionParser();

var versions = new[]
{
"0.0.7+branchA.1",
"0.0.7+branchA",
"0.0.6+branchA",
"0.0.5-beta.2",
"0.0.5-beta.1",
"0.0.4-beta",
"0.0.3",
"0.0.1",
"0.0.2"
}.Select(v => (IVersion)versionParser.Parse(v))
.ToList();

// This is the correct answer that we are looking for
Assert.AreEqual("0.0.7+branchA.1", mask.GetLatestMaskedVersion(versions)!.ToString());

// Now the real test; it should still return the same result even if the versions are not in the correct order
var reversedVersions = versions.ToList();
reversedVersions.Reverse();
Assert.AreEqual("0.0.7+branchA.1", mask.GetLatestMaskedVersion(reversedVersions)!.ToString());
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This currently returns 0.0.7+branchA instead of A.1

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The Semver spec says that version metadata (everything after +) shouldn't affect precedence:

Build metadata MUST be ignored when determining version precedence. Thus two versions that differ only in the build metadata, have the same precedence. Examples: 1.0.0-alpha+001, 1.0.0+20130313144700, 1.0.0-beta+exp.sha.5114f85, 1.0.0+21AF26D3----117B344092BD.

https://semver.org/#spec-item-10

Copy link
Contributor Author

@borland borland Feb 19, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Be that as it may, the side-effect of indeterminate precedence is that in Octopus, when it tries to do auto-deploy or other things the release it selects is nondeterministic where two builds with the same version but different metadata happens. It just picks whatever happens to come out of SQL server first which is not reliable from a customer perspective.

If we don't want deterministic ordering in our library here, then we'll need to make some compensating change for it in Octopus instead.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The problem here stems from OctopusVersionMask.CompareTo(object). We have tests here ensuring that version metadata doesn't affect versioning (OctopusVersionCompareTests.TestVersionComparisons(...)). I'm inclined to leave the tests as-is, and instead create a new GetLatestMaskedVersions method that returns all versions considered to be "latest". Then we can let Octopus decide how to handle that. What are your thoughts?

}
}
}
Loading