Skip to content

Commit

Permalink
Enable testing of compiled models in CI (#34111)
Browse files Browse the repository at this point in the history
* Mark tests as skipped instead of replacing with no-op

* Avoid most silent failures in `CompiledModelTestBase.AssertBaseline`
* Instead of considering the test passed if no check was done, mark it as failed.
* Additionally, handle paths mangled by DeterministicSourcePaths.

* Update baselines

* Instead of throwing the first exception, throw an aggregation of all of them.
  • Loading branch information
ranma42 authored Jul 2, 2024
1 parent 798fbc8 commit 3a49a80
Show file tree
Hide file tree
Showing 7 changed files with 90 additions and 81 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -146,13 +146,13 @@ public virtual Task Basic_cosmos_model()
Assert.Equal(new[] { id, partitionId, blob, storeId, jObject, eTag }, dataEntity.GetProperties());
});

// Primitive collections not supported yet
[ConditionalFact(Skip = "Primitive collections not supported yet")]
public override Task BigModel()
=> Task.CompletedTask;
=> base.BigModel();

// Primitive collections not supported yet
[ConditionalFact(Skip = "Primitive collections not supported yet")]
public override Task ComplexTypes()
=> Task.CompletedTask;
=> base.ComplexTypes();

protected override TestHelpers TestHelpers => CosmosTestHelpers.Instance;
protected override ITestStoreFactory TestStoreFactory => CosmosTestStoreFactory.Instance;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -494,9 +494,9 @@ protected virtual void AssertCyclesModel(IModel model)
TestHelpers.ModelAsserter.AssertEqual(principalBaseFk.PrincipalKey.Properties, dependentFk.Properties);
}

// Primitive collections not supported completely
[ConditionalFact(Skip = "Primitive collections not supported completely")]
public override Task BigModel()
=> Task.CompletedTask;
=> base.BigModel();

