From 5e443bbf21ca5e594655e44c826449a264230641 Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Thu, 19 Sep 2024 09:25:34 +0000 Subject: [PATCH 1/8] chore(deps): update terraform time to v0.12.1 --- terraform/modules/storage/database/mongo/versions.tf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/terraform/modules/storage/database/mongo/versions.tf b/terraform/modules/storage/database/mongo/versions.tf index 042090bbc..b4596b999 100644 --- a/terraform/modules/storage/database/mongo/versions.tf +++ b/terraform/modules/storage/database/mongo/versions.tf @@ -6,7 +6,7 @@ terraform { } time = { source = "hashicorp/time" - version = "0.12.0" + version = "0.12.1" } } } From 34da0243611b6b52ad675893861cdbdf80053373 Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Fri, 13 Dec 2024 16:21:17 +0000 Subject: [PATCH 2/8] chore(deps): update github actions --- .github/workflows/build.yml | 2 +- .github/workflows/scout-cron.yml | 2 +- .github/workflows/sonar.yml | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index ba30f4d73..dd5ae6cd0 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -316,7 +316,7 @@ jobs: username: ${{ secrets.DOCKER_HUB_LOGIN }} password: ${{ secrets.DOCKER_HUB_TOKEN }} - name: Analyze for critical and high CVEs - uses: docker/scout-action@6ac950eb733f8b2811f25c05d97bfb3d181b8026 # v1 + uses: docker/scout-action@b23590dc1e4d09febc00cfcbc51e9e8c0f7ee9f3 # v1 with: command: cves image: "${{ matrix.image }}:${{ needs.versionning.outputs.version }}" diff --git a/.github/workflows/scout-cron.yml b/.github/workflows/scout-cron.yml index bec584a0c..57dbc3c8e 100644 --- a/.github/workflows/scout-cron.yml +++ b/.github/workflows/scout-cron.yml @@ -43,7 +43,7 @@ jobs: username: ${{ secrets.DOCKER_HUB_LOGIN }} password: ${{ secrets.DOCKER_HUB_TOKEN }} - name: Analyze for critical and high CVEs - uses: docker/scout-action@6ac950eb733f8b2811f25c05d97bfb3d181b8026 # v1 + uses: docker/scout-action@b23590dc1e4d09febc00cfcbc51e9e8c0f7ee9f3 # v1 with: command: cves image: "${{ matrix.image }}:${{ matrix.image }}" diff --git a/.github/workflows/sonar.yml b/.github/workflows/sonar.yml index c9c0f49c8..79974443c 100644 --- a/.github/workflows/sonar.yml +++ b/.github/workflows/sonar.yml @@ -25,14 +25,14 @@ jobs: submodules: true - name: Cache SonarCloud packages - uses: actions/cache@6849a6489940f00c2f30c0fb92c6274307ccb58a # v4 + uses: actions/cache@1bd1e32a3bdc45362d1e726936510720a7c30a57 # v4 with: path: .\.sonar\cache key: ${{ runner.os }}-sonar restore-keys: ${{ runner.os }}-sonar - name: Cache SonarCloud scanner id: cache-sonar-scanner - uses: actions/cache@6849a6489940f00c2f30c0fb92c6274307ccb58a # v4 + uses: actions/cache@1bd1e32a3bdc45362d1e726936510720a7c30a57 # v4 with: path: .\.sonar\scanner key: ${{ runner.os }}-sonar-scanner From c1af4462b07e50e0ee5b1a921c94cd2bdd090473 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Gurhem?= Date: Wed, 24 May 2023 15:00:19 +0200 Subject: [PATCH 3/8] feat: Better assembly resolution during dynamic loading --- .../CollocatedAssemblyResolver.cs | 94 +++++++++++++++++++ Common/src/Injection/ServiceCollectionExt.cs | 3 +- .../AdapterLoading/AdapterLoadingTest.cs | 23 +++-- Compute/PollingAgent/src/Program.cs | 11 ++- Control/Submitter/src/Program.cs | 11 ++- 5 files changed, 123 insertions(+), 19 deletions(-) create mode 100644 Common/src/DynamicLoading/CollocatedAssemblyResolver.cs diff --git a/Common/src/DynamicLoading/CollocatedAssemblyResolver.cs b/Common/src/DynamicLoading/CollocatedAssemblyResolver.cs new file mode 100644 index 000000000..8ba3bdb0b --- /dev/null +++ b/Common/src/DynamicLoading/CollocatedAssemblyResolver.cs @@ -0,0 +1,94 @@ +// This file is part of the ArmoniK project +// +// Copyright (C) ANEO, 2021-2023. All rights reserved. +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as published +// by the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY, without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see . + +using System; +using System.Collections.Concurrent; +using System.IO; +using System.Reflection; + +using Microsoft.Extensions.Logging; + +namespace ArmoniK.Core.Common.DynamicLoading; + +public class CollocatedAssemblyResolver +{ + private static readonly ConcurrentDictionary PathDictionary = new(); + private readonly ILogger logger_; + + + public CollocatedAssemblyResolver(ILogger logger) + { + GetLoadDirectories(); + logger_ = logger; + } + + private static void GetLoadDirectories() + { + AppDomain.CurrentDomain.AssemblyLoad += (_, + eventArgs) => + { + var path = Path.GetDirectoryName(eventArgs.LoadedAssembly.Location); + if (path == null) + { + return; + } + + PathDictionary[path] = true; + }; + + PathDictionary[Path.GetDirectoryName(Assembly.GetCallingAssembly() + .Location)!] = true; + PathDictionary[Path.GetDirectoryName(typeof(CollocatedAssemblyResolver).Assembly.Location)!] = true; + } + + public Assembly? AssemblyResolve(object? sender, + ResolveEventArgs args) + { + logger_.LogDebug("RequestingAssembly {RequestingAssembly}", + args.RequestingAssembly); + + if (args.RequestingAssembly?.Location is null) + { + return null; + } + + var assemblyName = new AssemblyName(args.Name).Name; + var directoryName = Path.GetDirectoryName(args.RequestingAssembly.Location)!; + + PathDictionary[directoryName] = true; + + foreach (var kp in PathDictionary) + { + logger_.LogInformation("Trying to load {Assembly} from {Directory}", + assemblyName, + kp.Key); + + var assemblyPath = Path.Combine(kp.Key, + assemblyName + ".dll"); + + if (File.Exists(assemblyPath)) + { + return Assembly.LoadFile(assemblyPath); + } + + logger_.LogDebug("{AssemblyPath} file does not exist", + assemblyPath); + } + + return null; + } +} diff --git a/Common/src/Injection/ServiceCollectionExt.cs b/Common/src/Injection/ServiceCollectionExt.cs index ee56fc356..246d3be1f 100644 --- a/Common/src/Injection/ServiceCollectionExt.cs +++ b/Common/src/Injection/ServiceCollectionExt.cs @@ -103,8 +103,7 @@ public static IServiceCollection AddQueue(this IServiceCollection services, throw new InvalidOperationException($"{nameof(queueSettings.ClassName)} should not be null or empty."); } - var ctx = new AdapterLoadContext(queueSettings.AdapterAbsolutePath); - var assembly = ctx.LoadFromAssemblyName(AssemblyName.GetAssemblyName(queueSettings.AdapterAbsolutePath)); + var assembly = Assembly.LoadFrom(queueSettings.AdapterAbsolutePath); logger.LogInformation("Loaded assembly {assemblyName}", assembly.FullName); diff --git a/Common/tests/AdapterLoading/AdapterLoadingTest.cs b/Common/tests/AdapterLoading/AdapterLoadingTest.cs index 87e60586b..28f8b3d90 100644 --- a/Common/tests/AdapterLoading/AdapterLoadingTest.cs +++ b/Common/tests/AdapterLoading/AdapterLoadingTest.cs @@ -1,17 +1,17 @@ // This file is part of the ArmoniK project -// +// // Copyright (C) ANEO, 2021-2024. All rights reserved. -// +// // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU Affero General Public License as published // by the Free Software Foundation, either version 3 of the License, or // (at your option) any later version. -// +// // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY, without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU Affero General Public License for more details. -// +// // You should have received a copy of the GNU Affero General Public License // along with this program. If not, see . @@ -100,13 +100,15 @@ public static IEnumerable ConfInvalidOperationException { get { - yield return new TestCaseData(new Dictionary + yield return new TestCaseData(new InvalidOperationException(), + new Dictionary { { "Amqp:User", "User" }, }).SetArgDisplayNames("No components"); - yield return new TestCaseData(new Dictionary + yield return new TestCaseData(new InvalidOperationException(), + new Dictionary { { "Amqp:User", "User" @@ -115,7 +117,8 @@ public static IEnumerable ConfInvalidOperationException $"{Components.SettingSection}:{nameof(Components.QueueAdaptorSettings)}:{nameof(Components.QueueAdaptorSettings.ClassName)}", "" }, }).SetArgDisplayNames("Empty class"); - yield return new TestCaseData(new Dictionary + yield return new TestCaseData(new InvalidOperationException(), + new Dictionary { { "Amqp:User", "User" @@ -128,7 +131,8 @@ public static IEnumerable ConfInvalidOperationException "path" }, }).SetArgDisplayNames("Empty path"); - yield return new TestCaseData(new Dictionary + yield return new TestCaseData(new FileNotFoundException(), + new Dictionary { { "Amqp:User", "User" @@ -143,7 +147,8 @@ public static IEnumerable ConfInvalidOperationException }, }).SetArgDisplayNames("invalid path"); - yield return new TestCaseData(new Dictionary + yield return new TestCaseData(new InvalidOperationException(), + new Dictionary { { "Amqp:User", "User" diff --git a/Compute/PollingAgent/src/Program.cs b/Compute/PollingAgent/src/Program.cs index 9d552849f..aa674aff9 100644 --- a/Compute/PollingAgent/src/Program.cs +++ b/Compute/PollingAgent/src/Program.cs @@ -1,17 +1,17 @@ // This file is part of the ArmoniK project -// +// // Copyright (C) ANEO, 2021-2024. All rights reserved. -// +// // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU Affero General Public License as published // by the Free Software Foundation, either version 3 of the License, or // (at your option) any later version. -// +// // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY, without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU Affero General Public License for more details. -// +// // You should have received a copy of the GNU Affero General Public License // along with this program. If not, see . @@ -28,6 +28,7 @@ using ArmoniK.Core.Adapters.S3; using ArmoniK.Core.Base; using ArmoniK.Core.Base.DataStructures; +using ArmoniK.Core.Common.DynamicLoading; using ArmoniK.Core.Common.gRPC.Services; using ArmoniK.Core.Common.Injection; using ArmoniK.Core.Common.Meter; @@ -80,6 +81,8 @@ public static async Task Main(string[] args) try { + AppDomain.CurrentDomain.AssemblyResolve += new CollocatedAssemblyResolver(logger.GetLogger()).AssemblyResolve; + var pollsterOptions = builder.Configuration.GetSection(Pollster.SettingSection) .Get() ?? new Pollster(); diff --git a/Control/Submitter/src/Program.cs b/Control/Submitter/src/Program.cs index 892906ca5..105997565 100644 --- a/Control/Submitter/src/Program.cs +++ b/Control/Submitter/src/Program.cs @@ -1,17 +1,17 @@ // This file is part of the ArmoniK project -// +// // Copyright (C) ANEO, 2021-2024. All rights reserved. -// +// // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU Affero General Public License as published // by the Free Software Foundation, either version 3 of the License, or // (at your option) any later version. -// +// // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY, without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU Affero General Public License for more details. -// +// // You should have received a copy of the GNU Affero General Public License // along with this program. If not, see . @@ -29,6 +29,7 @@ using ArmoniK.Core.Base; using ArmoniK.Core.Base.DataStructures; using ArmoniK.Core.Common.Auth.Authentication; +using ArmoniK.Core.Common.DynamicLoading; using ArmoniK.Core.Common.gRPC; using ArmoniK.Core.Common.gRPC.Services; using ArmoniK.Core.Common.Injection; @@ -82,6 +83,8 @@ public static async Task Main(string[] args) try { + AppDomain.CurrentDomain.AssemblyResolve += new CollocatedAssemblyResolver(logger.GetLogger()).AssemblyResolve; + builder.Host.UseSerilog(logger.GetSerilogConf()); builder.Services.AddLogging(logger.Configure) From bac83e96079baf8e9d5d837d369951d91ae64732 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Gurhem?= Date: Tue, 17 Dec 2024 08:05:46 +0100 Subject: [PATCH 4/8] refactor: add null checks and improve log messages --- .../CollocatedAssemblyResolver.cs | 39 +++++++++++++------ 1 file changed, 27 insertions(+), 12 deletions(-) diff --git a/Common/src/DynamicLoading/CollocatedAssemblyResolver.cs b/Common/src/DynamicLoading/CollocatedAssemblyResolver.cs index 8ba3bdb0b..f68702be5 100644 --- a/Common/src/DynamicLoading/CollocatedAssemblyResolver.cs +++ b/Common/src/DynamicLoading/CollocatedAssemblyResolver.cs @@ -1,6 +1,6 @@ // This file is part of the ArmoniK project // -// Copyright (C) ANEO, 2021-2023. All rights reserved. +// Copyright (C) ANEO, 2021-2024. All rights reserved. // // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU Affero General Public License as published @@ -52,7 +52,11 @@ private static void GetLoadDirectories() PathDictionary[Path.GetDirectoryName(Assembly.GetCallingAssembly() .Location)!] = true; - PathDictionary[Path.GetDirectoryName(typeof(CollocatedAssemblyResolver).Assembly.Location)!] = true; + + foreach (var assembly in AppDomain.CurrentDomain.GetAssemblies()) + { + PathDictionary[Path.GetDirectoryName(assembly.Location)!] = true; + } } public Assembly? AssemblyResolve(object? sender, @@ -66,27 +70,38 @@ private static void GetLoadDirectories() return null; } - var assemblyName = new AssemblyName(args.Name).Name; - var directoryName = Path.GetDirectoryName(args.RequestingAssembly.Location)!; + var assemblyName = new AssemblyName(args.Name).Name; - PathDictionary[directoryName] = true; + if (string.IsNullOrEmpty(assemblyName)) + { + logger_.LogWarning("The assembly to resolve {AssemblyToResolve} does not have a name", + args.Name); + return null; + } + + var directoryName = Path.GetDirectoryName(args.RequestingAssembly.Location); - foreach (var kp in PathDictionary) + if (!string.IsNullOrEmpty(directoryName)) { - logger_.LogInformation("Trying to load {Assembly} from {Directory}", - assemblyName, - kp.Key); + PathDictionary[directoryName] = true; + } - var assemblyPath = Path.Combine(kp.Key, + foreach (var path in PathDictionary.Keys) + { + var assemblyPath = Path.Combine(path, assemblyName + ".dll"); if (File.Exists(assemblyPath)) { + logger_.LogDebug("Loading assembly {Assembly} from {Directory}", + assemblyName, + path); return Assembly.LoadFile(assemblyPath); } - logger_.LogDebug("{AssemblyPath} file does not exist", - assemblyPath); + logger_.LogDebug("Assembly {Assembly} not found in {Directory}", + assemblyName, + path); } return null; From 92ae55fb41d00544d73c4e74d618676f0e5e71d1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Gurhem?= Date: Tue, 17 Dec 2024 08:50:09 +0100 Subject: [PATCH 5/8] refactor: remove AdapterLoadContext as it is not needed anymore --- Common/src/Injection/AdapterLoadContext.cs | 54 ---------------------- 1 file changed, 54 deletions(-) delete mode 100644 Common/src/Injection/AdapterLoadContext.cs diff --git a/Common/src/Injection/AdapterLoadContext.cs b/Common/src/Injection/AdapterLoadContext.cs deleted file mode 100644 index f3cfe3544..000000000 --- a/Common/src/Injection/AdapterLoadContext.cs +++ /dev/null @@ -1,54 +0,0 @@ -// This file is part of the ArmoniK project -// -// Copyright (C) ANEO, 2021-2024. All rights reserved. -// -// This program is free software: you can redistribute it and/or modify -// it under the terms of the GNU Affero General Public License as published -// by the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY, without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU Affero General Public License for more details. -// -// You should have received a copy of the GNU Affero General Public License -// along with this program. If not, see . - -using System.Reflection; -using System.Runtime.Loader; - -namespace ArmoniK.Core.Common.Injection; - -/// -/// Class holding load context for Adapters -/// -public class AdapterLoadContext : AssemblyLoadContext -{ - private readonly AssemblyDependencyResolver resolver_; - - /// - /// Instantiate a with the path to the assembly to be loaded. - /// - /// Path to the assembly - public AdapterLoadContext(string assemblyPath) - => resolver_ = new AssemblyDependencyResolver(assemblyPath); - - /// - protected override Assembly? Load(AssemblyName assemblyName) - { - var assemblyPath = resolver_.ResolveAssemblyToPath(assemblyName); - return assemblyPath is not null - ? LoadFromAssemblyPath(assemblyPath) - : null; - } - - /// - protected override nint LoadUnmanagedDll(string unmanagedDllName) - { - var libraryPath = resolver_.ResolveUnmanagedDllToPath(unmanagedDllName); - return libraryPath is not null - ? LoadUnmanagedDllFromPath(libraryPath) - : nint.Zero; - } -} From 69b3630605ceecda19bfda9ca7d7f7399a2f7f4d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Gurhem?= Date: Tue, 17 Dec 2024 08:50:40 +0100 Subject: [PATCH 6/8] style: format code --- Common/src/DynamicLoading/CollocatedAssemblyResolver.cs | 5 +---- Compute/PollingAgent/src/Program.cs | 8 ++++---- Control/Submitter/src/Program.cs | 8 ++++---- 3 files changed, 9 insertions(+), 12 deletions(-) diff --git a/Common/src/DynamicLoading/CollocatedAssemblyResolver.cs b/Common/src/DynamicLoading/CollocatedAssemblyResolver.cs index f68702be5..8aa356679 100644 --- a/Common/src/DynamicLoading/CollocatedAssemblyResolver.cs +++ b/Common/src/DynamicLoading/CollocatedAssemblyResolver.cs @@ -53,10 +53,7 @@ private static void GetLoadDirectories() PathDictionary[Path.GetDirectoryName(Assembly.GetCallingAssembly() .Location)!] = true; - foreach (var assembly in AppDomain.CurrentDomain.GetAssemblies()) - { - PathDictionary[Path.GetDirectoryName(assembly.Location)!] = true; - } + PathDictionary[Path.GetDirectoryName(typeof(CollocatedAssemblyResolver).Assembly.Location)!] = true; } public Assembly? AssemblyResolve(object? sender, diff --git a/Compute/PollingAgent/src/Program.cs b/Compute/PollingAgent/src/Program.cs index aa674aff9..48f2d58c5 100644 --- a/Compute/PollingAgent/src/Program.cs +++ b/Compute/PollingAgent/src/Program.cs @@ -1,17 +1,17 @@ // This file is part of the ArmoniK project -// +// // Copyright (C) ANEO, 2021-2024. All rights reserved. -// +// // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU Affero General Public License as published // by the Free Software Foundation, either version 3 of the License, or // (at your option) any later version. -// +// // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY, without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU Affero General Public License for more details. -// +// // You should have received a copy of the GNU Affero General Public License // along with this program. If not, see . diff --git a/Control/Submitter/src/Program.cs b/Control/Submitter/src/Program.cs index 105997565..d5c5da458 100644 --- a/Control/Submitter/src/Program.cs +++ b/Control/Submitter/src/Program.cs @@ -1,17 +1,17 @@ // This file is part of the ArmoniK project -// +// // Copyright (C) ANEO, 2021-2024. All rights reserved. -// +// // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU Affero General Public License as published // by the Free Software Foundation, either version 3 of the License, or // (at your option) any later version. -// +// // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY, without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU Affero General Public License for more details. -// +// // You should have received a copy of the GNU Affero General Public License // along with this program. If not, see . From e0198c71c874a86c3fd1f679a900c1ab4f2298dd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Gurhem?= Date: Tue, 17 Dec 2024 08:51:24 +0100 Subject: [PATCH 7/8] test: try to laod pubsub and sqs --- .../AdapterLoading/AdapterLoadingTest.cs | 57 ++++++++++++++++--- 1 file changed, 50 insertions(+), 7 deletions(-) diff --git a/Common/tests/AdapterLoading/AdapterLoadingTest.cs b/Common/tests/AdapterLoading/AdapterLoadingTest.cs index 28f8b3d90..de630bb83 100644 --- a/Common/tests/AdapterLoading/AdapterLoadingTest.cs +++ b/Common/tests/AdapterLoading/AdapterLoadingTest.cs @@ -1,17 +1,17 @@ // This file is part of the ArmoniK project -// +// // Copyright (C) ANEO, 2021-2024. All rights reserved. -// +// // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU Affero General Public License as published // by the Free Software Foundation, either version 3 of the License, or // (at your option) any later version. -// +// // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY, without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU Affero General Public License for more details. -// +// // You should have received a copy of the GNU Affero General Public License // along with this program. If not, see . @@ -20,6 +20,7 @@ using System.Collections.Generic; using System.IO; +using ArmoniK.Core.Common.DynamicLoading; using ArmoniK.Core.Common.Injection; using ArmoniK.Core.Common.Injection.Options; using ArmoniK.Core.Common.Tests.Helpers; @@ -46,6 +47,12 @@ public class AdapterLoadingTest private static readonly string RabbitPath = $"{Path.DirectorySeparatorChar}Adaptors{Path.DirectorySeparatorChar}RabbitMQ{Path.DirectorySeparatorChar}src{Path.DirectorySeparatorChar}bin{Path.DirectorySeparatorChar}Debug{Path.DirectorySeparatorChar}net8.0{Path.DirectorySeparatorChar}ArmoniK.Core.Adapters.RabbitMQ.dll"; + private static readonly string SqsPath = + $"{Path.DirectorySeparatorChar}Adaptors{Path.DirectorySeparatorChar}SQS{Path.DirectorySeparatorChar}src{Path.DirectorySeparatorChar}bin{Path.DirectorySeparatorChar}Debug{Path.DirectorySeparatorChar}net8.0{Path.DirectorySeparatorChar}ArmoniK.Core.Adapters.SQS.dll"; + + private static readonly string PubSubPath = + $"{Path.DirectorySeparatorChar}Adaptors{Path.DirectorySeparatorChar}PubSub{Path.DirectorySeparatorChar}src{Path.DirectorySeparatorChar}bin{Path.DirectorySeparatorChar}Debug{Path.DirectorySeparatorChar}net8.0{Path.DirectorySeparatorChar}ArmoniK.Core.Adapters.PubSub.dll"; + public static IEnumerable TestCasesQueueLocation { @@ -63,6 +70,8 @@ public static void BuildServiceProvider(Dictionary config) var loggerProvider = new ConsoleForwardingLoggerProvider(); var logger = loggerProvider.CreateLogger("root"); + AppDomain.CurrentDomain.AssemblyResolve += new CollocatedAssemblyResolver(logger).AssemblyResolve; + var configuration = new ConfigurationManager(); configuration.AddInMemoryCollection(config); @@ -93,7 +102,7 @@ public void QueueShouldLoad(string path, }, }; - Assert.DoesNotThrow(() => BuildServiceProvider(config)); + BuildServiceProvider(config); } public static IEnumerable ConfInvalidOperationException @@ -162,13 +171,47 @@ public static IEnumerable ConfInvalidOperationException $"{SolutionRoot}{AmqpPath}" }, }).SetArgDisplayNames("Not implemented"); + + yield return new TestCaseData(new InvalidOperationException(), + new Dictionary + { + { + "PubSub:hey", "hey" + }, + { + $"{Components.SettingSection}:{nameof(Components.QueueAdaptorSettings)}:{nameof(Components.QueueAdaptorSettings.ClassName)}", + "ArmoniK.Core.Adapters.PubSub.QueueBuilder" + }, + { + $"{Components.SettingSection}:{nameof(Components.QueueAdaptorSettings)}:{nameof(Components.QueueAdaptorSettings.AdapterAbsolutePath)}", + $"{SolutionRoot}{PubSubPath}" + }, + }).SetArgDisplayNames("PubSub no credentials"); + + yield return new TestCaseData(new MissingMethodException(), + new Dictionary + { + { + "SQS:ServiceURL", "ServiceURL" + }, + { + $"{Components.SettingSection}:{nameof(Components.QueueAdaptorSettings)}:{nameof(Components.QueueAdaptorSettings.ClassName)}", + "ArmoniK.Core.Adapters.SQS.QueueBuilder" + }, + { + $"{Components.SettingSection}:{nameof(Components.QueueAdaptorSettings)}:{nameof(Components.QueueAdaptorSettings.AdapterAbsolutePath)}", + $"{SolutionRoot}{SqsPath}" + }, + }).SetArgDisplayNames("SQS misses a method when loading"); } } [Test] [TestCaseSource(nameof(ConfInvalidOperationException))] - public void InvalidConfShouldFail(Dictionary config) - => Assert.Throws(() => BuildServiceProvider(config)); + public void InvalidConfShouldFail(TEx ex, + Dictionary config) + where TEx : Exception + => Assert.Throws(() => BuildServiceProvider(config)); public static IEnumerable ConfTypeLoadException { From 4796421f6a4f4cc64bacf302df51067166d67287 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Gurhem?= Date: Tue, 17 Dec 2024 09:26:10 +0100 Subject: [PATCH 8/8] ci: build all the projects so that queue plugins can be loaded from tests --- .github/workflows/build.yml | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index dd5ae6cd0..75dbbfd5d 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -72,12 +72,12 @@ jobs: - name: Dotnet Restore run: | - MONITOR_PREFIX="monitor/restore/" MONITOR_CD=${{ matrix.projects }} tools/retry.sh -w 60 -- tools/monitor.sh \ + MONITOR_PREFIX="monitor/restore/" tools/retry.sh -w 60 -- tools/monitor.sh \ dotnet restore - name: Dotnet Build run: | - MONITOR_PREFIX="monitor/build/" MONITOR_CD=${{ matrix.projects }} tools/monitor.sh \ + MONITOR_PREFIX="monitor/build/" tools/monitor.sh \ dotnet build - name: Run tests @@ -143,12 +143,12 @@ jobs: - name: Dotnet Restore run: | - MONITOR_PREFIX="monitor/restore/" MONITOR_CD=${{ matrix.projects }} tools/retry.sh -w 60 -- tools/monitor.sh \ + MONITOR_PREFIX="monitor/restore/" tools/retry.sh -w 60 -- tools/monitor.sh \ dotnet restore - name: Dotnet Build run: | - MONITOR_PREFIX="monitor/build/" MONITOR_CD=${{ matrix.projects }} tools/monitor.sh \ + MONITOR_PREFIX="monitor/build/" tools/monitor.sh \ dotnet build - name: Run tests @@ -190,12 +190,10 @@ jobs: - name: Dotnet Restore run: | - cd ${{ matrix.projects }} dotnet restore - name: Dotnet Build run: | - cd ${{ matrix.projects }} dotnet build - name: Run tests