From 3059d04113a10af38bebbd195f832e31d818eacd Mon Sep 17 00:00:00 2001 From: Nikola Irinchev Date: Thu, 23 May 2024 00:10:05 +0200 Subject: [PATCH] Fix some tests --- .github/pkl-workflows/helpers/Lint.pkl | 4 +- .github/pkl-workflows/helpers/Steps.pkl | 2 +- .github/pkl-workflows/helpers/Test.pkl | 1 + .github/workflows/pr.yml | 20 +++--- .../Database/DynamicEmbeddedTests.cs | 10 +++ Tests/Realm.Tests/Database/MigrationTests.cs | 69 +++++++++---------- 6 files changed, 57 insertions(+), 49 deletions(-) diff --git a/.github/pkl-workflows/helpers/Lint.pkl b/.github/pkl-workflows/helpers/Lint.pkl index 4c5aaec21a..d897c121cb 100644 --- a/.github/pkl-workflows/helpers/Lint.pkl +++ b/.github/pkl-workflows/helpers/Lint.pkl @@ -4,13 +4,15 @@ import "../GithubAction/GithubAction.pkl" as gha import "Steps.pkl" import "Common.pkl" +const actionVerifyTODO = "nirinchev/verify-todo@ffa352ac028b4cdc8bc626471d33aa341b3ab7c9" + function lint(): gha.Job = new { name = "Verify TODOs" `runs-on` = new gha.UbuntuLatest{} steps { Steps.checkoutWithoutMatchers(false) new gha.Step { - uses = "nirinchev/verify-todo@9be6f76daddad71433e5deb1b58c517490e5c66e" + uses = actionVerifyTODO with { ["token"] = "${{ secrets.GITHUB_TOKEN }}" ["include"] = "**/*.+(cs|cpp|hpp)" diff --git a/.github/pkl-workflows/helpers/Steps.pkl b/.github/pkl-workflows/helpers/Steps.pkl index ce297a4e5a..018c75ad8f 100644 --- a/.github/pkl-workflows/helpers/Steps.pkl +++ b/.github/pkl-workflows/helpers/Steps.pkl @@ -9,7 +9,7 @@ const actionCheckout = "actions/checkout@v4" const actionUploadArtifact = "actions/upload-artifact@v4" const actionDownloadArtifact = "actions/download-artifact@v4" const actionSetupXcode = "maxim-lobanov/setup-xcode@60606e260d2fc5762a71e64e74b2174e8ea3c8bd" -const actionSetupDotnet = "actions/setup-dotnet@607fce577a46308457984d59e4954e075820f10a" +const actionSetupDotnet = "actions/setup-dotnet@5d1464d5da459f3d7085106d52e499f4dc5d0f59" const actionSetupMsBuild = "microsoft/setup-msbuild@0b44c6745b7e81956596964100aadb92d667c497" const function checkout(submodules: (Boolean | "recursive")): Listing = new Listing { diff --git a/.github/pkl-workflows/helpers/Test.pkl b/.github/pkl-workflows/helpers/Test.pkl index e4928a009e..095c93c755 100644 --- a/.github/pkl-workflows/helpers/Test.pkl +++ b/.github/pkl-workflows/helpers/Test.pkl @@ -24,6 +24,7 @@ function netFramework(_syncDifferentiators: Listing): gha.StepJobBase = properties { ["TargetFramework"] = "net461" } + standaloneExe = true }) new gha.Step { name = "Run the tests" diff --git a/.github/workflows/pr.yml b/.github/workflows/pr.yml index 32baef8787..276af729e5 100755 --- a/.github/workflows/pr.yml +++ b/.github/workflows/pr.yml @@ -43,7 +43,7 @@ jobs: run: |- echo "::add-matcher::.github/problem-matchers/csc.json" echo "::add-matcher::.github/problem-matchers/msvc.json" - - uses: actions/setup-dotnet@607fce577a46308457984d59e4954e075820f10a + - uses: actions/setup-dotnet@5d1464d5da459f3d7085106d52e499f4dc5d0f59 with: dotnet-version: 6.0.x - name: Deploy Apps @@ -111,7 +111,7 @@ jobs: if: ${{ runner.os == 'Windows' }} uses: microsoft/setup-msbuild@0b44c6745b7e81956596964100aadb92d667c497 - name: Build Tests/Realm.Tests - run: msbuild Tests/Realm.Tests -restore -p:Configuration=Release -p:TargetFramework=net461 -p:RestoreConfigFile=Tests/Test.NuGet.Config -p:UseRealmNupkgsWithVersion=${{ needs.build-packages.outputs.package_version }} + run: msbuild Tests/Realm.Tests -restore -p:Configuration=Release -p:TargetFramework=net461 -p:RestoreConfigFile=Tests/Test.NuGet.Config -p:UseRealmNupkgsWithVersion=${{ needs.build-packages.outputs.package_version }} -p:RealmTestsStandaloneExe=true - name: Run the tests run: './Tests/Realm.Tests/bin/Release/net461/Realm.Tests.exe --result=TestResults.xml --labels=After ' - name: Publish Unit Test Results @@ -214,7 +214,7 @@ jobs: NET_VERSION=$(echo '${{ matrix.framework }}.x' | sed 's/net//g') echo "version=$NET_VERSION" >> $GITHUB_OUTPUT shell: bash - - uses: actions/setup-dotnet@607fce577a46308457984d59e4954e075820f10a + - uses: actions/setup-dotnet@5d1464d5da459f3d7085106d52e499f4dc5d0f59 with: dotnet-version: ${{ steps.get-net-version.outputs.version }} - name: Publish Tests/Realm.Tests @@ -332,7 +332,7 @@ jobs: with: name: Realm.PlatformHelpers.${{ needs.build-packages.outputs.package_version }} path: ${{ github.workspace }}/Realm/packages/ - - uses: actions/setup-dotnet@607fce577a46308457984d59e4954e075820f10a + - uses: actions/setup-dotnet@5d1464d5da459f3d7085106d52e499f4dc5d0f59 with: dotnet-version: 8.0.x - name: Setup workloads @@ -434,7 +434,7 @@ jobs: with: name: Realm.PlatformHelpers.${{ needs.build-packages.outputs.package_version }} path: ${{ github.workspace }}/Realm/packages/ - - uses: actions/setup-dotnet@607fce577a46308457984d59e4954e075820f10a + - uses: actions/setup-dotnet@5d1464d5da459f3d7085106d52e499f4dc5d0f59 with: dotnet-version: 8.0.x - name: Setup workloads @@ -608,7 +608,7 @@ jobs: with: name: Realm.PlatformHelpers.${{ needs.build-packages.outputs.package_version }} path: ${{ github.workspace }}/Realm/packages/ - - uses: actions/setup-dotnet@607fce577a46308457984d59e4954e075820f10a + - uses: actions/setup-dotnet@5d1464d5da459f3d7085106d52e499f4dc5d0f59 with: dotnet-version: 8.0.x - name: Setup workloads @@ -705,7 +705,7 @@ jobs: run: |- echo "::add-matcher::.github/problem-matchers/csc.json" echo "::add-matcher::.github/problem-matchers/msvc.json" - - uses: actions/setup-dotnet@607fce577a46308457984d59e4954e075820f10a + - uses: actions/setup-dotnet@5d1464d5da459f3d7085106d52e499f4dc5d0f59 with: dotnet-version: 6.0.x - name: Setup workloads @@ -743,7 +743,7 @@ jobs: run: |- echo "::add-matcher::.github/problem-matchers/csc.json" echo "::add-matcher::.github/problem-matchers/msvc.json" - - uses: actions/setup-dotnet@607fce577a46308457984d59e4954e075820f10a + - uses: actions/setup-dotnet@5d1464d5da459f3d7085106d52e499f4dc5d0f59 with: dotnet-version: 6.0.x - name: Setup workloads @@ -859,7 +859,7 @@ jobs: run: |- echo "::add-matcher::.github/problem-matchers/csc.json" echo "::add-matcher::.github/problem-matchers/msvc.json" - - uses: actions/setup-dotnet@607fce577a46308457984d59e4954e075820f10a + - uses: actions/setup-dotnet@5d1464d5da459f3d7085106d52e499f4dc5d0f59 with: dotnet-version: 6.0.x - name: Terminate Baas @@ -938,7 +938,7 @@ jobs: with: submodules: false ref: ${{ github.event.pull_request.head.sha }} - - uses: nirinchev/verify-todo@9be6f76daddad71433e5deb1b58c517490e5c66e + - uses: nirinchev/verify-todo@ffa352ac028b4cdc8bc626471d33aa341b3ab7c9 with: token: ${{ secrets.GITHUB_TOKEN }} include: '**/*.+(cs|cpp|hpp)' diff --git a/Tests/Realm.Tests/Database/DynamicEmbeddedTests.cs b/Tests/Realm.Tests/Database/DynamicEmbeddedTests.cs index 7511078c6a..fc4f843254 100644 --- a/Tests/Realm.Tests/Database/DynamicEmbeddedTests.cs +++ b/Tests/Realm.Tests/Database/DynamicEmbeddedTests.cs @@ -390,6 +390,11 @@ public void RealmAddEmbeddedObjectToDictionary() Assert.That(addedDict.Count, Is.EqualTo(2)); Assert.That(addedDict["bar"].DynamicApi.Get(nameof(DynamicSubTask.Summary)), Is.EqualTo("This is a second subtask level 1")); + if (TestHelpers.IsAOTTarget) + { + return; + } + #if !UNITY var dynamicId = Guid.NewGuid().ToString(); @@ -610,6 +615,11 @@ public void RealmSetEmbeddedObjectInDictionary() Assert.That(subTasks["b"].DynamicApi.Get(nameof(DynamicSubTask.Summary)), Is.EqualTo("new at b")); Assert.That(subTasks["c"].DynamicApi.Get(nameof(DynamicSubTask.Summary)), Is.EqualTo("initial at c")); + if (TestHelpers.IsAOTTarget) + { + return; + } + #if !UNITY var dynamicId = Guid.NewGuid().ToString(); diff --git a/Tests/Realm.Tests/Database/MigrationTests.cs b/Tests/Realm.Tests/Database/MigrationTests.cs index f79ec5bee1..b913064762 100644 --- a/Tests/Realm.Tests/Database/MigrationTests.cs +++ b/Tests/Realm.Tests/Database/MigrationTests.cs @@ -34,7 +34,7 @@ namespace Realms.Tests.Database { [TestFixture, Preserve(AllMembers = true)] - public partial class MigrationTests : RealmInstanceTest + public class MigrationTests : RealmInstanceTest { private const string FileToMigrate = "ForMigrationsToCopyAndMigrate.realm"; @@ -116,10 +116,7 @@ public void ExceptionInMigrationCallback() var configuration = new RealmConfiguration(Guid.NewGuid().ToString()) { SchemaVersion = 100, - MigrationCallback = (migration, oldSchemaVersion) => - { - throw dummyException; - } + MigrationCallback = (_, _) => throw dummyException }; TestHelpers.CopyBundledFileToDocuments(FileToMigrate, configuration.DatabasePath); @@ -138,7 +135,7 @@ public void MigrationTriggersDelete() IsDynamic = true, Schema = new RealmSchema.Builder { - new ObjectSchema.Builder("Person", ObjectSchema.ObjectType.RealmObject) + new ObjectSchema.Builder("Person") { Property.FromType("Name") } @@ -160,7 +157,7 @@ public void MigrationTriggersDelete() ShouldDeleteIfMigrationNeeded = true, Schema = new RealmSchema.Builder { - new ObjectSchema.Builder("Person", ObjectSchema.ObjectType.RealmObject) + new ObjectSchema.Builder("Person") { Property.FromType("Name") } @@ -185,7 +182,7 @@ public void MigrationRenameProperty() var configuration = new RealmConfiguration(Guid.NewGuid().ToString()) { SchemaVersion = 100, - MigrationCallback = (migration, oldSchemaVersion) => + MigrationCallback = (migration, _) => { migration.RenameProperty(nameof(Person), "TriggersSchema", nameof(Person.OptionalAddress)); @@ -212,12 +209,10 @@ public void MigrationRenameProperty() [Test] public void MigrationRenamePropertyErrors() { - var oldPropertyValues = new List(); - var configuration = new RealmConfiguration(Guid.NewGuid().ToString()) { SchemaVersion = 100, - MigrationCallback = (migration, oldSchemaVersion) => + MigrationCallback = (migration, _) => { migration.RenameProperty(nameof(Person), "TriggersSchema", "PropertyNotInNewSchema"); } @@ -231,7 +226,7 @@ public void MigrationRenamePropertyErrors() configuration = new RealmConfiguration(configuration.DatabasePath) { SchemaVersion = 100, - MigrationCallback = (migration, oldSchemaVersion) => + MigrationCallback = (migration, _) => { migration.RenameProperty(nameof(Person), "PropertyNotInOldSchema", nameof(Person.OptionalAddress)); } @@ -243,7 +238,7 @@ public void MigrationRenamePropertyErrors() configuration = new RealmConfiguration(configuration.DatabasePath) { SchemaVersion = 100, - MigrationCallback = (migration, oldSchemaVersion) => + MigrationCallback = (migration, _) => { migration.RenameProperty("NonExistingType", "TriggersSchema", nameof(Person.OptionalAddress)); } @@ -255,7 +250,7 @@ public void MigrationRenamePropertyErrors() configuration = new RealmConfiguration(configuration.DatabasePath) { SchemaVersion = 100, - MigrationCallback = (migration, oldSchemaVersion) => + MigrationCallback = (migration, _) => { migration.RenameProperty(nameof(Person), "TriggersSchema", nameof(Person.Birthday)); } @@ -267,7 +262,7 @@ public void MigrationRenamePropertyErrors() configuration = new RealmConfiguration(configuration.DatabasePath) { SchemaVersion = 100, - MigrationCallback = (migration, oldSchemaVersion) => + MigrationCallback = (migration, _) => { migration.RenameProperty(nameof(Person), nameof(Person.Latitude), nameof(Person.Longitude)); } @@ -283,7 +278,7 @@ public void MigrationRenamePropertyInvalidArguments() var configuration = new RealmConfiguration(Guid.NewGuid().ToString()) { SchemaVersion = 100, - MigrationCallback = (migration, oldSchemaVersion) => + MigrationCallback = (migration, _) => { Assert.Throws(() => migration.RenameProperty(null!, "TriggersSchema", "OptionalAddress")); Assert.Throws(() => migration.RenameProperty("Person", null!, "OptionalAddress")); @@ -309,7 +304,7 @@ public void MigrationRemoveTypeInSchema() Schema = new[] { typeof(Dog), typeof(Owner), typeof(Person) }, }; - using (var oldRealm = GetRealm(oldRealmConfig)) + using (GetRealm(oldRealmConfig)) { } @@ -317,7 +312,7 @@ public void MigrationRemoveTypeInSchema() { SchemaVersion = 1, Schema = new[] { typeof(PrimaryKeyObjectIdObject), typeof(Person) }, - MigrationCallback = (migration, oldSchemaVersion) => + MigrationCallback = (migration, _) => { migration.RemoveType(nameof(Person)); } @@ -349,7 +344,7 @@ public void MigrationRemoveTypeNotInSchema() { SchemaVersion = 1, Schema = new[] { typeof(Dog), typeof(Owner) }, - MigrationCallback = (migration, oldSchemaVersion) => + MigrationCallback = (migration, _) => { migrationCallbackCalled = true; @@ -397,7 +392,7 @@ public void MigrationRemoveTypeInvalidArguments() Schema = new[] { typeof(Dog), typeof(Owner), typeof(Person) }, }; - using (var oldRealm = GetRealm(oldRealmConfig)) + using (GetRealm(oldRealmConfig)) { } @@ -405,7 +400,7 @@ public void MigrationRemoveTypeInvalidArguments() { SchemaVersion = 1, Schema = new[] { typeof(PrimaryKeyObjectIdObject), typeof(Person) }, - MigrationCallback = (migration, oldSchemaVersion) => + MigrationCallback = (migration, _) => { Assert.Throws(() => migration.RemoveType(null!)); Assert.Throws(() => migration.RemoveType(string.Empty)); @@ -419,7 +414,7 @@ public void MigrationRemoveTypeInvalidArguments() public void Migration_WhenDone_DisposesAllObjectsAndLists() { var config = new RealmConfiguration(Guid.NewGuid().ToString()); - using (var oldRealm = GetRealm(config)) + using (GetRealm(config)) { } @@ -433,7 +428,7 @@ public void Migration_WhenDone_DisposesAllObjectsAndLists() var newConfig = new RealmConfiguration(config.DatabasePath) { SchemaVersion = 1, - MigrationCallback = (migration, oldSchemaVersion) => + MigrationCallback = (migration, _) => { standaloneObject = migration.NewRealm.Add(new AllTypesObject { RequiredStringProperty = string.Empty }); Assert.That(standaloneObject.IsValid); @@ -476,7 +471,7 @@ public void Migration_WhenDone_DisposesAllObjectsAndLists() } }; - using (var newRealm = Realm.GetInstance(newConfig)) + using (Realm.GetInstance(newConfig)) { // Here we should see all objects accessed during the migration get disposed, even though // newRealm is still open. @@ -583,7 +578,7 @@ public void Migration_ChangePrimaryKey_Dynamic() var newRealmConfig = new RealmConfiguration(oldRealmConfig.DatabasePath) { SchemaVersion = 1, - MigrationCallback = (migration, oldSchemaVersion) => + MigrationCallback = (migration, _) => { var value = migration.NewRealm.DynamicApi.Find(nameof(IntPrimaryKeyWithValueObject), 123)!; value.DynamicApi.Set("_id", 456); @@ -619,7 +614,7 @@ public void Migration_ChangePrimaryKey_Static() var newRealmConfig = new RealmConfiguration(oldRealmConfig.DatabasePath) { SchemaVersion = 1, - MigrationCallback = (migration, oldSchemaVersion) => + MigrationCallback = (migration, _) => { var value = migration.NewRealm.Find(123)!; value.Id = 456; @@ -666,7 +661,7 @@ public void Migration_ChangePrimaryKeyType() { SchemaVersion = 1, Schema = new[] { typeof(ObjectV2) }, - MigrationCallback = (migration, oldSchemaVersion) => + MigrationCallback = (migration, _) => { foreach (var oldObj in migration.OldRealm.DynamicApi.All("Object")) { @@ -706,7 +701,7 @@ public void Migration_ChangePrimaryKey_WithDuplicates_Throws() var newRealmConfig = new RealmConfiguration(oldRealmConfig.DatabasePath) { SchemaVersion = 1, - MigrationCallback = (migration, oldSchemaVersion) => + MigrationCallback = (migration, _) => { var value = migration.NewRealm.Find(1)!; value.Id = 2; @@ -744,7 +739,7 @@ public void Migration_ToEmbedded_DuplicatesObjects() Value = "foo" }); - var container1 = oldRealm.Add(new ObjectContainerV1 + oldRealm.Add(new ObjectContainerV1 { Value = "container1", Link = obj, @@ -757,7 +752,7 @@ public void Migration_ToEmbedded_DuplicatesObjects() Value = "bar" }); - var container2 = oldRealm.Add(new ObjectContainerV1 + oldRealm.Add(new ObjectContainerV1 { Value = "container2", Link = obj, @@ -805,13 +800,13 @@ public void Migration_ToEmbedded_DeletesOrphans() Value = "foo" }); - var orphanedObj = oldRealm.Add(new ObjectV1 + oldRealm.Add(new ObjectV1 { Id = 2, Value = "bar" }); - var container = oldRealm.Add(new ObjectContainerV1 + oldRealm.Add(new ObjectContainerV1 { Value = "container", Link = obj @@ -862,7 +857,7 @@ public void Migration_FindInNewRealm_WhenObjectIsDeleted_ReturnsNull() typeof(Dotnet_3597) }, SchemaVersion = 2, - MigrationCallback = (migration, version) => + MigrationCallback = (migration, _) => { var oldObjects = migration.OldRealm.DynamicApi.All(nameof(Dotnet_3597)).ToArray(); var old1 = oldObjects.First(o => o.DynamicApi.Get("IntProp") == 1); @@ -921,7 +916,7 @@ public void Migration_MigratesListOfFloats() typeof(Dotnet_3597) }, SchemaVersion = 2, - MigrationCallback = (migration, version) => + MigrationCallback = (migration, _) => { foreach (var item in migration.OldRealm.DynamicApi.All(nameof(Dotnet_3597))) { @@ -1000,7 +995,7 @@ public partial class Dotnet_3597_Old : TestRealmObject public float? FloatProp { get; set; } - public IList FloatList { get; } + public IList FloatList { get; } = null!; } [Explicit] @@ -1009,8 +1004,8 @@ public partial class Dotnet_3597 : TestRealmObject { public int IntProp { get; set; } - public string FloatProp { get; set; } + public string FloatProp { get; set; } = string.Empty; - public IList FloatList { get; } + public IList FloatList { get; } = null!; } }