public class Scaffolding
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1465,7 +1465,8 @@ private IModel CompileModel(
{
var build = new BuildSource
{
Sources = scaffoldedFiles.ToDictionary(f => f.Path, f => f.Code), NullableReferenceTypes = options.UseNullableReferenceTypes
Sources = scaffoldedFiles.ToDictionary(f => f.Path, f => f.Code),
NullableReferenceTypes = options.UseNullableReferenceTypes
};
AddReferences(build);

Expand All @@ -1491,42 +1492,50 @@ private void AssertBaseline(
string testName)
{
var testDirectory = Path.GetDirectoryName(_filePath);
if (string.IsNullOrEmpty(testDirectory)
|| !Directory.Exists(testDirectory))
if (string.IsNullOrEmpty(testDirectory))
{
return;
return; // cannot look for the baseline
}

var baselinesDirectory = Path.Combine(testDirectory, "Baselines", testName);
try
var prefix = Path.DirectorySeparatorChar + "_" + Path.DirectorySeparatorChar;
if (testDirectory.StartsWith(prefix))
{
Directory.CreateDirectory(baselinesDirectory);
// assumes a current directory like /path/to/efcore/artifacts/bin/EFCore.Sqlite.FunctionalTests/Release/net9.0
// so that a path mangled by DeterministicSourcePaths such as /_/test/EFCore.Sqlite.FunctionalTests/Scaffolding becomes
// /path/to/efcore/test/EFCore.Sqlite.FunctionalTests/Scaffolding
testDirectory = string.Join(Path.DirectorySeparatorChar, Enumerable.Repeat("..", 5)) + testDirectory[2..];
}
catch
if (!Directory.Exists(testDirectory))
{
return;
throw new Exception($"Test directory '{testDirectory}' not found from '{Directory.GetCurrentDirectory()}'");
}

var baselinesDirectory = Path.Combine(testDirectory, "Baselines", testName);
Directory.CreateDirectory(baselinesDirectory);

var shouldRewrite = Environment.GetEnvironmentVariable("EF_TEST_REWRITE_BASELINES")?.ToUpper() is "1" or "TRUE";
List<Exception> exceptions = [];
foreach (var file in scaffoldedFiles)
{
var fullFilePath = Path.Combine(baselinesDirectory, file.Path);
if (!File.Exists(fullFilePath)
|| shouldRewrite)
try
{
File.WriteAllText(fullFilePath, file.Code);
Assert.Equal(File.ReadAllText(fullFilePath), file.Code, ignoreLineEndingDifferences: true);
}
else
catch (Exception ex)
{
try
{
Assert.Equal(File.ReadAllText(fullFilePath), file.Code, ignoreLineEndingDifferences: true);
}
catch (Exception ex)
if (shouldRewrite)
{
throw new Exception($"Difference found in {file.Path}", ex);
File.WriteAllText(fullFilePath, file.Code);
}

exceptions.Add(new Exception($"Difference found in {file.Path}", ex));
}
}

if (exceptions.Count > 0)
{
throw new AggregateException($"Differences found in {exceptions.Count} files", exceptions);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14933,11 +14933,11 @@ public static RuntimeEntityType Create(RuntimeModel model, RuntimeEntityType bas
storeGenerationIndex: -1);
nullableUri.TypeMapping = SqlServerStringTypeMapping.Default.Clone(
comparer: new ValueComparer<Uri>(
(Uri v1, Uri v2) => v1 == v2,
(Uri v1, Uri v2) => v1 == null && v2 == null || v1 != null && v2 != null && v1.Equals(v2),
(Uri v) => ((object)v).GetHashCode(),
(Uri v) => v),
keyComparer: new ValueComparer<Uri>(
(Uri v1, Uri v2) => v1 == v2,
(Uri v1, Uri v2) => v1 == null && v2 == null || v1 != null && v2 != null && v1.Equals(v2),
(Uri v) => ((object)v).GetHashCode(),
(Uri v) => v),
providerValueComparer: new ValueComparer<string>(
Expand Down Expand Up @@ -14988,11 +14988,11 @@ public static RuntimeEntityType Create(RuntimeModel model, RuntimeEntityType bas
storeGenerationIndex: -1);
nullableUriArray.TypeMapping = SqlServerStringTypeMapping.Default.Clone(
comparer: new ListOfReferenceTypesComparer<Uri[], Uri>(new ValueComparer<Uri>(
(Uri v1, Uri v2) => v1 == v2,
(Uri v1, Uri v2) => v1 == null && v2 == null || v1 != null && v2 != null && v1.Equals(v2),
(Uri v) => ((object)v).GetHashCode(),
(Uri v) => v)),
keyComparer: new ListOfReferenceTypesComparer<Uri[], Uri>(new ValueComparer<Uri>(
(Uri v1, Uri v2) => v1 == v2,
(Uri v1, Uri v2) => v1 == null && v2 == null || v1 != null && v2 != null && v1.Equals(v2),
(Uri v) => ((object)v).GetHashCode(),
(Uri v) => v)),
providerValueComparer: new ValueComparer<string>(
Expand All @@ -15018,11 +15018,11 @@ public static RuntimeEntityType Create(RuntimeModel model, RuntimeEntityType bas
(string v) => new Uri(v, UriKind.RelativeOrAbsolute)))),
elementMapping: SqlServerStringTypeMapping.Default.Clone(
comparer: new ValueComparer<Uri>(
(Uri v1, Uri v2) => v1 == v2,
(Uri v1, Uri v2) => v1 == null && v2 == null || v1 != null && v2 != null && v1.Equals(v2),
(Uri v) => ((object)v).GetHashCode(),
(Uri v) => v),
keyComparer: new ValueComparer<Uri>(
(Uri v1, Uri v2) => v1 == v2,
(Uri v1, Uri v2) => v1 == null && v2 == null || v1 != null && v2 != null && v1.Equals(v2),
(Uri v) => ((object)v).GetHashCode(),
(Uri v) => v),
providerValueComparer: new ValueComparer<string>(
Expand Down Expand Up @@ -17259,11 +17259,11 @@ public static RuntimeEntityType Create(RuntimeModel model, RuntimeEntityType bas
storeGenerationIndex: -1);
uri.TypeMapping = SqlServerStringTypeMapping.Default.Clone(
comparer: new ValueComparer<Uri>(
(Uri v1, Uri v2) => v1 == v2,
(Uri v1, Uri v2) => v1 == null && v2 == null || v1 != null && v2 != null && v1.Equals(v2),
(Uri v) => ((object)v).GetHashCode(),
(Uri v) => v),
keyComparer: new ValueComparer<Uri>(
(Uri v1, Uri v2) => v1 == v2,
(Uri v1, Uri v2) => v1 == null && v2 == null || v1 != null && v2 != null && v1.Equals(v2),
(Uri v) => ((object)v).GetHashCode(),
(Uri v) => v),
providerValueComparer: new ValueComparer<string>(
Expand Down Expand Up @@ -17314,11 +17314,11 @@ public static RuntimeEntityType Create(RuntimeModel model, RuntimeEntityType bas
storeGenerationIndex: -1);
uriArray.TypeMapping = SqlServerStringTypeMapping.Default.Clone(
comparer: new ListOfReferenceTypesComparer<Uri[], Uri>(new ValueComparer<Uri>(
(Uri v1, Uri v2) => v1 == v2,
(Uri v1, Uri v2) => v1 == null && v2 == null || v1 != null && v2 != null && v1.Equals(v2),
(Uri v) => ((object)v).GetHashCode(),
(Uri v) => v)),
keyComparer: new ListOfReferenceTypesComparer<Uri[], Uri>(new ValueComparer<Uri>(
(Uri v1, Uri v2) => v1 == v2,
(Uri v1, Uri v2) => v1 == null && v2 == null || v1 != null && v2 != null && v1.Equals(v2),
(Uri v) => ((object)v).GetHashCode(),
(Uri v) => v)),
providerValueComparer: new ValueComparer<string>(
Expand All @@ -17344,11 +17344,11 @@ public static RuntimeEntityType Create(RuntimeModel model, RuntimeEntityType bas
(string v) => new Uri(v, UriKind.RelativeOrAbsolute)))),
elementMapping: SqlServerStringTypeMapping.Default.Clone(
comparer: new ValueComparer<Uri>(
(Uri v1, Uri v2) => v1 == v2,
(Uri v1, Uri v2) => v1 == null && v2 == null || v1 != null && v2 != null && v1.Equals(v2),
(Uri v) => ((object)v).GetHashCode(),
(Uri v) => v),
keyComparer: new ValueComparer<Uri>(
(Uri v1, Uri v2) => v1 == v2,
(Uri v1, Uri v2) => v1 == null && v2 == null || v1 != null && v2 != null && v1.Equals(v2),
(Uri v) => ((object)v).GetHashCode(),
(Uri v) => v),
providerValueComparer: new ValueComparer<string>(
Expand Down Expand Up @@ -17400,11 +17400,11 @@ public static RuntimeEntityType Create(RuntimeModel model, RuntimeEntityType bas
storeGenerationIndex: -1);
uriToStringConverterProperty.TypeMapping = SqlServerStringTypeMapping.Default.Clone(
comparer: new ValueComparer<Uri>(
(Uri v1, Uri v2) => v1 == v2,
(Uri v1, Uri v2) => v1 == null && v2 == null || v1 != null && v2 != null && v1.Equals(v2),
(Uri v) => ((object)v).GetHashCode(),
(Uri v) => v),
keyComparer: new ValueComparer<Uri>(
(Uri v1, Uri v2) => v1 == v2,
(Uri v1, Uri v2) => v1 == null && v2 == null || v1 != null && v2 != null && v1.Equals(v2),
(Uri v) => ((object)v).GetHashCode(),
(Uri v) => v),
providerValueComparer: new ValueComparer<string>(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14933,11 +14933,11 @@ public static RuntimeEntityType Create(RuntimeModel model, RuntimeEntityType bas
storeGenerationIndex: -1);
nullableUri.TypeMapping = SqlServerStringTypeMapping.Default.Clone(
comparer: new ValueComparer<Uri>(
(Uri v1, Uri v2) => v1 == v2,
(Uri v1, Uri v2) => v1 == null && v2 == null || v1 != null && v2 != null && v1.Equals(v2),
(Uri v) => ((object)v).GetHashCode(),
(Uri v) => v),
keyComparer: new ValueComparer<Uri>(
(Uri v1, Uri v2) => v1 == v2,
(Uri v1, Uri v2) => v1 == null && v2 == null || v1 != null && v2 != null && v1.Equals(v2),
(Uri v) => ((object)v).GetHashCode(),
(Uri v) => v),
providerValueComparer: new ValueComparer<string>(
Expand Down Expand Up @@ -14988,11 +14988,11 @@ public static RuntimeEntityType Create(RuntimeModel model, RuntimeEntityType bas
storeGenerationIndex: -1);
nullableUriArray.TypeMapping = SqlServerStringTypeMapping.Default.Clone(
comparer: new ListOfReferenceTypesComparer<Uri[], Uri>(new ValueComparer<Uri>(
(Uri v1, Uri v2) => v1 == v2,
(Uri v1, Uri v2) => v1 == null && v2 == null || v1 != null && v2 != null && v1.Equals(v2),
(Uri v) => ((object)v).GetHashCode(),
(Uri v) => v)),
keyComparer: new ListOfReferenceTypesComparer<Uri[], Uri>(new ValueComparer<Uri>(
(Uri v1, Uri v2) => v1 == v2,
(Uri v1, Uri v2) => v1 == null && v2 == null || v1 != null && v2 != null && v1.Equals(v2),
(Uri v) => ((object)v).GetHashCode(),
(Uri v) => v)),
providerValueComparer: new ValueComparer<string>(
Expand All @@ -15018,11 +15018,11 @@ public static RuntimeEntityType Create(RuntimeModel model, RuntimeEntityType bas
(string v) => new Uri(v, UriKind.RelativeOrAbsolute)))),
elementMapping: SqlServerStringTypeMapping.Default.Clone(
comparer: new ValueComparer<Uri>(
(Uri v1, Uri v2) => v1 == v2,
(Uri v1, Uri v2) => v1 == null && v2 == null || v1 != null && v2 != null && v1.Equals(v2),
(Uri v) => ((object)v).GetHashCode(),
(Uri v) => v),
keyComparer: new ValueComparer<Uri>(
(Uri v1, Uri v2) => v1 == v2,
(Uri v1, Uri v2) => v1 == null && v2 == null || v1 != null && v2 != null && v1.Equals(v2),
(Uri v) => ((object)v).GetHashCode(),
(Uri v) => v),
providerValueComparer: new ValueComparer<string>(
Expand Down Expand Up @@ -17259,11 +17259,11 @@ public static RuntimeEntityType Create(RuntimeModel model, RuntimeEntityType bas
storeGenerationIndex: -1);
uri.TypeMapping = SqlServerStringTypeMapping.Default.Clone(
comparer: new ValueComparer<Uri>(
(Uri v1, Uri v2) => v1 == v2,
(Uri v1, Uri v2) => v1 == null && v2 == null || v1 != null && v2 != null && v1.Equals(v2),
(Uri v) => ((object)v).GetHashCode(),
(Uri v) => v),
keyComparer: new ValueComparer<Uri>(
(Uri v1, Uri v2) => v1 == v2,
(Uri v1, Uri v2) => v1 == null && v2 == null || v1 != null && v2 != null && v1.Equals(v2),
(Uri v) => ((object)v).GetHashCode(),
(Uri v) => v),
providerValueComparer: new ValueComparer<string>(
Expand Down Expand Up @@ -17314,11 +17314,11 @@ public static RuntimeEntityType Create(RuntimeModel model, RuntimeEntityType bas
storeGenerationIndex: -1);
uriArray.TypeMapping = SqlServerStringTypeMapping.Default.Clone(
comparer: new ListOfReferenceTypesComparer<Uri[], Uri>(new ValueComparer<Uri>(
(Uri v1, Uri v2) => v1 == v2,
(Uri v1, Uri v2) => v1 == null && v2 == null || v1 != null && v2 != null && v1.Equals(v2),
(Uri v) => ((object)v).GetHashCode(),
(Uri v) => v)),
keyComparer: new ListOfReferenceTypesComparer<Uri[], Uri>(new ValueComparer<Uri>(
(Uri v1, Uri v2) => v1 == v2,
(Uri v1, Uri v2) => v1 == null && v2 == null || v1 != null && v2 != null && v1.Equals(v2),
(Uri v) => ((object)v).GetHashCode(),
(Uri v) => v)),
providerValueComparer: new ValueComparer<string>(
Expand All @@ -17344,11 +17344,11 @@ public static RuntimeEntityType Create(RuntimeModel model, RuntimeEntityType bas
(string v) => new Uri(v, UriKind.RelativeOrAbsolute)))),
elementMapping: SqlServerStringTypeMapping.Default.Clone(
comparer: new ValueComparer<Uri>(
(Uri v1, Uri v2) => v1 == v2,
(Uri v1, Uri v2) => v1 == null && v2 == null || v1 != null && v2 != null && v1.Equals(v2),
(Uri v) => ((object)v).GetHashCode(),
(Uri v) => v),
keyComparer: new ValueComparer<Uri>(
(Uri v1, Uri v2) => v1 == v2,
(Uri v1, Uri v2) => v1 == null && v2 == null || v1 != null && v2 != null && v1.Equals(v2),
(Uri v) => ((object)v).GetHashCode(),
(Uri v) => v),
providerValueComparer: new ValueComparer<string>(
Expand Down Expand Up @@ -17400,11 +17400,11 @@ public static RuntimeEntityType Create(RuntimeModel model, RuntimeEntityType bas
storeGenerationIndex: -1);
uriToStringConverterProperty.TypeMapping = SqlServerStringTypeMapping.Default.Clone(
comparer: new ValueComparer<Uri>(
(Uri v1, Uri v2) => v1 == v2,
(Uri v1, Uri v2) => v1 == null && v2 == null || v1 != null && v2 != null && v1.Equals(v2),
(Uri v) => ((object)v).GetHashCode(),
(Uri v) => v),
keyComparer: new ValueComparer<Uri>(
(Uri v1, Uri v2) => v1 == v2,
(Uri v1, Uri v2) => v1 == null && v2 == null || v1 != null && v2 != null && v1.Equals(v2),
(Uri v) => ((object)v).GetHashCode(),
(Uri v) => v),
providerValueComparer: new ValueComparer<string>(
Expand Down
Loading

0 comments on commit 3a49a80

Please sign in to comment.