From 7b46e692f518755082395ff0cca23df24a3f46e6 Mon Sep 17 00:00:00 2001 From: wkirschenmann Date: Wed, 9 Aug 2023 17:15:16 +0200 Subject: [PATCH 01/21] Clean most warning and messages --- Adaptors/Amqp/src/ConnectionAmqp.cs | 36 ++--- Adaptors/Amqp/src/PullQueueStorage.cs | 1 - Adaptors/Amqp/src/QueueMessageHandler.cs | 3 - Adaptors/LocalStorage/src/ObjectStorage.cs | 28 ++-- .../LocalStorage/tests/ObjectStorageTests.cs | 2 +- Adaptors/Memory/src/PushQueueStorage.cs | 8 +- Adaptors/Memory/src/QueueStorage.cs | 8 +- Adaptors/Memory/src/ResultTable.cs | 10 +- Adaptors/Memory/src/TaskTable.cs | 22 --- Adaptors/MongoDB/src/AuthenticationTable.cs | 2 +- .../src/Common/MongoCollectionProvider.cs | 31 ++-- .../MongoDB/src/Common/SessionProvider.cs | 28 ++-- Adaptors/MongoDB/src/IMongoQueryableExt.cs | 2 +- Adaptors/MongoDB/src/ObjectStorage.cs | 6 +- Adaptors/MongoDB/src/PartitionTable.cs | 2 +- Adaptors/MongoDB/src/ResultTable.cs | 3 +- Adaptors/MongoDB/src/ServiceCollectionExt.cs | 9 +- .../DataModel/Auth/AuthDataModelMapping.cs | 6 +- .../DataModel/Auth/PipelineIntermediates.cs | 4 +- Adaptors/MongoDB/tests/BsonSerializerTest.cs | 4 +- ...sionsBuildersFieldFilterExpressionTests.cs | 42 +++--- Adaptors/MongoDB/tests/IndexTest.cs | 12 +- .../MongoDB/tests/MongoDatabaseProvider.cs | 11 +- Adaptors/MongoDB/tests/ObjectStorageTests.cs | 2 +- .../MongoDB/tests/SessionProviderTests.cs | 8 +- Adaptors/RabbitMQ/src/ConnectionRabbit.cs | 42 +++--- Adaptors/RabbitMQ/src/PullQueueStorage.cs | 1 - Adaptors/RabbitMQ/src/QueueMessageHandler.cs | 3 - Adaptors/Redis/src/ObjectStorage.cs | 28 ++-- Adaptors/Redis/tests/ObjectStorageTests.cs | 2 +- Adaptors/S3/src/ObjectStorage.cs | 48 +++--- Adaptors/S3/tests/ObjectStorageTests.cs | 2 +- Base/src/IQueueMessageHandler.cs | 11 -- Base/src/QueueMessageStatus.cs | 29 ++++ Common/src/Auth/Authentication/AuthData.cs | 4 +- .../Authentication/AuthenticationCache.cs | 8 +- .../src/Auth/Authentication/Authenticator.cs | 12 +- Common/src/Pollster/AgentHandler.cs | 4 +- Common/src/Pollster/Pollster.cs | 2 +- Common/src/Pollster/TaskHandler.cs | 72 ++++++--- .../src/StateMachines/UmlMermaidGraphStyle.cs | 2 +- Common/src/Utils/LocalIPv4.cs | 4 +- Common/src/Utils/LoggerInit.cs | 2 +- Common/src/gRPC/EnumFieldExt.cs | 32 ++-- Common/src/gRPC/FilterRangeExt.cs | 12 +- Common/src/gRPC/ListApplicationsRequestExt.cs | 10 +- Common/src/gRPC/ListPartitionsRequestExt.cs | 50 +++---- Common/src/gRPC/ListResultsRequestExt.cs | 20 +-- Common/src/gRPC/ListSessionsRequestExt.cs | 26 ++-- Common/src/gRPC/ListTasksRequestExt.cs | 29 ++-- Common/src/gRPC/Services/Agent.cs | 4 +- Common/src/gRPC/Services/GrpcAgentService.cs | 5 - .../gRPC/Services/GrpcApplicationsService.cs | 6 +- Common/src/gRPC/Services/GrpcAuthService.cs | 5 +- Common/src/gRPC/Services/GrpcEventsService.cs | 3 +- .../src/gRPC/Services/GrpcSessionsService.cs | 6 +- .../src/gRPC/Services/GrpcSubmitterService.cs | 2 + Common/src/gRPC/Services/GrpcTasksService.cs | 12 +- Common/src/gRPC/Services/Submitter.cs | 2 + Common/src/gRPC/Services/WatchToGrpc.cs | 5 +- .../AdapterLoading/AdapterLoadingTest.cs | 2 +- Common/tests/Auth/AuthenticationCacheTest.cs | 20 +-- .../Auth/AuthenticationIntegrationTest.cs | 90 ++++++----- Common/tests/Auth/MockIdentity.cs | 4 +- .../Helpers/ExceptionWorkerStreamHandler.cs | 2 +- .../Helpers/GrpcSubmitterServiceHelper.cs | 13 +- .../Helpers/SimpleQueueMessageHandler.cs | 5 +- .../Helpers/SimpleWorkerStreamHandler.cs | 2 + Common/tests/Helpers/TestDatabaseProvider.cs | 16 +- .../tests/Helpers/TestPollingAgentProvider.cs | 51 +++---- Common/tests/Helpers/TestPollsterProvider.cs | 8 +- .../tests/Helpers/TestTaskHandlerProvider.cs | 8 +- .../ToApplicationFieldTest.cs | 16 +- .../ToPartitionDataFieldTest.cs | 16 +- .../ToResultFieldTest.cs | 17 +-- .../ToSessionDataFieldTest.cs | 16 +- Common/tests/Pollster/PollsterTest.cs | 48 +++--- Common/tests/Pollster/TaskHandlerTest.cs | 12 +- Common/tests/Submitter/SubmitterTests.cs | 8 +- .../tests/TestBase/ObjectStorageTestBase.cs | 2 +- .../tests/TestBase/PartitionTableTestBase.cs | 48 +++--- .../tests/TestBase/QueueStorageTestsBase.cs | 1 - Common/tests/TestBase/SessionTableTestBase.cs | 98 ++++++------ Common/tests/TestBase/TaskTableTestBase.cs | 141 +++++++++--------- .../CreateLargeTaskRequestValidatorTest.cs | 3 + Common/tests/WatchToGrpcTests.cs | 10 +- Control/Submitter/src/Program.cs | 4 +- Tests/Bench/Client/src/Program.cs | 5 +- .../Bench/Server/src/BenchComputerService.cs | 4 + Tests/Bench/Server/src/GlobalSuppressions.cs | 8 + Tests/Common/Client/src/ConnectionTest.cs | 6 +- Tests/HtcMock/Client/src/Program.cs | 2 +- Tests/HtcMock/Client/src/SessionClient.cs | 6 +- Tests/Stream/Client/CreateSessionTests.cs | 1 - Tests/Stream/Client/GlobalSuppressions.cs | 8 + Tests/Stream/Client/StreamWrapperTests.cs | 3 + Tests/Stream/Client/SubmitterExt.cs | 23 ++- Utils/src/IQueryableExt.cs | 2 +- 98 files changed, 734 insertions(+), 790 deletions(-) create mode 100644 Base/src/QueueMessageStatus.cs create mode 100644 Tests/Bench/Server/src/GlobalSuppressions.cs create mode 100644 Tests/Stream/Client/GlobalSuppressions.cs diff --git a/Adaptors/Amqp/src/ConnectionAmqp.cs b/Adaptors/Amqp/src/ConnectionAmqp.cs index 56277742a..80ceb3a58 100644 --- a/Adaptors/Amqp/src/ConnectionAmqp.cs +++ b/Adaptors/Amqp/src/ConnectionAmqp.cs @@ -53,24 +53,18 @@ public ConnectionAmqp(QueueCommon.Amqp options, public Connection? Connection { get; private set; } public Task Check(HealthCheckTag tag) - { - switch (tag) + => tag switch { - case HealthCheckTag.Startup: - case HealthCheckTag.Readiness: - return Task.FromResult(isInitialized_ - ? HealthCheckResult.Healthy() - : HealthCheckResult.Unhealthy($"{nameof(ConnectionAmqp)} is not yet initialized.")); - case HealthCheckTag.Liveness: - return Task.FromResult(isInitialized_ && Connection is not null && Connection.ConnectionState == ConnectionState.Opened - ? HealthCheckResult.Healthy() - : HealthCheckResult.Unhealthy($"{nameof(ConnectionAmqp)} not initialized or connection dropped.")); - default: - throw new ArgumentOutOfRangeException(nameof(tag), - tag, - null); - } - } + HealthCheckTag.Startup or HealthCheckTag.Readiness => Task.FromResult(isInitialized_ + ? HealthCheckResult.Healthy() + : HealthCheckResult.Unhealthy($"{nameof(ConnectionAmqp)} is not yet initialized.")), + HealthCheckTag.Liveness => Task.FromResult(isInitialized_ && Connection is not null && Connection.ConnectionState == ConnectionState.Opened + ? HealthCheckResult.Healthy() + : HealthCheckResult.Unhealthy($"{nameof(ConnectionAmqp)} not initialized or connection dropped.")), + _ => throw new ArgumentOutOfRangeException(nameof(tag), + tag, + null), + }; public async Task Init(CancellationToken cancellationToken = default) => await connectionTask_; @@ -114,8 +108,7 @@ private static async Task InitTask(ConnectionAmqp conn, conn.Connection = await connectionFactory.CreateAsync(address) .ConfigureAwait(false); conn.Connection.AddClosedCallback((x, - e) => OnCloseConnection(x, - e, + e) => OnCloseConnection(e, conn.logger_)); break; } @@ -137,8 +130,7 @@ await Task.Delay(1000 * retry, conn.isInitialized_ = true; } - private static void OnCloseConnection(IAmqpObject sender, - Error? error, + private static void OnCloseConnection(Error? error, ILogger logger) { if (error == null) @@ -147,7 +139,7 @@ private static void OnCloseConnection(IAmqpObject sender, } else { - logger.LogWarning("AMQP Connection closed with error: {0}", + logger.LogWarning("AMQP Connection closed with error: {error}", error.ToString()); } } diff --git a/Adaptors/Amqp/src/PullQueueStorage.cs b/Adaptors/Amqp/src/PullQueueStorage.cs index 22b0cd1cd..9ace93128 100644 --- a/Adaptors/Amqp/src/PullQueueStorage.cs +++ b/Adaptors/Amqp/src/PullQueueStorage.cs @@ -141,7 +141,6 @@ public async IAsyncEnumerable PullMessagesAsync(int sender, receiver, Encoding.UTF8.GetString(message.Body as byte[] ?? throw new InvalidOperationException("Error while deserializing message")), - logger_, cancellationToken); break; diff --git a/Adaptors/Amqp/src/QueueMessageHandler.cs b/Adaptors/Amqp/src/QueueMessageHandler.cs index 16d74d12e..8dc555c29 100644 --- a/Adaptors/Amqp/src/QueueMessageHandler.cs +++ b/Adaptors/Amqp/src/QueueMessageHandler.cs @@ -30,7 +30,6 @@ namespace ArmoniK.Core.Adapters.Amqp; public class QueueMessageHandler : IQueueMessageHandler { - private readonly ILogger logger_; private readonly Message message_; private readonly IReceiverLink receiver_; private readonly ISenderLink sender_; @@ -39,13 +38,11 @@ public QueueMessageHandler(Message message, ISenderLink sender, IReceiverLink receiver, string taskId, - ILogger logger, CancellationToken cancellationToken) { message_ = message; sender_ = sender; receiver_ = receiver; - logger_ = logger; TaskId = taskId; CancellationToken = cancellationToken; ReceptionDateTime = DateTime.UtcNow; diff --git a/Adaptors/LocalStorage/src/ObjectStorage.cs b/Adaptors/LocalStorage/src/ObjectStorage.cs index 0d540bd84..a870a04bb 100644 --- a/Adaptors/LocalStorage/src/ObjectStorage.cs +++ b/Adaptors/LocalStorage/src/ObjectStorage.cs @@ -80,24 +80,18 @@ public Task Init(CancellationToken cancellationToken) /// public Task Check(HealthCheckTag tag) - { - switch (tag) + => tag switch { - case HealthCheckTag.Startup: - case HealthCheckTag.Readiness: - return Task.FromResult(isInitialized_ - ? HealthCheckResult.Healthy() - : HealthCheckResult.Unhealthy("Local storage not initialized yet.")); - case HealthCheckTag.Liveness: - return Task.FromResult(isInitialized_ && Directory.Exists(path_) - ? HealthCheckResult.Healthy() - : HealthCheckResult.Unhealthy("Local storage not initialized or folder has been deleted.")); - default: - throw new ArgumentOutOfRangeException(nameof(tag), - tag, - null); - } - } + HealthCheckTag.Startup or HealthCheckTag.Readiness => Task.FromResult(isInitialized_ + ? HealthCheckResult.Healthy() + : HealthCheckResult.Unhealthy("Local storage not initialized yet.")), + HealthCheckTag.Liveness => Task.FromResult(isInitialized_ && Directory.Exists(path_) + ? HealthCheckResult.Healthy() + : HealthCheckResult.Unhealthy("Local storage not initialized or folder has been deleted.")), + _ => throw new ArgumentOutOfRangeException(nameof(tag), + tag, + null), + }; /// public async Task AddOrUpdateAsync(string key, diff --git a/Adaptors/LocalStorage/tests/ObjectStorageTests.cs b/Adaptors/LocalStorage/tests/ObjectStorageTests.cs index e4eca5759..48fefd88b 100644 --- a/Adaptors/LocalStorage/tests/ObjectStorageTests.cs +++ b/Adaptors/LocalStorage/tests/ObjectStorageTests.cs @@ -35,7 +35,7 @@ public override void TearDown() RunTests = false; } - public override void GetObjectStorageInstance() + protected override void GetObjectStorageInstance() { var rootPath = Path.Combine(Path.GetTempPath(), $"ArmoniK.{Environment.ProcessId}"); diff --git a/Adaptors/Memory/src/PushQueueStorage.cs b/Adaptors/Memory/src/PushQueueStorage.cs index 8fe6addb0..02fcb95d2 100644 --- a/Adaptors/Memory/src/PushQueueStorage.cs +++ b/Adaptors/Memory/src/PushQueueStorage.cs @@ -54,16 +54,12 @@ public async Task PushMessagesAsync(IEnumerable messages, { var priorityGroups = messages.GroupBy(msgData => msgData.Options.Priority); await Task.WhenAll(priorityGroups.Select(group => PushMessagesAsync(group, - partitionId, - group.Key, - cancellationToken))) + group.Key))) .ConfigureAwait(false); } private Task PushMessagesAsync(IEnumerable messages, - string partitionId, - int priority = 1, - CancellationToken cancellationToken = default) + int priority = 1) { var messageHandlers = messages.Select(message => new MessageHandler { diff --git a/Adaptors/Memory/src/QueueStorage.cs b/Adaptors/Memory/src/QueueStorage.cs index 909e94622..1fb718783 100644 --- a/Adaptors/Memory/src/QueueStorage.cs +++ b/Adaptors/Memory/src/QueueStorage.cs @@ -41,10 +41,6 @@ public class QueueStorage : IQueueStorage private readonly SortedList queues_ = new(MessageComparer.Instance); - /// - public string PartitionId - => ""; - /// public Task Check(HealthCheckTag tag) => Task.FromResult(HealthCheckResult.Healthy()); @@ -57,7 +53,6 @@ public Task Init(CancellationToken cancellationToken) public int MaxPriority => 100; - /// public async IAsyncEnumerable PullMessagesAsync(int nbMessages, [EnumeratorCancellation] CancellationToken cancellationToken = default) { @@ -97,10 +92,11 @@ await message.Semaphore.WaitAsync(CancellationToken.None) /// public Task PushMessagesAsync(IEnumerable messages, - string partitionId, int priority = 1, CancellationToken cancellationToken = default) { + cancellationToken.ThrowIfCancellationRequested(); + var messageHandlers = messages.Select(message => new MessageHandler { IsVisible = true, diff --git a/Adaptors/Memory/src/ResultTable.cs b/Adaptors/Memory/src/ResultTable.cs index 807d6945c..76c736ee1 100644 --- a/Adaptors/Memory/src/ResultTable.cs +++ b/Adaptors/Memory/src/ResultTable.cs @@ -302,18 +302,18 @@ public Task SetTaskOwnership(string sessi throw new SessionNotFoundException($"Session '{session}' not found"); } - foreach (var req in requests) + foreach (var (resultId, taskId) in requests) { - if (!session.TryGetValue(req.resultId, + if (!session.TryGetValue(resultId, out var result)) { - throw new ResultNotFoundException($"Key '{req.resultId}' not found"); + throw new ResultNotFoundException($"Key '{resultId}' not found"); } - session.TryUpdate(req.resultId, + session.TryUpdate(resultId, result with { - OwnerTaskId = req.taskId, + OwnerTaskId = taskId, }, result); } diff --git a/Adaptors/Memory/src/TaskTable.cs b/Adaptors/Memory/src/TaskTable.cs index 43755017f..4497fb48d 100644 --- a/Adaptors/Memory/src/TaskTable.cs +++ b/Adaptors/Memory/src/TaskTable.cs @@ -505,26 +505,4 @@ public Task Check(HealthCheckTag tag) ? HealthCheckResult.Healthy() : HealthCheckResult.Unhealthy()); - private bool UpdateTaskToSubmitted(string id) - { - var updated = false; - taskId2TaskData_.AddOrUpdate(id, - _ => throw new InvalidOperationException("The task does not exist."), - (_, - data) => - { - if (data.Status != TaskStatus.Creating) - { - return data; - } - - updated = true; - return data with - { - Status = TaskStatus.Submitted, - SubmittedDate = DateTime.UtcNow, - }; - }); - return updated; - } } diff --git a/Adaptors/MongoDB/src/AuthenticationTable.cs b/Adaptors/MongoDB/src/AuthenticationTable.cs index 4898ce779..e5e791b05 100644 --- a/Adaptors/MongoDB/src/AuthenticationTable.cs +++ b/Adaptors/MongoDB/src/AuthenticationTable.cs @@ -168,7 +168,7 @@ await sessionProvider_.Init(cancellationToken) return (await GetIdentityFromPipelineAsync(sessionHandle, authCollection, GetAuthToIdentityPipeline(), - auth => auth.CN == cn && (auth.Fingerprint == fingerprint || auth.Fingerprint == null), + auth => auth.Cn == cn && (auth.Fingerprint == fingerprint || auth.Fingerprint == null), cancellationToken) .ConfigureAwait(false))?.ToUserAuthenticationResult(); } diff --git a/Adaptors/MongoDB/src/Common/MongoCollectionProvider.cs b/Adaptors/MongoDB/src/Common/MongoCollectionProvider.cs index c7dfc1b96..c2006360a 100644 --- a/Adaptors/MongoDB/src/Common/MongoCollectionProvider.cs +++ b/Adaptors/MongoDB/src/Common/MongoCollectionProvider.cs @@ -37,7 +37,6 @@ public class MongoCollectionProvider : IInitializable, IAs where TModelMapping : IMongoDataModelMapping, new() { private bool isInitialized_; - private ILogger> logger_; private IMongoCollection? mongoCollection_; public MongoCollectionProvider(Options.MongoDB options, @@ -52,8 +51,6 @@ public MongoCollectionProvider(Options.MongoDB options, $"{nameof(Options.MongoDB.DataRetention)} is not defined."); } - logger_ = logger; - Initialization = InitializeAsync(options, sessionProvider, mongoDatabase, @@ -66,24 +63,18 @@ public MongoCollectionProvider(Options.MongoDB options, /// public Task Check(HealthCheckTag tag) - { - switch (tag) + => tag switch { - case HealthCheckTag.Startup: - case HealthCheckTag.Readiness: - return Task.FromResult(isInitialized_ - ? HealthCheckResult.Healthy() - : HealthCheckResult.Unhealthy("MongoCollection not initialized yet.")); - case HealthCheckTag.Liveness: - return Task.FromResult(isInitialized_ && mongoCollection_ is null - ? HealthCheckResult.Healthy() - : HealthCheckResult.Unhealthy("MongoCollection not initialized yet.")); - default: - throw new ArgumentOutOfRangeException(nameof(tag), - tag, - null); - } - } + HealthCheckTag.Startup or HealthCheckTag.Readiness => Task.FromResult(isInitialized_ + ? HealthCheckResult.Healthy() + : HealthCheckResult.Unhealthy("MongoCollection not initialized yet.")), + HealthCheckTag.Liveness => Task.FromResult(isInitialized_ && mongoCollection_ is null + ? HealthCheckResult.Healthy() + : HealthCheckResult.Unhealthy("MongoCollection not initialized yet.")), + _ => throw new ArgumentOutOfRangeException(nameof(tag), + tag, + null), + }; /// public async Task Init(CancellationToken cancellationToken) diff --git a/Adaptors/MongoDB/src/Common/SessionProvider.cs b/Adaptors/MongoDB/src/Common/SessionProvider.cs index e3b0e937b..65140238e 100644 --- a/Adaptors/MongoDB/src/Common/SessionProvider.cs +++ b/Adaptors/MongoDB/src/Common/SessionProvider.cs @@ -42,24 +42,18 @@ public SessionProvider(IMongoClient client) => client_ = client; public Task Check(HealthCheckTag tag) - { - switch (tag) + => tag switch { - case HealthCheckTag.Readiness: - case HealthCheckTag.Startup: - return Task.FromResult(clientSessionHandle_ is not null - ? HealthCheckResult.Healthy() - : HealthCheckResult.Degraded($"{nameof(clientSessionHandle_)} is still null")); - case HealthCheckTag.Liveness: - return Task.FromResult(clientSessionHandle_ is not null && client_.Cluster.Description.State == ClusterState.Connected - ? HealthCheckResult.Healthy() - : HealthCheckResult.Unhealthy("Connection to MongoDB cluster dropped.")); - default: - throw new ArgumentOutOfRangeException(nameof(tag), - tag, - null); - } - } + HealthCheckTag.Readiness or HealthCheckTag.Startup => Task.FromResult(clientSessionHandle_ is not null + ? HealthCheckResult.Healthy() + : HealthCheckResult.Degraded($"{nameof(clientSessionHandle_)} is still null")), + HealthCheckTag.Liveness => Task.FromResult(clientSessionHandle_ is not null && client_.Cluster.Description.State == ClusterState.Connected + ? HealthCheckResult.Healthy() + : HealthCheckResult.Unhealthy("Connection to MongoDB cluster dropped.")), + _ => throw new ArgumentOutOfRangeException(nameof(tag), + tag, + null), + }; public Task Init(CancellationToken cancellationToken) { diff --git a/Adaptors/MongoDB/src/IMongoQueryableExt.cs b/Adaptors/MongoDB/src/IMongoQueryableExt.cs index b877fde2d..a5e828f7a 100644 --- a/Adaptors/MongoDB/src/IMongoQueryableExt.cs +++ b/Adaptors/MongoDB/src/IMongoQueryableExt.cs @@ -46,7 +46,7 @@ public static async IAsyncEnumerable ToAsyncEnumerable(this } - public static async IAsyncEnumerable ToAsyncEnumerable(this IFindFluent findFluent, + public static async IAsyncEnumerable ToAsyncEnumerable(this IFindFluent findFluent, [EnumeratorCancellation] CancellationToken cancellationToken = default) { var cursor = await findFluent.ToCursorAsync(cancellationToken) diff --git a/Adaptors/MongoDB/src/ObjectStorage.cs b/Adaptors/MongoDB/src/ObjectStorage.cs index 8abaa50a5..906561614 100644 --- a/Adaptors/MongoDB/src/ObjectStorage.cs +++ b/Adaptors/MongoDB/src/ObjectStorage.cs @@ -145,8 +145,7 @@ async IAsyncEnumerable IObjectStorage.GetValuesAsync(string .Where(odm => odm.Key == objectStorageName_ + key) .OrderBy(odm => odm.ChunkIdx) .Select(odm => odm.Chunk) - .ToAsyncEnumerable() - .WithCancellation(cancellationToken) + .ToAsyncEnumerable(cancellationToken) .ConfigureAwait(false)) { throwException = false; @@ -182,8 +181,7 @@ public async IAsyncEnumerable ListKeysAsync([EnumeratorCancellation] Can await foreach (var key in objectCollection.AsQueryable(sessionHandle) .Where(odm => odm.ChunkIdx == 0) .Select(odm => odm.Key) - .ToAsyncEnumerable() - .WithCancellation(cancellationToken) + .ToAsyncEnumerable(cancellationToken) .ConfigureAwait(false)) { yield return key; diff --git a/Adaptors/MongoDB/src/PartitionTable.cs b/Adaptors/MongoDB/src/PartitionTable.cs index 592b6374b..853450ebf 100644 --- a/Adaptors/MongoDB/src/PartitionTable.cs +++ b/Adaptors/MongoDB/src/PartitionTable.cs @@ -126,7 +126,7 @@ public IAsyncEnumerable GetPartitionWithAllocationAsync(Cancellat return taskCollection.AsQueryable(sessionHandle) .Where(tdm => tdm.PodMax > 0) - .ToAsyncEnumerable(); + .ToAsyncEnumerable(cancellationToken); } /// diff --git a/Adaptors/MongoDB/src/ResultTable.cs b/Adaptors/MongoDB/src/ResultTable.cs index e89de729f..3b0b64c32 100644 --- a/Adaptors/MongoDB/src/ResultTable.cs +++ b/Adaptors/MongoDB/src/ResultTable.cs @@ -355,7 +355,7 @@ public async Task SetTaskOwnership(string cancellationToken: cancellationToken) .ConfigureAwait(false); - if (res.ModifiedCount != requests.Count()) + if (res.ModifiedCount != requests.Count) { throw new ResultNotFoundException("One of the requested result was not found"); } @@ -450,7 +450,6 @@ public async IAsyncEnumerable ListResultsAsync(string await foreach (var result in resultCollection.Find(model => model.SessionId == sessionId) .Project(model => model.ResultId) .ToAsyncEnumerable(cancellationToken) - .WithCancellation(cancellationToken) .ConfigureAwait(false)) { yield return result; diff --git a/Adaptors/MongoDB/src/ServiceCollectionExt.cs b/Adaptors/MongoDB/src/ServiceCollectionExt.cs index f0f8c50fd..1e1ba127f 100644 --- a/Adaptors/MongoDB/src/ServiceCollectionExt.cs +++ b/Adaptors/MongoDB/src/ServiceCollectionExt.cs @@ -221,12 +221,10 @@ public static IServiceCollection AddMongoClient(this IServiceCollection services /// /// Services /// Configuration - /// Logger /// Services [PublicAPI] public static IServiceCollection AddClientSubmitterAuthenticationStorage(this IServiceCollection services, - ConfigurationManager configuration, - ILogger logger) + ConfigurationManager configuration) { var components = configuration.GetSection(Components.SettingSection); if (components[nameof(Components.AuthenticationStorage)] == "ArmoniK.Adapters.MongoDB.AuthenticationTable") @@ -243,13 +241,12 @@ public static IServiceCollection AddClientSubmitterAuthenticationStorage(this IS /// /// Services /// Configuration - /// Logger /// Created authentication cache + /// /// Services [PublicAPI] public static IServiceCollection AddClientSubmitterAuthServices(this IServiceCollection services, - ConfigurationManager configuration, - ILogger logger, + ConfigurationManager configuration, out AuthenticationCache authCache) { authCache = new AuthenticationCache(); diff --git a/Adaptors/MongoDB/src/Table/DataModel/Auth/AuthDataModelMapping.cs b/Adaptors/MongoDB/src/Table/DataModel/Auth/AuthDataModelMapping.cs index b870d7a35..0a659feb7 100644 --- a/Adaptors/MongoDB/src/Table/DataModel/Auth/AuthDataModelMapping.cs +++ b/Adaptors/MongoDB/src/Table/DataModel/Auth/AuthDataModelMapping.cs @@ -43,14 +43,14 @@ static AuthDataModelMapping() cm.MapProperty(nameof(AuthData.UserId)) .SetIsRequired(true) .SetSerializer(IdSerializer.Instance); - cm.MapProperty(nameof(AuthData.CN)) + cm.MapProperty(nameof(AuthData.Cn)) .SetIsRequired(true); cm.MapProperty(nameof(AuthData.Fingerprint)) .SetDefaultValue(BsonNull.Value); cm.SetIgnoreExtraElements(true); cm.MapCreator(model => new AuthData(model.AuthId, model.UserId, - model.CN, + model.Cn, model.Fingerprint)); }); } @@ -68,7 +68,7 @@ public async Task InitializeIndexesAsync(IClientSessionHandle sessionHandl var indexModels = new[] { IndexHelper.CreateUniqueIndex((IndexType.Descending, model => model.Fingerprint), - (IndexType.Ascending, model => model.CN)), + (IndexType.Ascending, model => model.Cn)), IndexHelper.CreateHashedIndex(model => model.Fingerprint), IndexHelper.CreateHashedIndex(model => model.UserId), }; diff --git a/Adaptors/MongoDB/src/Table/DataModel/Auth/PipelineIntermediates.cs b/Adaptors/MongoDB/src/Table/DataModel/Auth/PipelineIntermediates.cs index 814507c86..1459f0532 100644 --- a/Adaptors/MongoDB/src/Table/DataModel/Auth/PipelineIntermediates.cs +++ b/Adaptors/MongoDB/src/Table/DataModel/Auth/PipelineIntermediates.cs @@ -29,14 +29,14 @@ namespace ArmoniK.Core.Adapters.MongoDB.Table.DataModel.Auth; /// /// Certificate ID /// User ID -/// Common Name +/// Common Name /// Certificate Fingerprint /// List of users that have the id UserId [BsonIgnoreExtraElements] public record AuthDataAfterLookup([property: BsonId] ObjectId AuthId, ObjectId UserId, - string CN, + string Cn, string Fingerprint, UserData[] UserData); diff --git a/Adaptors/MongoDB/tests/BsonSerializerTest.cs b/Adaptors/MongoDB/tests/BsonSerializerTest.cs index ab24cb656..31e4bd0fe 100644 --- a/Adaptors/MongoDB/tests/BsonSerializerTest.cs +++ b/Adaptors/MongoDB/tests/BsonSerializerTest.cs @@ -307,8 +307,8 @@ public void SerializeAuthDataModel() deserialized.AuthId); Assert.AreEqual(adm.UserId, deserialized.UserId); - Assert.AreEqual(adm.CN, - deserialized.CN); + Assert.AreEqual(adm.Cn, + deserialized.Cn); Assert.AreEqual(adm.Fingerprint, deserialized.Fingerprint); } diff --git a/Adaptors/MongoDB/tests/ExpressionsBuildersFieldFilterExpressionTests.cs b/Adaptors/MongoDB/tests/ExpressionsBuildersFieldFilterExpressionTests.cs index dd8693921..186d021f1 100644 --- a/Adaptors/MongoDB/tests/ExpressionsBuildersFieldFilterExpressionTests.cs +++ b/Adaptors/MongoDB/tests/ExpressionsBuildersFieldFilterExpressionTests.cs @@ -32,7 +32,7 @@ namespace ArmoniK.Core.Adapters.MongoDB.Tests; [TestFixture(TestOf = typeof(ExpressionsBuilders))] internal class ExpressionsBuildersFieldFilterExpressionTests { - private static readonly TaskOptions _taskOptions = new(new Dictionary(), + private static readonly TaskOptions TaskOptions = new(new Dictionary(), TimeSpan.Zero, 0, 0, @@ -73,7 +73,7 @@ public void ShouldRecognizeSession() }, Array.Empty(), TaskStatus.Completed, - _taskOptions, + TaskOptions, new Output(true, "")); @@ -109,7 +109,7 @@ public void ShouldRejectOtherSession() }, Array.Empty(), TaskStatus.Completed, - _taskOptions, + TaskOptions, new Output(true, "")); @@ -146,7 +146,7 @@ public void ShouldExcludeSession() }, Array.Empty(), TaskStatus.Completed, - _taskOptions, + TaskOptions, new Output(true, "")); @@ -183,7 +183,7 @@ public void ShouldIncludeOtherSession() }, Array.Empty(), TaskStatus.Completed, - _taskOptions, + TaskOptions, new Output(true, "")); @@ -220,7 +220,7 @@ public void ShouldRecognizeStatus() }, Array.Empty(), TaskStatus.Completed, - _taskOptions, + TaskOptions, new Output(true, "")); @@ -257,7 +257,7 @@ public void ShouldExcludeStatus() }, Array.Empty(), TaskStatus.Completed, - _taskOptions, + TaskOptions, new Output(true, "")); @@ -294,7 +294,7 @@ public void ShouldRecognizeMultipleStatus() }, Array.Empty(), TaskStatus.Completed, - _taskOptions, + TaskOptions, new Output(true, "")); @@ -332,7 +332,7 @@ public void ShouldExcludeMultipleStatus() }, Array.Empty(), TaskStatus.Completed, - _taskOptions, + TaskOptions, new Output(true, "")); @@ -368,7 +368,7 @@ public void ShouldRejectOtherStatus() }, Array.Empty(), TaskStatus.Cancelled, - _taskOptions, + TaskOptions, new Output(true, "")); @@ -405,7 +405,7 @@ public void ShouldIncludeOtherStatus() }, Array.Empty(), TaskStatus.Cancelled, - _taskOptions, + TaskOptions, new Output(true, "")); @@ -442,7 +442,7 @@ public void ShouldRejectOtherMultipleStatus() }, Array.Empty(), TaskStatus.Cancelled, - _taskOptions, + TaskOptions, new Output(true, "")); @@ -480,7 +480,7 @@ public void ShouldIncludeOtherMultipleStatus() }, Array.Empty(), TaskStatus.Cancelled, - _taskOptions, + TaskOptions, new Output(true, "")); @@ -516,7 +516,7 @@ public void ShouldRecognizeTask() }, Array.Empty(), TaskStatus.Cancelled, - _taskOptions, + TaskOptions, new Output(true, "")); @@ -553,7 +553,7 @@ public void ShouldExcludeTask() }, Array.Empty(), TaskStatus.Cancelled, - _taskOptions, + TaskOptions, new Output(true, "")); @@ -590,7 +590,7 @@ public void ShouldRecognizeMultipleTask() }, Array.Empty(), TaskStatus.Cancelled, - _taskOptions, + TaskOptions, new Output(true, "")); @@ -628,7 +628,7 @@ public void ShouldExcludeMultipleTask() }, Array.Empty(), TaskStatus.Cancelled, - _taskOptions, + TaskOptions, new Output(true, "")); @@ -664,7 +664,7 @@ public void ShouldRejectOtherTask() }, Array.Empty(), TaskStatus.Cancelled, - _taskOptions, + TaskOptions, new Output(true, "")); @@ -701,7 +701,7 @@ public void ShouldIncludeOtherTask() }, Array.Empty(), TaskStatus.Cancelled, - _taskOptions, + TaskOptions, new Output(true, "")); @@ -738,7 +738,7 @@ public void ShouldRejectOtherMultipleTask() }, Array.Empty(), TaskStatus.Cancelled, - _taskOptions, + TaskOptions, new Output(true, "")); @@ -776,7 +776,7 @@ public void ShouldIncludeOtherMultipleTask() }, Array.Empty(), TaskStatus.Cancelled, - _taskOptions, + TaskOptions, new Output(true, "")); diff --git a/Adaptors/MongoDB/tests/IndexTest.cs b/Adaptors/MongoDB/tests/IndexTest.cs index e8206fa8d..53af2ce77 100644 --- a/Adaptors/MongoDB/tests/IndexTest.cs +++ b/Adaptors/MongoDB/tests/IndexTest.cs @@ -46,9 +46,11 @@ public void StartUp() var options = new MongoRunnerOptions { UseSingleNodeReplicaSet = false, - StandardOuputLogger = line => logger.LogInformation(line), - StandardErrorLogger = line => logger.LogError(line), - }; +#pragma warning disable CA2254 // log inputs should be constant + StandardOuputLogger = line => logger.LogInformation(line), + StandardErrorLogger = line => logger.LogError(line), +#pragma warning restore CA2254 + }; runner_ = MongoRunner.Run(options); client_ = new MongoClient(runner_.ConnectionString); @@ -237,10 +239,10 @@ public void GenericIndexCreationShouldSucceed() { IndexHelper.CreateIndex(IndexType.Hashed, model => model.Fingerprint), - IndexHelper.CreateUniqueIndex((IndexType.Ascending, model => model.CN), + IndexHelper.CreateUniqueIndex((IndexType.Ascending, model => model.Cn), (IndexType.Descending, model => model.Fingerprint)), IndexHelper.CreateIndex((IndexType.Hashed, model => model.UserId)), - IndexHelper.CreateUniqueIndex((IndexType.Text, model => model.CN)), + IndexHelper.CreateUniqueIndex((IndexType.Text, model => model.Cn)), }; collection.Indexes.CreateMany(indexModels); diff --git a/Adaptors/MongoDB/tests/MongoDatabaseProvider.cs b/Adaptors/MongoDB/tests/MongoDatabaseProvider.cs index 93d7e121a..6c516b9ad 100644 --- a/Adaptors/MongoDB/tests/MongoDatabaseProvider.cs +++ b/Adaptors/MongoDB/tests/MongoDatabaseProvider.cs @@ -55,9 +55,11 @@ public MongoDatabaseProvider(bool useSingleNodeReplicaSet var options = new MongoRunnerOptions { UseSingleNodeReplicaSet = useSingleNodeReplicaSet, - StandardOuputLogger = line => logger.LogInformation(line), - StandardErrorLogger = line => logger.LogError(line), - ReplicaSetSetupTimeout = TimeSpan.FromSeconds(30), +#pragma warning disable CA2254 // log inputs should be constant + StandardOuputLogger = line => logger.LogInformation(line), + StandardErrorLogger = line => logger.LogError(line), +#pragma warning restore CA2254 + ReplicaSetSetupTimeout = TimeSpan.FromSeconds(30), }; runner_ = MongoRunner.Run(options); @@ -101,8 +103,7 @@ public MongoDatabaseProvider(bool useSingleNodeReplicaSet var serviceCollection = new ServiceCollection(); serviceCollection.AddMongoStorages(configuration, logger); - serviceCollection.AddClientSubmitterAuthenticationStorage(configuration, - logger); + serviceCollection.AddClientSubmitterAuthenticationStorage(configuration); serviceCollection.AddSingleton(ActivitySource); serviceCollection.AddTransient(_ => client); diff --git a/Adaptors/MongoDB/tests/ObjectStorageTests.cs b/Adaptors/MongoDB/tests/ObjectStorageTests.cs index 848c671ec..bb1ca1a83 100644 --- a/Adaptors/MongoDB/tests/ObjectStorageTests.cs +++ b/Adaptors/MongoDB/tests/ObjectStorageTests.cs @@ -36,7 +36,7 @@ public override void TearDown() private MongoDatabaseProvider? tableProvider_; - public override void GetObjectStorageInstance() + protected override void GetObjectStorageInstance() { tableProvider_ = new MongoDatabaseProvider(serviceConfigurator: collection => collection.AddSingleton()); var provider = tableProvider_.GetServiceProvider(); diff --git a/Adaptors/MongoDB/tests/SessionProviderTests.cs b/Adaptors/MongoDB/tests/SessionProviderTests.cs index 4e9501022..8c2baea8c 100644 --- a/Adaptors/MongoDB/tests/SessionProviderTests.cs +++ b/Adaptors/MongoDB/tests/SessionProviderTests.cs @@ -57,9 +57,11 @@ public void SetUp() var options = new MongoRunnerOptions { UseSingleNodeReplicaSet = false, - StandardOuputLogger = line => logger.LogInformation(line), - StandardErrorLogger = line => logger.LogError(line), - }; +#pragma warning disable CA2254 // log inputs should be constant + StandardOuputLogger = line => logger.LogInformation(line), + StandardErrorLogger = line => logger.LogError(line), +#pragma warning restore CA2254 + }; runner_ = MongoRunner.Run(options); client_ = new MongoClient(runner_.ConnectionString); diff --git a/Adaptors/RabbitMQ/src/ConnectionRabbit.cs b/Adaptors/RabbitMQ/src/ConnectionRabbit.cs index c4c5b11f7..d5da38162 100644 --- a/Adaptors/RabbitMQ/src/ConnectionRabbit.cs +++ b/Adaptors/RabbitMQ/src/ConnectionRabbit.cs @@ -60,24 +60,18 @@ public async Task Init(CancellationToken cancellationToken = default) => await connectionTask_; public Task Check(HealthCheckTag tag) - { - switch (tag) + => tag switch { - case HealthCheckTag.Startup: - case HealthCheckTag.Readiness: - return Task.FromResult(isInitialized_ - ? HealthCheckResult.Healthy() - : HealthCheckResult.Unhealthy($"{nameof(ConnectionRabbit)} is not yet initialized.")); - case HealthCheckTag.Liveness: - return Task.FromResult(isInitialized_ && Connection is not null && Connection.IsOpen && Channel is not null && Channel.IsOpen - ? HealthCheckResult.Healthy() - : HealthCheckResult.Unhealthy($"{nameof(ConnectionRabbit)} not initialized or connection dropped.")); - default: - throw new ArgumentOutOfRangeException(nameof(tag), - tag, - null); - } - } + HealthCheckTag.Startup or HealthCheckTag.Readiness => Task.FromResult(isInitialized_ + ? HealthCheckResult.Healthy() + : HealthCheckResult.Unhealthy($"{nameof(ConnectionRabbit)} is not yet initialized.")), + HealthCheckTag.Liveness => Task.FromResult(isInitialized_ && Connection is not null && Connection.IsOpen && Channel is not null && Channel.IsOpen + ? HealthCheckResult.Healthy() + : HealthCheckResult.Unhealthy($"{nameof(ConnectionRabbit)} not initialized or connection dropped.")), + _ => throw new ArgumentOutOfRangeException(nameof(tag), + tag, + null), + }; public void Dispose() { @@ -135,15 +129,13 @@ private async Task InitTask(ConnectionRabbit conn, { conn.Connection = factory.CreateConnection(); conn.Connection.ConnectionShutdown += (obj, - ea) => OnShutDown(obj, - ea, + ea) => OnShutDown(ea, "Connection", logger_); Channel = conn.Connection.CreateModel(); Channel.ModelShutdown += (obj, - ea) => OnShutDown(obj, - ea, + ea) => OnShutDown(ea, "Channel", logger_); break; @@ -166,18 +158,18 @@ await Task.Delay(1000 * retry, conn.isInitialized_ = true; } - private static void OnShutDown(object? obj, - ShutdownEventArgs ea, + private static void OnShutDown(ShutdownEventArgs ea, string model, ILogger logger) { if (ea.Cause is null) { - logger.LogInformation($"RabbitMQ {model} closed with no error"); + logger.LogInformation("RabbitMQ {model} closed with no error", model); } else { - logger.LogWarning($"RabbitMQ {model} closed with error: {0}", + logger.LogWarning("RabbitMQ {model} closed with error: {error}", + model, ea.Cause); } } diff --git a/Adaptors/RabbitMQ/src/PullQueueStorage.cs b/Adaptors/RabbitMQ/src/PullQueueStorage.cs index c3e82e712..650dc3fd7 100644 --- a/Adaptors/RabbitMQ/src/PullQueueStorage.cs +++ b/Adaptors/RabbitMQ/src/PullQueueStorage.cs @@ -149,7 +149,6 @@ Task Subscriber(object? model, queueMessageHandlers_.Enqueue(new QueueMessageHandler(ConnectionRabbit.Channel!, eventArgs, message, - logger_, cancellationToken)); return Task.CompletedTask; } diff --git a/Adaptors/RabbitMQ/src/QueueMessageHandler.cs b/Adaptors/RabbitMQ/src/QueueMessageHandler.cs index 12cc574e1..abae5b31f 100644 --- a/Adaptors/RabbitMQ/src/QueueMessageHandler.cs +++ b/Adaptors/RabbitMQ/src/QueueMessageHandler.cs @@ -32,15 +32,12 @@ public class QueueMessageHandler : IQueueMessageHandler { private readonly IModel channel_; private readonly BasicDeliverEventArgs deliverEvent_; - private readonly ILogger logger_; public QueueMessageHandler(IModel channel, BasicDeliverEventArgs deliverEvent, string taskId, - ILogger logger, CancellationToken cancellationToken) { - logger_ = logger; TaskId = taskId; deliverEvent_ = deliverEvent; CancellationToken = cancellationToken; diff --git a/Adaptors/Redis/src/ObjectStorage.cs b/Adaptors/Redis/src/ObjectStorage.cs index acaa6f628..b966b711b 100644 --- a/Adaptors/Redis/src/ObjectStorage.cs +++ b/Adaptors/Redis/src/ObjectStorage.cs @@ -73,24 +73,18 @@ await redis_.PingAsync() /// public Task Check(HealthCheckTag tag) - { - switch (tag) + => tag switch { - case HealthCheckTag.Startup: - case HealthCheckTag.Readiness: - return Task.FromResult(isInitialized_ - ? HealthCheckResult.Healthy() - : HealthCheckResult.Unhealthy("Redis not initialized yet.")); - case HealthCheckTag.Liveness: - return Task.FromResult(isInitialized_ && redis_.Multiplexer.IsConnected - ? HealthCheckResult.Healthy() - : HealthCheckResult.Unhealthy("Redis not initialized or connection dropped.")); - default: - throw new ArgumentOutOfRangeException(nameof(tag), - tag, - null); - } - } + HealthCheckTag.Startup or HealthCheckTag.Readiness => Task.FromResult(isInitialized_ + ? HealthCheckResult.Healthy() + : HealthCheckResult.Unhealthy("Redis not initialized yet.")), + HealthCheckTag.Liveness => Task.FromResult(isInitialized_ && redis_.Multiplexer.IsConnected + ? HealthCheckResult.Healthy() + : HealthCheckResult.Unhealthy("Redis not initialized or connection dropped.")), + _ => throw new ArgumentOutOfRangeException(nameof(tag), + tag, + null), + }; /// public async Task AddOrUpdateAsync(string key, diff --git a/Adaptors/Redis/tests/ObjectStorageTests.cs b/Adaptors/Redis/tests/ObjectStorageTests.cs index cf3099547..928fa45f7 100644 --- a/Adaptors/Redis/tests/ObjectStorageTests.cs +++ b/Adaptors/Redis/tests/ObjectStorageTests.cs @@ -45,7 +45,7 @@ public override void TearDown() private RedisInside.Redis? redis_; - public override void GetObjectStorageInstance() + protected override void GetObjectStorageInstance() { redis_ = new RedisInside.Redis(configuration => configuration.Port(Random.Shared.Next(1000, 2000))); diff --git a/Adaptors/S3/src/ObjectStorage.cs b/Adaptors/S3/src/ObjectStorage.cs index 09ab4a18d..8f3088d91 100644 --- a/Adaptors/S3/src/ObjectStorage.cs +++ b/Adaptors/S3/src/ObjectStorage.cs @@ -76,24 +76,18 @@ await AmazonS3Util.DoesS3BucketExistV2Async(s3Client_, /// public Task Check(HealthCheckTag tag) - { - switch (tag) + => tag switch { - case HealthCheckTag.Startup: - case HealthCheckTag.Readiness: - return Task.FromResult(isInitialized_ - ? HealthCheckResult.Healthy() - : HealthCheckResult.Unhealthy("S3 not initialized yet.")); - case HealthCheckTag.Liveness: - return Task.FromResult(isInitialized_ - ? HealthCheckResult.Healthy() - : HealthCheckResult.Unhealthy("S3 not initialized or connection dropped.")); - default: - throw new ArgumentOutOfRangeException(nameof(tag), - tag, - null); - } - } + HealthCheckTag.Startup or HealthCheckTag.Readiness => Task.FromResult(isInitialized_ + ? HealthCheckResult.Healthy() + : HealthCheckResult.Unhealthy("S3 not initialized yet.")), + HealthCheckTag.Liveness => Task.FromResult(isInitialized_ + ? HealthCheckResult.Healthy() + : HealthCheckResult.Unhealthy("S3 not initialized or connection dropped.")), + _ => throw new ArgumentOutOfRangeException(nameof(tag), + tag, + null), + }; /// public async Task AddOrUpdateAsync(string key, @@ -154,8 +148,7 @@ public async IAsyncEnumerable GetValuesAsync(string foreach (var chunkTask in Enumerable.Range(0, valuesCount) .Select(index => s3Client_.StringByteGetAsync(bucketName_, - $"{objectStorageName_}{key}_{index}", - logger_)) + $"{objectStorageName_}{key}_{index}")) .ToList()) { yield return (await chunkTask.ConfigureAwait(false))!; @@ -168,8 +161,7 @@ public async Task TryDeleteAsync(string key, { using var _ = logger_.LogFunction(objectStorageName_ + key); var value = await s3Client_.StringGetValueAsync(bucketName_, - $"{objectStorageName_}{key}_count", - logger_) + $"{objectStorageName_}{key}_count") .ConfigureAwait(false); if (value == null) @@ -256,10 +248,9 @@ internal static Task WriteStringAsync(this AmazonS3Client s3C return s3Client.PutObjectAsync(requestCount); } - internal static async Task StringByteGetAsync(this AmazonS3Client s3Client, - string bucketName, - string key, - ILogger logger) + internal static async Task StringByteGetAsync(this AmazonS3Client s3Client, + string bucketName, + string key) { var request = new GetObjectRequest { @@ -274,10 +265,9 @@ internal static async Task StringByteGetAsync(this AmazonS3Client s3C return fileContent; } - internal static async Task StringGetValueAsync(this AmazonS3Client s3Client, - string bucketName, - string key, - ILogger logger) + internal static async Task StringGetValueAsync(this AmazonS3Client s3Client, + string bucketName, + string key) { var response = await s3Client.GetObjectAsync(bucketName, key); diff --git a/Adaptors/S3/tests/ObjectStorageTests.cs b/Adaptors/S3/tests/ObjectStorageTests.cs index d2aa7376a..261a53643 100644 --- a/Adaptors/S3/tests/ObjectStorageTests.cs +++ b/Adaptors/S3/tests/ObjectStorageTests.cs @@ -35,7 +35,7 @@ public override void TearDown() RunTests = false; } - public override void GetObjectStorageInstance() + protected override void GetObjectStorageInstance() { Dictionary minimalConfig = new() { diff --git a/Base/src/IQueueMessageHandler.cs b/Base/src/IQueueMessageHandler.cs index 5c81bdbfe..ac6e34d4b 100644 --- a/Base/src/IQueueMessageHandler.cs +++ b/Base/src/IQueueMessageHandler.cs @@ -20,17 +20,6 @@ namespace ArmoniK.Core.Base; -public enum QueueMessageStatus -{ - Waiting, - Failed, - Running, - Postponed, - Processed, - Cancelled, - Poisonous, -} - public interface IQueueMessageHandler : IAsyncDisposable { CancellationToken CancellationToken { get; set; } diff --git a/Base/src/QueueMessageStatus.cs b/Base/src/QueueMessageStatus.cs new file mode 100644 index 000000000..54db212e5 --- /dev/null +++ b/Base/src/QueueMessageStatus.cs @@ -0,0 +1,29 @@ +// 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 . + +namespace ArmoniK.Core.Base; + +public enum QueueMessageStatus +{ + Waiting, + Failed, + Running, + Postponed, + Processed, + Cancelled, + Poisonous, +} diff --git a/Common/src/Auth/Authentication/AuthData.cs b/Common/src/Auth/Authentication/AuthData.cs index d302ddfe2..70e6adaf3 100644 --- a/Common/src/Auth/Authentication/AuthData.cs +++ b/Common/src/Auth/Authentication/AuthData.cs @@ -22,12 +22,12 @@ namespace ArmoniK.Core.Common.Auth.Authentication; /// /// Unique Id of the entry /// Id of the user this entry refers to -/// Common Name of the certificate(s) +/// Common Name of the certificate(s) /// /// fingerprint of the certificate. If null, this entry matches with every certificates /// matching the Common Name /// public record AuthData(string AuthId, string UserId, - string CN, + string Cn, string? Fingerprint); diff --git a/Common/src/Auth/Authentication/AuthenticationCache.cs b/Common/src/Auth/Authentication/AuthenticationCache.cs index 3f683f3fb..ef28bfd1d 100644 --- a/Common/src/Auth/Authentication/AuthenticationCache.cs +++ b/Common/src/Auth/Authentication/AuthenticationCache.cs @@ -42,7 +42,7 @@ public AuthenticationCacheKey(string connectionId, string? impersonateUsername = "") { ConnectionId = connectionId; - CN = cn ?? ""; + Cn = cn ?? ""; Fingerprint = fingerprint ?? ""; ImpersonateId = impersonateId ?? ""; ImpersonateUsername = impersonateUsername ?? ""; @@ -56,7 +56,7 @@ public AuthenticationCacheKey(string connectionId, /// /// Certificate common name /// - public string CN { get; } + public string Cn { get; } /// /// Certificate fingerprint @@ -87,7 +87,7 @@ public bool Equals(AuthenticationCacheKey? other) return true; } - return ConnectionId == other.ConnectionId && CN == other.CN && Fingerprint == other.Fingerprint && ImpersonateId == other.ImpersonateId && + return ConnectionId == other.ConnectionId && Cn == other.Cn && Fingerprint == other.Fingerprint && ImpersonateId == other.ImpersonateId && ImpersonateUsername == other.ImpersonateUsername; } @@ -111,7 +111,7 @@ public override bool Equals(object? obj) /// public override int GetHashCode() => HashCode.Combine(ConnectionId, - CN, + Cn, Fingerprint, ImpersonateId, ImpersonateUsername); diff --git a/Common/src/Auth/Authentication/Authenticator.cs b/Common/src/Auth/Authentication/Authenticator.cs index 4aa5beb70..f8c3d62bd 100644 --- a/Common/src/Auth/Authentication/Authenticator.cs +++ b/Common/src/Auth/Authentication/Authenticator.cs @@ -211,7 +211,9 @@ protected override async Task HandleAuthenticateAsync() var identity = cache_.Get(cacheKey); if (identity?.Identity is not null) { - logger_.LogInformation($"Found authenticated user {identity.Identity.Name} in cache. Authentication hashkey : {keyHash}."); + logger_.LogInformation("Found authenticated user {username} in cache. Authentication hashkey : {keyHash}.", + identity.Identity.Name, + keyHash); return AuthenticateResult.Success(new AuthenticationTicket(identity, SchemeName)); } @@ -246,7 +248,13 @@ protected override async Task HandleAuthenticateAsync() impersonationId, impersonationUsername) .ConfigureAwait(false); - logger_.LogInformation($"User with id {(prevIdentity.Identity as UserIdentity)!.UserId} and name {(prevIdentity.Identity as UserIdentity)!.UserName} impersonated the user with id {(identity.Identity as UserIdentity)!.UserId} and name {(identity.Identity as UserIdentity)!.UserName}. Authentication key : {keyHash}"); + logger_.LogInformation("User with id {userId} and name {userName} impersonated the user with id {impersonatedId} and name {impersonatedName}. Authentication key : {keyHash}", + (prevIdentity.Identity as UserIdentity)!.UserId, + (prevIdentity.Identity as UserIdentity)!.UserName, + (identity.Identity as UserIdentity)!.UserId, + (identity.Identity as UserIdentity)!.UserName, + keyHash + ); } catch (AuthenticationException e) { diff --git a/Common/src/Pollster/AgentHandler.cs b/Common/src/Pollster/AgentHandler.cs index f24852fba..1fc3dc9e1 100644 --- a/Common/src/Pollster/AgentHandler.cs +++ b/Common/src/Pollster/AgentHandler.cs @@ -42,7 +42,7 @@ namespace ArmoniK.Core.Common.Pollster; /// /// Represents the handler that will provide servers to process requests from worker /// -public class AgentHandler : IAgentHandler, IAsyncDisposable +public sealed class AgentHandler : IAgentHandler, IAsyncDisposable { private readonly WebApplication app_; private readonly ComputePlane computePlaneOptions_; @@ -86,7 +86,7 @@ public AgentHandler(LoggerInit loggerInit, { if (computePlaneOptions.AgentChannel?.Address == null) { - throw new ArgumentNullException(nameof(computePlaneOptions.AgentChannel)); + throw new ArgumentNullException(nameof(computePlaneOptions), $"{nameof(computePlaneOptions.AgentChannel)} is null"); } logger.LogDebug("Agent address is {address}", diff --git a/Common/src/Pollster/Pollster.cs b/Common/src/Pollster/Pollster.cs index 868197346..b29d4c257 100644 --- a/Common/src/Pollster/Pollster.cs +++ b/Common/src/Pollster/Pollster.cs @@ -249,7 +249,7 @@ void RecordError(Exception e) var messages = pullQueueStorage_.PullMessagesAsync(messageBatchSize_, cancellationToken); - await foreach (var message in messages.WithCancellation(cancellationToken) + await foreach (var message in messages .ConfigureAwait(false)) { using var scopedLogger = logger_.BeginNamedScope("Prefetch messageHandler", diff --git a/Common/src/Pollster/TaskHandler.cs b/Common/src/Pollster/TaskHandler.cs index d00311a4e..b35775971 100644 --- a/Common/src/Pollster/TaskHandler.cs +++ b/Common/src/Pollster/TaskHandler.cs @@ -41,7 +41,7 @@ namespace ArmoniK.Core.Common.Pollster; -public class TaskHandler : IAsyncDisposable +public sealed class TaskHandler : IAsyncDisposable { private readonly ActivitySource activitySource_; private readonly IAgentHandler agentHandler_; @@ -629,10 +629,16 @@ private async Task HandleErrorInternalAsync(Exception e, if (cancellationToken.IsCancellationRequested || (requeueIfUnavailable && isWorkerDown)) { - logger_.LogWarning(e, - cancellationToken.IsCancellationRequested - ? "Cancellation triggered, task cancelled here and re executed elsewhere" - : "Worker not available, task cancelled here and re executed elsewhere"); + if (cancellationToken.IsCancellationRequested) + { + logger_.LogWarning(e, + "Cancellation triggered, task cancelled here and re executed elsewhere"); + } + else + { + logger_.LogWarning(e, + "Worker not available, task cancelled here and re executed elsewhere"); + } await taskTable_.ReleaseTask(taskData, CancellationToken.None) @@ -641,25 +647,43 @@ await taskTable_.ReleaseTask(taskData, } else { - logger_.LogError(e, - resubmit - ? "Error during task execution, retrying task" - : "Error during task execution, cancelling task"); - - await submitter_.CompleteTaskAsync(taskData, - resubmit, - new Output - { - Error = new Output.Types.Error - { - Details = e.Message, - }, - }, - CancellationToken.None) - .ConfigureAwait(false); - messageHandler_.Status = resubmit - ? QueueMessageStatus.Cancelled - : QueueMessageStatus.Processed; + if (resubmit) + { + logger_.LogError(e, + "Error during task execution, retrying task"); + + await submitter_.CompleteTaskAsync(taskData, + resubmit, + new Output + { + Error = new Output.Types.Error + { + Details = e.Message, + }, + }, + CancellationToken.None) + .ConfigureAwait(false); + + messageHandler_.Status = QueueMessageStatus.Cancelled; + } + else + { + logger_.LogError(e, + "Error during task execution, cancelling task"); + + await submitter_.CompleteTaskAsync(taskData, + resubmit, + new Output + { + Error = new Output.Types.Error + { + Details = e.Message, + }, + }, + CancellationToken.None) + .ConfigureAwait(false); + messageHandler_.Status = QueueMessageStatus.Processed; + } } } diff --git a/Common/src/StateMachines/UmlMermaidGraphStyle.cs b/Common/src/StateMachines/UmlMermaidGraphStyle.cs index 3f60c0c8e..292c2df11 100644 --- a/Common/src/StateMachines/UmlMermaidGraphStyle.cs +++ b/Common/src/StateMachines/UmlMermaidGraphStyle.cs @@ -85,7 +85,7 @@ public override string FormatOneTransition(string sourceNodeName, { if (bld.Length > 0) { - bld.Append(" "); + bld.Append(' '); } bld.Append(info); diff --git a/Common/src/Utils/LocalIPv4.cs b/Common/src/Utils/LocalIPv4.cs index 1a66c4c5c..5d1aa110c 100644 --- a/Common/src/Utils/LocalIPv4.cs +++ b/Common/src/Utils/LocalIPv4.cs @@ -40,7 +40,7 @@ public class LocalIPv4 /// public static string GetLocalIPv4(NetworkInterfaceType type) { - var output = ""; + var output = string.Empty; foreach (var item in NetworkInterface.GetAllNetworkInterfaces()) { if (item.NetworkInterfaceType == type && item.OperationalStatus == OperationalStatus.Up) @@ -56,7 +56,7 @@ public static string GetLocalIPv4(NetworkInterfaceType type) } } - if (output == "") + if (string.IsNullOrEmpty(output)) { throw new ArmoniKException("No local IPv4 found"); } diff --git a/Common/src/Utils/LoggerInit.cs b/Common/src/Utils/LoggerInit.cs index 67b5d2808..1fee8c8ee 100644 --- a/Common/src/Utils/LoggerInit.cs +++ b/Common/src/Utils/LoggerInit.cs @@ -38,7 +38,7 @@ public LoggerInit(IConfiguration configuration) .Enrich.FromLogContext() .Enrich.WithProperty("CoreVersion", typeof(LoggerInit).Assembly.GetName() - .Version) + .Version!) .CreateLogger(); logger_ = LoggerFactory.Create(builder => builder.AddSerilog(loggerConfiguration_)) diff --git a/Common/src/gRPC/EnumFieldExt.cs b/Common/src/gRPC/EnumFieldExt.cs index bbc295411..ef9a4b09a 100644 --- a/Common/src/gRPC/EnumFieldExt.cs +++ b/Common/src/gRPC/EnumFieldExt.cs @@ -76,8 +76,8 @@ public static class EnumFieldExt TaskSummaryEnumField.ReceivedAt => data => data.ReceptionDate, TaskSummaryEnumField.AcquiredAt => data => data.AcquisitionDate, TaskSummaryEnumField.Error => data => data.Output.Error, - TaskSummaryEnumField.Unspecified => throw new ArgumentOutOfRangeException(), - _ => throw new ArgumentOutOfRangeException(), + TaskSummaryEnumField.Unspecified => throw new ArgumentOutOfRangeException(nameof(enumField)), + _ => throw new ArgumentOutOfRangeException(nameof(enumField)), }; @@ -100,8 +100,8 @@ public static class EnumFieldExt TaskOptionEnumField.ApplicationNamespace => data => data.Options.ApplicationNamespace, TaskOptionEnumField.ApplicationService => data => data.Options.ApplicationService, TaskOptionEnumField.EngineType => data => data.Options.EngineType, - TaskOptionEnumField.Unspecified => throw new ArgumentOutOfRangeException(), - _ => throw new ArgumentOutOfRangeException(), + TaskOptionEnumField.Unspecified => throw new ArgumentOutOfRangeException(nameof(enumField)), + _ => throw new ArgumentOutOfRangeException(nameof(enumField)), }; /// @@ -120,9 +120,9 @@ public static class EnumFieldExt SessionRawEnumField.Options => session => session.Options, SessionRawEnumField.CreatedAt => session => session.CreationDate, SessionRawEnumField.CancelledAt => session => session.CancellationDate, - SessionRawEnumField.Duration => throw new ArgumentOutOfRangeException(), - SessionRawEnumField.Unspecified => throw new ArgumentOutOfRangeException(), - _ => throw new ArgumentOutOfRangeException(), + SessionRawEnumField.Duration => throw new ArgumentOutOfRangeException(nameof(enumField)), + SessionRawEnumField.Unspecified => throw new ArgumentOutOfRangeException(nameof(enumField)), + _ => throw new ArgumentOutOfRangeException(nameof(enumField)), }; /// @@ -144,8 +144,8 @@ public static class EnumFieldExt Api.gRPC.V1.Sessions.TaskOptionEnumField.ApplicationNamespace => data => data.Options.ApplicationNamespace, Api.gRPC.V1.Sessions.TaskOptionEnumField.ApplicationService => data => data.Options.ApplicationService, Api.gRPC.V1.Sessions.TaskOptionEnumField.EngineType => data => data.Options.EngineType, - Api.gRPC.V1.Sessions.TaskOptionEnumField.Unspecified => throw new ArgumentOutOfRangeException(), - _ => throw new ArgumentOutOfRangeException(), + Api.gRPC.V1.Sessions.TaskOptionEnumField.Unspecified => throw new ArgumentOutOfRangeException(nameof(enumField)), + _ => throw new ArgumentOutOfRangeException(nameof(enumField)), }; /// @@ -174,9 +174,9 @@ public static class EnumFieldExt ResultRawEnumField.Status => result => result.Status, ResultRawEnumField.CreatedAt => result => result.CreationDate, ResultRawEnumField.ResultId => result => result.ResultId, - ResultRawEnumField.CompletedAt => throw new ArgumentOutOfRangeException(), - ResultRawEnumField.Unspecified => throw new ArgumentOutOfRangeException(), - _ => throw new ArgumentOutOfRangeException(), + ResultRawEnumField.CompletedAt => throw new ArgumentOutOfRangeException(nameof(enumField)), + ResultRawEnumField.Unspecified => throw new ArgumentOutOfRangeException(nameof(enumField)), + _ => throw new ArgumentOutOfRangeException(nameof(enumField)), }; /// @@ -195,8 +195,8 @@ public static class EnumFieldExt PartitionRawEnumField.PodMax => partitionData => partitionData.PodMax, PartitionRawEnumField.PreemptionPercentage => partitionData => partitionData.PreemptionPercentage, PartitionRawEnumField.Priority => partitionData => partitionData.Priority, - PartitionRawEnumField.Unspecified => throw new ArgumentOutOfRangeException(), - _ => throw new ArgumentOutOfRangeException(), + PartitionRawEnumField.Unspecified => throw new ArgumentOutOfRangeException(nameof(enumField)), + _ => throw new ArgumentOutOfRangeException(nameof(enumField)), }; /// @@ -213,7 +213,7 @@ public static class EnumFieldExt ApplicationRawEnumField.Version => taskData => taskData.Options.ApplicationVersion, ApplicationRawEnumField.Namespace => taskData => taskData.Options.ApplicationNamespace, ApplicationRawEnumField.Service => taskData => taskData.Options.ApplicationService, - ApplicationRawEnumField.Unspecified => throw new ArgumentOutOfRangeException(), - _ => throw new ArgumentOutOfRangeException(), + ApplicationRawEnumField.Unspecified => throw new ArgumentOutOfRangeException(nameof(enumField)), + _ => throw new ArgumentOutOfRangeException(nameof(enumField)), }; } diff --git a/Common/src/gRPC/FilterRangeExt.cs b/Common/src/gRPC/FilterRangeExt.cs index f02cd304a..0a6f12a2e 100644 --- a/Common/src/gRPC/FilterRangeExt.cs +++ b/Common/src/gRPC/FilterRangeExt.cs @@ -51,7 +51,7 @@ public static Expression> ToFilter(this FilterStatusOp FilterStatusOperator.NotEqual => ExpressionBuilders.MakeBinary(field, value, ExpressionType.NotEqual), - _ => throw new ArgumentOutOfRangeException(), + _ => throw new ArgumentOutOfRangeException(nameof(filterOperator)), }; /// @@ -87,7 +87,7 @@ public static Expression> ToFilter(this FilterDateOperator FilterDateOperator.NotEqual => ExpressionBuilders.MakeBinary(field, value, ExpressionType.NotEqual), - _ => throw new ArgumentOutOfRangeException(), + _ => throw new ArgumentOutOfRangeException(nameof(filterOperator)), }; @@ -124,7 +124,7 @@ public static Expression> ToFilter(this FilterNumberOperator FilterNumberOperator.GreaterThan => ExpressionBuilders.MakeBinary(field, value, ExpressionType.GreaterThan), - _ => throw new ArgumentOutOfRangeException(), + _ => throw new ArgumentOutOfRangeException(nameof(filterOperator)), }; @@ -162,7 +162,7 @@ public static Expression> ToFilter(this FilterStringOperator FilterStringOperator.EndsWith => ExpressionBuilders.MakeCallString(field, value, nameof(string.EndsWith)), - _ => throw new ArgumentOutOfRangeException(), + _ => throw new ArgumentOutOfRangeException(nameof(filterOperator)), }; /// @@ -189,7 +189,7 @@ public static Expression> ToFilter(this FilterArrayOperator typeof(Enumerable), nameof(Enumerable.Contains), true), - _ => throw new ArgumentOutOfRangeException(), + _ => throw new ArgumentOutOfRangeException(nameof(filterOperator)), }; /// @@ -210,6 +210,6 @@ public static Expression> ToFilter(this FilterBooleanOperator FilterBooleanOperator.Is => ExpressionBuilders.MakeBinary(field, value, ExpressionType.Equal), - _ => throw new ArgumentOutOfRangeException(), + _ => throw new ArgumentOutOfRangeException(nameof(filterOperator)), }; } diff --git a/Common/src/gRPC/ListApplicationsRequestExt.cs b/Common/src/gRPC/ListApplicationsRequestExt.cs index 08a8323ba..5b8e7ab7f 100644 --- a/Common/src/gRPC/ListApplicationsRequestExt.cs +++ b/Common/src/gRPC/ListApplicationsRequestExt.cs @@ -34,6 +34,7 @@ public static class ListApplicationsRequestExt /// The that access the field from the object /// /// the given message is not recognized + [System.Diagnostics.CodeAnalysis.SuppressMessage("Style", "IDE0066:Convert switch statement to expression", Justification = "Readibility with nested switch")] public static Expression> ToField(this ApplicationField field) { switch (field.FieldCase) @@ -45,13 +46,13 @@ public static class ListApplicationsRequestExt ApplicationRawEnumField.Version => application => application.Version, ApplicationRawEnumField.Namespace => application => application.Namespace, ApplicationRawEnumField.Service => application => application.Service, - ApplicationRawEnumField.Unspecified => throw new ArgumentOutOfRangeException(), - _ => throw new ArgumentOutOfRangeException(), + ApplicationRawEnumField.Unspecified => throw new ArgumentOutOfRangeException(nameof(field)), + _ => throw new ArgumentOutOfRangeException(nameof(field)), }; case ApplicationField.FieldOneofCase.None: default: - throw new ArgumentOutOfRangeException(); + throw new ArgumentOutOfRangeException(nameof(field)); } } @@ -63,6 +64,7 @@ public static class ListApplicationsRequestExt /// The that represents the filter conditions /// /// the given message is not recognized + [System.Diagnostics.CodeAnalysis.SuppressMessage("Style", "IDE0066:Convert switch statement to expression", Justification = "Readibility with nested switch")] public static Expression> ToApplicationFilter(this Filters filters) { Expression> expr = data => false; @@ -88,7 +90,7 @@ public static Expression> ToApplicationFilter(this Filters break; case FilterField.ValueConditionOneofCase.None: default: - throw new ArgumentOutOfRangeException(); + throw new ArgumentOutOfRangeException(nameof(filters)); } } diff --git a/Common/src/gRPC/ListPartitionsRequestExt.cs b/Common/src/gRPC/ListPartitionsRequestExt.cs index fd69ddad3..5fa1b0473 100644 --- a/Common/src/gRPC/ListPartitionsRequestExt.cs +++ b/Common/src/gRPC/ListPartitionsRequestExt.cs @@ -36,24 +36,18 @@ public static class ListPartitionsRequestExt /// /// the given message is not recognized public static Expression> ToField(this ListPartitionsRequest.Types.Sort sort) - { - switch (sort.Field.FieldCase) + => sort.Field.FieldCase switch { - case PartitionField.FieldOneofCase.PartitionRawField: - return sort.Field.PartitionRawField.Field.ToField(); - - case PartitionField.FieldOneofCase.None: - default: - throw new ArgumentOutOfRangeException(); - } - } + PartitionField.FieldOneofCase.PartitionRawField => sort.Field.PartitionRawField.Field.ToField(), + _ => throw new ArgumentOutOfRangeException(nameof(sort)), + }; public static Expression> ToField(this PartitionField taskField) => taskField.FieldCase switch { - PartitionField.FieldOneofCase.None => throw new ArgumentOutOfRangeException(), + PartitionField.FieldOneofCase.None => throw new ArgumentOutOfRangeException(nameof(taskField)), PartitionField.FieldOneofCase.PartitionRawField => taskField.PartitionRawField.Field.ToField(), - _ => throw new ArgumentOutOfRangeException(), + _ => throw new ArgumentOutOfRangeException(nameof(taskField)), }; /// @@ -78,28 +72,18 @@ public static Expression> ToPartitionFilter(this Filte Expression> exprAnd = data => true; foreach (var filterField in filtersAnd.And) { - switch (filterField.ValueConditionCase) + exprAnd = filterField.ValueConditionCase switch { - case FilterField.ValueConditionOneofCase.FilterString: - exprAnd = exprAnd.ExpressionAnd(filterField.FilterString.Operator.ToFilter(filterField.Field.ToField(), - filterField.FilterString.Value)); - break; - case FilterField.ValueConditionOneofCase.FilterNumber: - exprAnd = exprAnd.ExpressionAnd(filterField.FilterNumber.Operator.ToFilter(filterField.Field.ToField(), - filterField.FilterNumber.Value)); - break; - case FilterField.ValueConditionOneofCase.FilterBoolean: - exprAnd = exprAnd.ExpressionAnd(filterField.FilterBoolean.Operator.ToFilter(filterField.Field.ToField(), - filterField.FilterBoolean.Value)); - break; - case FilterField.ValueConditionOneofCase.FilterArray: - exprAnd = exprAnd.ExpressionAnd(filterField.FilterArray.Operator.ToFilter(filterField.Field.ToField(), - filterField.FilterArray.Value)); - break; - case FilterField.ValueConditionOneofCase.None: - default: - throw new ArgumentOutOfRangeException(); - } + FilterField.ValueConditionOneofCase.FilterString => exprAnd.ExpressionAnd(filterField.FilterString.Operator.ToFilter(filterField.Field.ToField(), + filterField.FilterString.Value)), + FilterField.ValueConditionOneofCase.FilterNumber => exprAnd.ExpressionAnd(filterField.FilterNumber.Operator.ToFilter(filterField.Field.ToField(), + filterField.FilterNumber.Value)), + FilterField.ValueConditionOneofCase.FilterBoolean => exprAnd.ExpressionAnd(filterField.FilterBoolean.Operator.ToFilter(filterField.Field.ToField(), + filterField.FilterBoolean.Value)), + FilterField.ValueConditionOneofCase.FilterArray => exprAnd.ExpressionAnd(filterField.FilterArray.Operator.ToFilter(filterField.Field.ToField(), + filterField.FilterArray.Value)), + _ => throw new ArgumentOutOfRangeException(nameof(filters)), + }; } expr = expr.ExpressionOr(exprAnd); diff --git a/Common/src/gRPC/ListResultsRequestExt.cs b/Common/src/gRPC/ListResultsRequestExt.cs index 475ea0425..1edce455b 100644 --- a/Common/src/gRPC/ListResultsRequestExt.cs +++ b/Common/src/gRPC/ListResultsRequestExt.cs @@ -35,23 +35,18 @@ public static class ListResultsRequestExt /// /// the given message is not recognized public static Expression> ToField(this ListResultsRequest.Types.Sort sort) - { - switch (sort.Field.FieldCase) + => sort.Field.FieldCase switch { - case ResultField.FieldOneofCase.ResultRawField: - return sort.Field.ResultRawField.Field.ToField(); - case ResultField.FieldOneofCase.None: - default: - throw new ArgumentOutOfRangeException(); - } - } + ResultField.FieldOneofCase.ResultRawField => sort.Field.ResultRawField.Field.ToField(), + _ => throw new ArgumentOutOfRangeException(nameof(sort)), + }; public static Expression> ToField(this ResultField taskField) => taskField.FieldCase switch { - ResultField.FieldOneofCase.None => throw new ArgumentOutOfRangeException(), + ResultField.FieldOneofCase.None => throw new ArgumentOutOfRangeException(nameof(taskField)), ResultField.FieldOneofCase.ResultRawField => taskField.ResultRawField.Field.ToField(), - _ => throw new ArgumentOutOfRangeException(), + _ => throw new ArgumentOutOfRangeException(nameof(taskField)), }; /// @@ -62,6 +57,7 @@ public static class ListResultsRequestExt /// The that represents the filter conditions /// /// the given message is not recognized + [System.Diagnostics.CodeAnalysis.SuppressMessage("Style", "IDE0066:Convert switch statement to expression", Justification = "Readibility for nested switch")] public static Expression> ToResultFilter(this Filters filters) { Expression> expr = data => false; @@ -96,7 +92,7 @@ public static Expression> ToResultFilter(this Filters filters break; case FilterField.ValueConditionOneofCase.None: default: - throw new ArgumentOutOfRangeException(); + throw new ArgumentOutOfRangeException(nameof(filters)); } } diff --git a/Common/src/gRPC/ListSessionsRequestExt.cs b/Common/src/gRPC/ListSessionsRequestExt.cs index ae15ac83f..91f3dfd1a 100644 --- a/Common/src/gRPC/ListSessionsRequestExt.cs +++ b/Common/src/gRPC/ListSessionsRequestExt.cs @@ -35,29 +35,22 @@ public static class ListSessionsRequestExt /// /// the given message is not recognized public static Expression> ToField(this ListSessionsRequest.Types.Sort sort) - { - switch (sort.Field.FieldCase) + => sort.Field.FieldCase switch { - case SessionField.FieldOneofCase.SessionRawField: - return sort.Field.SessionRawField.Field.ToField(); - case SessionField.FieldOneofCase.TaskOptionField: - return sort.Field.TaskOptionField.Field.ToField(); - case SessionField.FieldOneofCase.TaskOptionGenericField: - return sort.Field.TaskOptionGenericField.ToField(); - case SessionField.FieldOneofCase.None: - default: - throw new ArgumentOutOfRangeException(); - } - } + SessionField.FieldOneofCase.SessionRawField => sort.Field.SessionRawField.Field.ToField(), + SessionField.FieldOneofCase.TaskOptionField => sort.Field.TaskOptionField.Field.ToField(), + SessionField.FieldOneofCase.TaskOptionGenericField => sort.Field.TaskOptionGenericField.ToField(), + _ => throw new ArgumentOutOfRangeException(nameof(sort)), + }; public static Expression> ToField(this SessionField taskField) => taskField.FieldCase switch { - SessionField.FieldOneofCase.None => throw new ArgumentOutOfRangeException(), + SessionField.FieldOneofCase.None => throw new ArgumentOutOfRangeException(nameof(taskField)), SessionField.FieldOneofCase.SessionRawField => taskField.SessionRawField.Field.ToField(), SessionField.FieldOneofCase.TaskOptionField => taskField.TaskOptionField.Field.ToField(), SessionField.FieldOneofCase.TaskOptionGenericField => taskField.TaskOptionGenericField.ToField(), - _ => throw new ArgumentOutOfRangeException(), + _ => throw new ArgumentOutOfRangeException(nameof(taskField)), }; /// @@ -68,6 +61,7 @@ public static class ListSessionsRequestExt /// The that represents the filter conditions /// /// the given message is not recognized + [System.Diagnostics.CodeAnalysis.SuppressMessage("Style", "IDE0066:Convert switch statement to expression", Justification = "Readibility for nested switch")] public static Expression> ToSessionDataFilter(this Filters filters) { Expression> expr = data => false; @@ -110,7 +104,7 @@ public static Expression> ToSessionDataFilter(this Filte break; case FilterField.ValueConditionOneofCase.None: default: - throw new ArgumentOutOfRangeException(); + throw new ArgumentOutOfRangeException(nameof(filters)); } } diff --git a/Common/src/gRPC/ListTasksRequestExt.cs b/Common/src/gRPC/ListTasksRequestExt.cs index d403eb42c..13c337d03 100644 --- a/Common/src/gRPC/ListTasksRequestExt.cs +++ b/Common/src/gRPC/ListTasksRequestExt.cs @@ -37,29 +37,22 @@ public static class ListTasksRequestExt /// /// the given message is not recognized public static Expression> ToField(this ListTasksRequest.Types.Sort sort) - { - switch (sort.Field.FieldCase) + => sort.Field.FieldCase switch { - case TaskField.FieldOneofCase.TaskSummaryField: - return sort.Field.TaskSummaryField.Field.ToField(); - case TaskField.FieldOneofCase.TaskOptionField: - return sort.Field.TaskOptionField.Field.ToField(); - case TaskField.FieldOneofCase.TaskOptionGenericField: - return sort.Field.TaskOptionGenericField.ToField(); - case TaskField.FieldOneofCase.None: - default: - throw new ArgumentOutOfRangeException(); - } - } + TaskField.FieldOneofCase.TaskSummaryField => sort.Field.TaskSummaryField.Field.ToField(), + TaskField.FieldOneofCase.TaskOptionField => sort.Field.TaskOptionField.Field.ToField(), + TaskField.FieldOneofCase.TaskOptionGenericField => sort.Field.TaskOptionGenericField.ToField(), + _ => throw new ArgumentOutOfRangeException(nameof(sort)), + }; public static Expression> ToField(this TaskField taskField) => taskField.FieldCase switch { - TaskField.FieldOneofCase.None => throw new ArgumentOutOfRangeException(), + TaskField.FieldOneofCase.None => throw new ArgumentOutOfRangeException(nameof(taskField)), TaskField.FieldOneofCase.TaskSummaryField => taskField.TaskSummaryField.Field.ToField(), TaskField.FieldOneofCase.TaskOptionField => taskField.TaskOptionField.Field.ToField(), TaskField.FieldOneofCase.TaskOptionGenericField => taskField.TaskOptionGenericField.ToField(), - _ => throw new ArgumentOutOfRangeException(), + _ => throw new ArgumentOutOfRangeException(nameof(taskField)), }; /// @@ -105,9 +98,7 @@ public static Expression> ToTaskDataFilter(this Filters fil case FilterField.ValueConditionOneofCase.FilterDate: var val = filterField.FilterDate.Value; exprAnd = exprAnd.ExpressionAnd(filterField.FilterDate.Operator.ToFilter(filterField.Field.ToField(), - val == null - ? null - : val.ToDateTime())); + val?.ToDateTime())); break; case FilterField.ValueConditionOneofCase.FilterArray: exprAnd = exprAnd.ExpressionAnd(filterField.FilterArray.Operator.ToFilter(filterField.Field.ToField(), @@ -115,7 +106,7 @@ public static Expression> ToTaskDataFilter(this Filters fil break; case FilterField.ValueConditionOneofCase.None: default: - throw new ArgumentOutOfRangeException(); + throw new ArgumentOutOfRangeException(nameof(filters)); } } diff --git a/Common/src/gRPC/Services/Agent.cs b/Common/src/gRPC/Services/Agent.cs index 0198e74b8..9e4f8334e 100644 --- a/Common/src/gRPC/Services/Agent.cs +++ b/Common/src/gRPC/Services/Agent.cs @@ -49,7 +49,7 @@ namespace ArmoniK.Core.Common.gRPC.Services; /// /// Represents the internal processing requests received by the agent. Provides methods to process those requests /// -public class Agent : IAgent +public sealed class Agent : IAgent { private readonly List createdTasks_; private readonly ILogger logger_; @@ -187,6 +187,7 @@ await taskTable_.FinalizeTaskCreation(ids, } /// + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2208:Instantiate argument exceptions correctly", Justification = "No correct value for ArgumentOutOfRange Exception in nested code")] public async Task CreateTask(IAsyncStreamReader requestStream, CancellationToken cancellationToken) { @@ -508,6 +509,7 @@ await responseStream.WriteAsync(new DataReply } /// + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2208:Instantiate argument exceptions correctly", Justification = "")] public async Task SendResult(IAsyncStreamReader requestStream, CancellationToken cancellationToken) { diff --git a/Common/src/gRPC/Services/GrpcAgentService.cs b/Common/src/gRPC/Services/GrpcAgentService.cs index fcdeeccb1..322387fff 100644 --- a/Common/src/gRPC/Services/GrpcAgentService.cs +++ b/Common/src/gRPC/Services/GrpcAgentService.cs @@ -29,13 +29,8 @@ namespace ArmoniK.Core.Common.gRPC.Services; [IgnoreAuthentication] public class GrpcAgentService : Api.gRPC.V1.Agent.Agent.AgentBase { - private readonly ILogger logger_; private IAgent? agent_; - - public GrpcAgentService(ILogger logger) - => logger_ = logger; - public Task Start(IAgent agent) { agent_ = agent; diff --git a/Common/src/gRPC/Services/GrpcApplicationsService.cs b/Common/src/gRPC/Services/GrpcApplicationsService.cs index a3c026b9d..0ade41d98 100644 --- a/Common/src/gRPC/Services/GrpcApplicationsService.cs +++ b/Common/src/gRPC/Services/GrpcApplicationsService.cs @@ -54,7 +54,7 @@ public GrpcApplicationsService(ITaskTable taskTable, public override async Task ListApplications(ListApplicationsRequest request, ServerCallContext context) { - var tasks = await taskTable_.ListApplicationsAsync(request.Filters is null + var (applications, totalCount) = await taskTable_.ListApplicationsAsync(request.Filters is null ? data => true : request.Filters.ToApplicationFilter(), request.Sort is null @@ -75,7 +75,7 @@ request.Sort is null PageSize = request.PageSize, Applications = { - tasks.applications.Select(data => new ApplicationRaw + applications.Select(data => new ApplicationRaw { Name = data.Name, Namespace = data.Namespace, @@ -83,7 +83,7 @@ request.Sort is null Service = data.Service, }), }, - Total = tasks.totalCount, + Total = totalCount, }; } } diff --git a/Common/src/gRPC/Services/GrpcAuthService.cs b/Common/src/gRPC/Services/GrpcAuthService.cs index 844d5d39e..5a4ead027 100644 --- a/Common/src/gRPC/Services/GrpcAuthService.cs +++ b/Common/src/gRPC/Services/GrpcAuthService.cs @@ -36,14 +36,11 @@ namespace ArmoniK.Core.Common.gRPC.Services; [Authorize(AuthenticationSchemes = Authenticator.SchemeName)] public class GrpcAuthService : Authentication.AuthenticationBase { - private readonly ILogger logger_; private readonly bool requireAuthentication_; private readonly bool requireAuthorization_; - public GrpcAuthService(IOptionsMonitor options, - ILogger logger) + public GrpcAuthService(IOptionsMonitor options) { - logger_ = logger; requireAuthentication_ = options.CurrentValue.RequireAuthentication; requireAuthorization_ = requireAuthentication_ && options.CurrentValue.RequireAuthorization; } diff --git a/Common/src/gRPC/Services/GrpcEventsService.cs b/Common/src/gRPC/Services/GrpcEventsService.cs index 74e34806a..9c22126fe 100644 --- a/Common/src/gRPC/Services/GrpcEventsService.cs +++ b/Common/src/gRPC/Services/GrpcEventsService.cs @@ -62,8 +62,7 @@ public override async Task GetEvents(EventSubscriptionRequest var wtg = new WatchToGrpc(taskTable_, taskWatcher_, resultTable_, - resultWatcher_, - logger_); + resultWatcher_); try { diff --git a/Common/src/gRPC/Services/GrpcSessionsService.cs b/Common/src/gRPC/Services/GrpcSessionsService.cs index 75548c2ca..bf37ff121 100644 --- a/Common/src/gRPC/Services/GrpcSessionsService.cs +++ b/Common/src/gRPC/Services/GrpcSessionsService.cs @@ -129,7 +129,7 @@ public override async Task ListSessions(ListSessionsReques { try { - var sessionData = await sessionTable_.ListSessionsAsync(request.Filters is null + var (sessions, totalCount) = await sessionTable_.ListSessionsAsync(request.Filters is null ? data => true : request.Filters.ToSessionDataFilter(), request.Sort is null @@ -147,9 +147,9 @@ request.Sort is null PageSize = request.PageSize, Sessions = { - sessionData.sessions.Select(data => new SessionRaw(data)), + sessions.Select(data => new SessionRaw(data)), }, - Total = (int)sessionData.totalCount, + Total = (int)totalCount, }; } catch (ArmoniKException e) diff --git a/Common/src/gRPC/Services/GrpcSubmitterService.cs b/Common/src/gRPC/Services/GrpcSubmitterService.cs index fe3976ad2..b315791c7 100644 --- a/Common/src/gRPC/Services/GrpcSubmitterService.cs +++ b/Common/src/gRPC/Services/GrpcSubmitterService.cs @@ -501,6 +501,7 @@ public override async Task TryGetTaskOutput(TaskOutputRequest request, [RequiresPermission(typeof(GrpcSubmitterService), nameof(WaitForAvailability))] + [Obsolete($"{nameof(ISubmitter.WaitForAvailabilityAsync)} is obsolete")] public override async Task WaitForAvailability(ResultRequest request, ServerCallContext context) { @@ -582,6 +583,7 @@ await taskTable_.GetTaskStatus(request.TaskIds, [RequiresPermission(typeof(GrpcSubmitterService), nameof(GetResultStatus))] + [Obsolete($"{nameof(Api.gRPC.V1.Submitter.Submitter.SubmitterBase.GetResultStatus)} is obsolete")] public override async Task GetResultStatus(GetResultStatusRequest request, ServerCallContext context) { diff --git a/Common/src/gRPC/Services/GrpcTasksService.cs b/Common/src/gRPC/Services/GrpcTasksService.cs index 992260831..f5860aeaa 100644 --- a/Common/src/gRPC/Services/GrpcTasksService.cs +++ b/Common/src/gRPC/Services/GrpcTasksService.cs @@ -113,7 +113,7 @@ public override async Task ListTasks(ListTasksRequest reques request.Sort.Field.TaskOptionGenericField.Field); } - var taskData = await taskTable_.ListTasksAsync(request.Filters is null + var (tasks, totalCount) = await taskTable_.ListTasksAsync(request.Filters is null ? data => true : request.Filters.ToTaskDataFilter(), request.Sort is null @@ -153,9 +153,9 @@ request.Sort is null PageSize = request.PageSize, Tasks = { - taskData.tasks.Select(data => data.ToTaskSummary()), + tasks.Select(data => data.ToTaskSummary()), }, - Total = (int)taskData.totalCount, + Total = (int)totalCount, }; } catch (ArmoniKException e) @@ -326,7 +326,7 @@ public override async Task ListTasksRaw(ListTasksRequest request.Sort.Field.TaskOptionGenericField.Field); } - var taskData = await taskTable_.ListTasksAsync(request.Filters is null + var (tasks, totalCount) = await taskTable_.ListTasksAsync(request.Filters is null ? data => true : request.Filters.ToTaskDataFilter(), request.Sort is null @@ -345,9 +345,9 @@ request.Sort is null PageSize = request.PageSize, Tasks = { - taskData.tasks.Select(data => new TaskRaw(data)), + tasks.Select(data => new TaskRaw(data)), }, - Total = (int)taskData.totalCount, + Total = (int)totalCount, }; } catch (ArmoniKException e) diff --git a/Common/src/gRPC/Services/Submitter.cs b/Common/src/gRPC/Services/Submitter.cs index 3305684ff..dbd7686a3 100644 --- a/Common/src/gRPC/Services/Submitter.cs +++ b/Common/src/gRPC/Services/Submitter.cs @@ -176,6 +176,7 @@ public async Task CreateSession(IList partitionI } /// + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2208:Instantiate argument exceptions correctly", Justification = $"{nameof(ArgumentOutOfRangeException)} is used in nested code")] public async Task TryGetResult(ResultRequest request, IServerStreamWriter responseStream, CancellationToken cancellationToken) @@ -450,6 +451,7 @@ await ResultLifeCycleHelper.AbortTaskAndResults(taskTable_, } /// + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2208:Instantiate argument exceptions correctly", Justification = $"{nameof(ArgumentOutOfRangeException)} is used in nested code")] public async Task WaitForAvailabilityAsync(ResultRequest request, CancellationToken contextCancellationToken) { diff --git a/Common/src/gRPC/Services/WatchToGrpc.cs b/Common/src/gRPC/Services/WatchToGrpc.cs index 9156ea21d..b09e43487 100644 --- a/Common/src/gRPC/Services/WatchToGrpc.cs +++ b/Common/src/gRPC/Services/WatchToGrpc.cs @@ -35,7 +35,6 @@ namespace ArmoniK.Core.Common.gRPC.Services; public class WatchToGrpc { private const int PageSize = 100; - private readonly ILogger logger_; private readonly IResultTable resultTable_; private readonly IResultWatcher resultWatcher_; private readonly ITaskTable taskTable_; @@ -52,14 +51,12 @@ public class WatchToGrpc public WatchToGrpc(ITaskTable taskTable, ITaskWatcher taskWatcher, IResultTable resultTable, - IResultWatcher resultWatcher, - ILogger logger) + IResultWatcher resultWatcher) { taskTable_ = taskTable; taskWatcher_ = taskWatcher; resultTable_ = resultTable; resultWatcher_ = resultWatcher; - logger_ = logger; } /// diff --git a/Common/tests/AdapterLoading/AdapterLoadingTest.cs b/Common/tests/AdapterLoading/AdapterLoadingTest.cs index 31634e5b8..50ce33a11 100644 --- a/Common/tests/AdapterLoading/AdapterLoadingTest.cs +++ b/Common/tests/AdapterLoading/AdapterLoadingTest.cs @@ -58,7 +58,7 @@ public static IEnumerable TestCasesQueueLocation } } - public void Setup(Dictionary config) + public static void Setup(Dictionary config) { var loggerProvider = new ConsoleForwardingLoggerProvider(); var logger = loggerProvider.CreateLogger("root"); diff --git a/Common/tests/Auth/AuthenticationCacheTest.cs b/Common/tests/Auth/AuthenticationCacheTest.cs index c1c41e202..1de601d8c 100644 --- a/Common/tests/Auth/AuthenticationCacheTest.cs +++ b/Common/tests/Auth/AuthenticationCacheTest.cs @@ -35,11 +35,11 @@ public void Setup() } private const string ConnectionId = "TestConnectionId"; - private const string CN = "CN1"; + private const string Cn = "CN1"; private const string Fingerprint = "Fingerprint1"; private static readonly AuthenticationCacheKey BaseKey = new(ConnectionId, - CN, + Cn, Fingerprint); private static readonly ClaimsPrincipal BaseIdentity = new(new UserIdentity(new UserAuthenticationResult(), @@ -58,32 +58,32 @@ public void CacheShouldHit() [Test] [TestCase(ConnectionId, - CN, + Cn, Fingerprint, "ImpId", null)] [TestCase(ConnectionId, - CN, + Cn, Fingerprint, null, "ImpName")] [TestCase(ConnectionId, - CN + "0", + Cn + "0", Fingerprint + "0", null, null)] [TestCase(ConnectionId, - CN + "0", + Cn + "0", null, null, null)] [TestCase(ConnectionId + "0", - CN, + Cn, Fingerprint, null, null)] [TestCase(ConnectionId + "0", - CN + "0", + Cn + "0", Fingerprint + "0", null, null)] @@ -124,11 +124,11 @@ public void CacheKeyEquatableShouldMatch() { Assert.IsTrue(BaseKey.Equals(BaseKey)); Assert.IsTrue(BaseKey.Equals(new AuthenticationCacheKey(ConnectionId, - CN, + Cn, Fingerprint))); Assert.IsFalse(BaseKey.Equals(null)); Assert.IsFalse(BaseKey!.Equals(new AuthenticationCacheKey(ConnectionId, - CN + "0", + Cn + "0", Fingerprint))); Assert.IsFalse(BaseKey.Equals(new object())); } diff --git a/Common/tests/Auth/AuthenticationIntegrationTest.cs b/Common/tests/Auth/AuthenticationIntegrationTest.cs index 41bdd0cbe..9096104f5 100644 --- a/Common/tests/Auth/AuthenticationIntegrationTest.cs +++ b/Common/tests/Auth/AuthenticationIntegrationTest.cs @@ -108,11 +108,11 @@ await helper_.StopServer() [SetUp] public void BeforeEach() - => singleThreadSemaphore.Wait(); + => SingleThreadSemaphore.Wait(); [TearDown] public void AfterEach() - => singleThreadSemaphore.Release(); + => SingleThreadSemaphore.Release(); private const string SessionId = "MySession"; private const string ResultKey = "ResultKey"; @@ -406,7 +406,7 @@ public static Metadata GetHeaders(IdentityIndex index, ? "DoesntExistCN" : Identities[(int)index] .Certificates.FirstOrDefault(defaultCertificate) - .CN); + .Cn); headers.Add(AuthenticatorOptions.DefaultAuth.FingerprintHeader, index == IdentityIndex.DoesntExist ? "DoesntExistFingerprint" @@ -653,8 +653,7 @@ public static Metadata GetHeaders(IdentityIndex index, new() { Id = - new UploadResultDataRequest.Types. - ResultIdentifier + new UploadResultDataRequest.Types.ResultIdentifier { ResultId = ResultKey, SessionId = SessionId, @@ -670,8 +669,7 @@ public static Metadata GetHeaders(IdentityIndex index, typeof(TaskFilter), new TaskFilter { Session = - new TaskFilter.Types. - IdsRequest + new TaskFilter.Types.IdsRequest { Ids = { @@ -894,8 +892,7 @@ public static IEnumerable GetTestReflectionCases(bool isAsync, public static readonly IReadOnlyDictionary ClientServerTypeMapping = new ReadOnlyDictionary(new Dictionary { { - typeof(Api.gRPC.V1.Submitter.Submitter. - SubmitterClient), + typeof(Api.gRPC.V1.Submitter.Submitter.SubmitterClient), typeof(GrpcSubmitterService) }, { @@ -979,7 +976,7 @@ public static Task SyncTestFunction(string method, client, args)); - private static readonly SemaphoreSlim singleThreadSemaphore = new(1, + private static readonly SemaphoreSlim SingleThreadSemaphore = new(1, 1); /// @@ -1182,9 +1179,7 @@ public void TransformResult(IdentityIndex initialUserIndex, false, true, })] - public void AuthenticationShouldMatch(CaseParameters parameters, - TRequest requestExample, - TReply replyExample) + public void AuthenticationShouldMatch(CaseParameters parameters) { TransformResult(parameters.IdentityIndex, parameters.ImpersonationType, @@ -1202,38 +1197,6 @@ public void AuthenticationShouldMatch(CaseParameters parameter Assert.IsNotNull(client); Assert.IsInstanceOf(client); - async Task TestFunction() - { - if (parameters.IsAsync) - { - await AsyncTestFunction(parameters.Method, - (ClientBase)client!, - parameters.Args) - .ConfigureAwait(false); - } - else if (parameters.ClientStream) - { - await ClientStreamTestFunction(parameters.Method, - (ClientBase)client!, - parameters.Args) - .ConfigureAwait(false); - } - else if (parameters.ServerStream) - { - await ServerStreamTestFunction(parameters.Method, - (ClientBase)client!, - parameters.Args) - .ConfigureAwait(false); - } - else - { - await SyncTestFunction(parameters.Method, - (ClientBase)client!, - parameters.Args) - .ConfigureAwait(false); - } - } - var serviceName = ServicesPermissions.FromType(ClientServerTypeMapping[parameters.ClientType]); if (shouldSucceed == ResultType.AlwaysTrue || (shouldSucceed == ResultType.AuthorizedForSome && Identities[finalUserIndex] @@ -1278,6 +1241,39 @@ await SyncTestFunction(parameters.Method, helper_.DeleteChannel(channel) .Wait(); + return; + + async Task TestFunction() + { + if (parameters.IsAsync) + { + await AsyncTestFunction(parameters.Method, + (ClientBase)client!, + parameters.Args) + .ConfigureAwait(false); + } + else if (parameters.ClientStream) + { + await ClientStreamTestFunction(parameters.Method, + (ClientBase)client!, + parameters.Args) + .ConfigureAwait(false); + } + else if (parameters.ServerStream) + { + await ServerStreamTestFunction(parameters.Method, + (ClientBase)client!, + parameters.Args) + .ConfigureAwait(false); + } + else + { + await SyncTestFunction(parameters.Method, + (ClientBase)client!, + parameters.Args) + .ConfigureAwait(false); + } + } } /// @@ -1301,9 +1297,7 @@ public static IEnumerable GetAuthServiceTestCaseSource() } [TestCaseSource(nameof(GetAuthServiceTestCaseSource))] - public async Task AuthServiceShouldGiveUserInfo(CaseParameters parameters, - object _, - object __) + public async Task AuthServiceShouldGiveUserInfo(CaseParameters parameters) { TransformResult(parameters.IdentityIndex, parameters.ImpersonationType, diff --git a/Common/tests/Auth/MockIdentity.cs b/Common/tests/Auth/MockIdentity.cs index d1a4f6abb..4b456d0de 100644 --- a/Common/tests/Auth/MockIdentity.cs +++ b/Common/tests/Auth/MockIdentity.cs @@ -42,7 +42,7 @@ public MockIdentity(string userId, public bool HasCertificate(string cn, string fingerprint) - => Certificates.Any(t => t.CN == cn && t.Fingerprint == fingerprint); + => Certificates.Any(t => t.Cn == cn && t.Fingerprint == fingerprint); public UserAuthenticationResult ToUserAuthenticationResult() => new(UserId, @@ -50,6 +50,6 @@ public UserAuthenticationResult ToUserAuthenticationResult() Roles, Permissions.Select(perm => perm.ToString())); - public record MockCertificate(string CN, + public record MockCertificate(string Cn, string Fingerprint); } diff --git a/Common/tests/Helpers/ExceptionWorkerStreamHandler.cs b/Common/tests/Helpers/ExceptionWorkerStreamHandler.cs index 8dd375fba..f95153ed3 100644 --- a/Common/tests/Helpers/ExceptionWorkerStreamHandler.cs +++ b/Common/tests/Helpers/ExceptionWorkerStreamHandler.cs @@ -29,7 +29,7 @@ namespace ArmoniK.Core.Common.Tests.Helpers; -public class ExceptionWorkerStreamHandler : IWorkerStreamHandler +public sealed class ExceptionWorkerStreamHandler : IWorkerStreamHandler where T : Exception, new() { private readonly int delay_; diff --git a/Common/tests/Helpers/GrpcSubmitterServiceHelper.cs b/Common/tests/Helpers/GrpcSubmitterServiceHelper.cs index 236a5276e..c390a3be3 100644 --- a/Common/tests/Helpers/GrpcSubmitterServiceHelper.cs +++ b/Common/tests/Helpers/GrpcSubmitterServiceHelper.cs @@ -44,21 +44,19 @@ public class GrpcSubmitterServiceHelper : IDisposable private readonly WebApplication app_; private readonly ILoggerFactory loggerFactory_; private ChannelBase? channel_; - private Mutex channelMutex_; + private readonly Mutex channelMutex_ = new (); private HttpMessageHandler? handler_; - private ILogger logger_; - private int nChannels; private TestServer? server_; public GrpcSubmitterServiceHelper(ISubmitter submitter, List authIdentities, AuthenticatorOptions authOptions, - LogLevel loglevel, + LogLevel logLevel, Action? serviceConfigurator = null, bool validateGrpcRequests = true) { loggerFactory_ = new LoggerFactory(); - loggerFactory_.AddProvider(new ConsoleForwardingLoggerProvider(loglevel)); + loggerFactory_.AddProvider(new ConsoleForwardingLoggerProvider(logLevel)); var builder = WebApplication.CreateBuilder(); @@ -71,7 +69,7 @@ public GrpcSubmitterServiceHelper(ISubmitter submitter, .AddSingleton() .AddSingleton() .Configure(o => o.CopyFrom(authOptions)) - .AddLogging(build => build.SetMinimumLevel(loglevel) + .AddLogging(build => build.SetMinimumLevel(logLevel) .AddConsole()) .AddAuthentication() .AddScheme(Authenticator.SchemeName, @@ -90,7 +88,7 @@ public GrpcSubmitterServiceHelper(ISubmitter submitter, serviceConfigurator?.Invoke(builder.Services); builder.WebHost.UseTestServer(options => options.PreserveExecutionContext = true); - logger_ = loggerFactory_.CreateLogger("Testing apps"); + loggerFactory_.CreateLogger("Testing apps"); app_ = builder.Build(); app_.UseRouting(); app_.UseAuthentication(); @@ -129,6 +127,7 @@ public void Dispose() .Wait(); channel_ = null; loggerFactory_.Dispose(); + channelMutex_?.Dispose(); GC.SuppressFinalize(this); } diff --git a/Common/tests/Helpers/SimpleQueueMessageHandler.cs b/Common/tests/Helpers/SimpleQueueMessageHandler.cs index 0fa7ef2af..615e91754 100644 --- a/Common/tests/Helpers/SimpleQueueMessageHandler.cs +++ b/Common/tests/Helpers/SimpleQueueMessageHandler.cs @@ -26,7 +26,10 @@ namespace ArmoniK.Core.Common.Tests.Helpers; public class SimpleQueueMessageHandler : IQueueMessageHandler { public ValueTask DisposeAsync() - => ValueTask.CompletedTask; + { + GC.SuppressFinalize(this); + return ValueTask.CompletedTask; + } public CancellationToken CancellationToken { get; set; } public string MessageId { get; init; } = ""; diff --git a/Common/tests/Helpers/SimpleWorkerStreamHandler.cs b/Common/tests/Helpers/SimpleWorkerStreamHandler.cs index 840e7686d..8f60ab0ea 100644 --- a/Common/tests/Helpers/SimpleWorkerStreamHandler.cs +++ b/Common/tests/Helpers/SimpleWorkerStreamHandler.cs @@ -15,6 +15,7 @@ // You should have received a copy of the GNU Affero General Public License // along with this program. If not, see . +using System; using System.Threading; using System.Threading.Tasks; @@ -41,6 +42,7 @@ public Task Init(CancellationToken cancellationToken) public void Dispose() { + GC.SuppressFinalize(this); } public void StartTaskProcessing(TaskData taskData, diff --git a/Common/tests/Helpers/TestDatabaseProvider.cs b/Common/tests/Helpers/TestDatabaseProvider.cs index a51595c58..16e221b68 100644 --- a/Common/tests/Helpers/TestDatabaseProvider.cs +++ b/Common/tests/Helpers/TestDatabaseProvider.cs @@ -60,12 +60,14 @@ public TestDatabaseProvider(Action? collectionConfigurato var options = new MongoRunnerOptions { UseSingleNodeReplicaSet = false, - StandardOuputLogger = line => logger.LogInformation(line), - StandardErrorLogger = line => logger.LogError(line), - }; +#pragma warning disable CA2254 // log inputs should be constant + StandardOuputLogger = line => logger.LogInformation(line), + StandardErrorLogger = line => logger.LogError(line), +#pragma warning restore CA2254 + }; var loggerProvider = new ConsoleForwardingLoggerProvider(); - var loggerDB = loggerProvider.CreateLogger("db commands"); + var loggerDb = loggerProvider.CreateLogger("db commands"); runner_ = MongoRunner.Run(options); var settings = MongoClientSettings.FromConnectionString(runner_.ConnectionString); @@ -74,7 +76,7 @@ public TestDatabaseProvider(Action? collectionConfigurato { settings.ClusterConfigurator = cb => { - cb.Subscribe(e => loggerDB.LogTrace("{CommandName} - {Command}", + cb.Subscribe(e => loggerDb.LogTrace("{CommandName} - {Command}", e.CommandName, e.Command.ToJson())); }; @@ -130,10 +132,8 @@ public TestDatabaseProvider(Action? collectionConfigurato builder.Services.AddMongoStorages(builder.Configuration, NullLogger.Instance) - .AddClientSubmitterAuthenticationStorage(builder.Configuration, - NullLogger.Instance) + .AddClientSubmitterAuthenticationStorage(builder.Configuration) .AddClientSubmitterAuthServices(builder.Configuration, - NullLogger.Instance, out _) .Configure(o => o.CopyFrom(AuthenticatorOptions.DefaultNoAuth)) .AddLogging() diff --git a/Common/tests/Helpers/TestPollingAgentProvider.cs b/Common/tests/Helpers/TestPollingAgentProvider.cs index 0ca2545a2..a4cb85920 100644 --- a/Common/tests/Helpers/TestPollingAgentProvider.cs +++ b/Common/tests/Helpers/TestPollingAgentProvider.cs @@ -47,34 +47,31 @@ namespace ArmoniK.Core.Common.Tests.Helpers; public class TestPollingAgentProvider : IDisposable { - private const string DatabaseName = "ArmoniK_TestDB"; - private static readonly ActivitySource ActivitySource = new("ArmoniK.Core.Common.Tests.FullIntegration"); - private readonly WebApplication app; - private readonly IMongoClient client_; - private readonly LoggerFactory loggerFactory_; - private readonly Common.Pollster.Pollster pollster_; + private const string DatabaseName = "ArmoniK_TestDB"; + private static readonly ActivitySource ActivitySource = new("ArmoniK.Core.Common.Tests.FullIntegration"); + private readonly WebApplication app_; + private readonly LoggerFactory loggerFactory_; private readonly CancellationTokenSource pollsterCancellationTokenSource_ = new(); - private readonly Task pollsterRunningTask; - private readonly IResultTable resultTable_; + private readonly Task pollsterRunningTask_; private readonly IMongoRunner runner_; - private readonly ISessionTable sessionTable_; public readonly ISubmitter Submitter; - private readonly ITaskTable taskTable_; public TestPollingAgentProvider(IWorkerStreamHandler workerStreamHandler) { - var logger = NullLogger.Instance; + var logger = NullLogger.Instance; var options = new MongoRunnerOptions { UseSingleNodeReplicaSet = false, - StandardOuputLogger = line => logger.LogInformation(line), - StandardErrorLogger = line => logger.LogError(line), - }; +#pragma warning disable CA2254 // log inputs should be constant + StandardOuputLogger = line => logger.LogInformation(line), + StandardErrorLogger = line => logger.LogError(line), +#pragma warning restore CA2254 + }; runner_ = MongoRunner.Run(options); - client_ = new MongoClient(runner_.ConnectionString); + IMongoClient client = new MongoClient(runner_.ConnectionString); // Minimal set of configurations to operate on a toy DB Dictionary minimalConfig = new() @@ -114,7 +111,7 @@ public TestPollingAgentProvider(IWorkerStreamHandler workerStreamHandler) builder.Services.AddMongoStorages(builder.Configuration, logger) .AddSingleton(ActivitySource) - .AddSingleton(serviceProvider => client_) + .AddSingleton(serviceProvider => client) .AddLogging() .AddSingleton() .AddSingleton() @@ -126,28 +123,28 @@ public TestPollingAgentProvider(IWorkerStreamHandler workerStreamHandler) var computePlanOptions = builder.Configuration.GetRequiredValue(ComputePlane.SettingSection); builder.Services.AddSingleton(computePlanOptions); - app = builder.Build(); + app_ = builder.Build(); - resultTable_ = app.Services.GetRequiredService(); - taskTable_ = app.Services.GetRequiredService(); - sessionTable_ = app.Services.GetRequiredService(); - Submitter = app.Services.GetRequiredService(); - pollster_ = app.Services.GetRequiredService(); + app_.Services.GetRequiredService(); + app_.Services.GetRequiredService(); + var sessionTable = app_.Services.GetRequiredService(); + Submitter = app_.Services.GetRequiredService(); + var pollster = app_.Services.GetRequiredService(); - sessionTable_.Init(CancellationToken.None) + sessionTable.Init(CancellationToken.None) .Wait(); - pollsterRunningTask = Task.Factory.StartNew(() => pollster_.MainLoop(pollsterCancellationTokenSource_.Token), + pollsterRunningTask_ = Task.Factory.StartNew(() => pollster.MainLoop(pollsterCancellationTokenSource_.Token), TaskCreationOptions.LongRunning); } public void Dispose() { pollsterCancellationTokenSource_?.Cancel(false); - pollsterRunningTask?.Wait(); - pollsterRunningTask?.Dispose(); + pollsterRunningTask_?.Wait(); + pollsterRunningTask_?.Dispose(); pollsterCancellationTokenSource_?.Dispose(); - ((IDisposable)app)?.Dispose(); + ((IDisposable)app_)?.Dispose(); loggerFactory_?.Dispose(); runner_?.Dispose(); GC.SuppressFinalize(this); diff --git a/Common/tests/Helpers/TestPollsterProvider.cs b/Common/tests/Helpers/TestPollsterProvider.cs index f0e3b7bb7..a94fec441 100644 --- a/Common/tests/Helpers/TestPollsterProvider.cs +++ b/Common/tests/Helpers/TestPollsterProvider.cs @@ -68,9 +68,11 @@ public TestPollsterProvider(IWorkerStreamHandler workerStreamHandler, var options = new MongoRunnerOptions { UseSingleNodeReplicaSet = false, - StandardOuputLogger = line => logger.LogInformation(line), - StandardErrorLogger = line => logger.LogError(line), - }; +#pragma warning disable CA2254 // log inputs should be constant + StandardOuputLogger = line => logger.LogInformation(line), + StandardErrorLogger = line => logger.LogError(line), +#pragma warning restore CA2254 + }; runner_ = MongoRunner.Run(options); client_ = new MongoClient(runner_.ConnectionString); diff --git a/Common/tests/Helpers/TestTaskHandlerProvider.cs b/Common/tests/Helpers/TestTaskHandlerProvider.cs index 6ed67ba8e..5e82e65a3 100644 --- a/Common/tests/Helpers/TestTaskHandlerProvider.cs +++ b/Common/tests/Helpers/TestTaskHandlerProvider.cs @@ -73,9 +73,11 @@ public TestTaskHandlerProvider(IWorkerStreamHandler workerStreamHandler, var options = new MongoRunnerOptions { UseSingleNodeReplicaSet = false, - StandardOuputLogger = line => logger.LogInformation(line), - StandardErrorLogger = line => logger.LogError(line), - }; +#pragma warning disable CA2254 // log inputs should be constant + StandardOuputLogger = line => logger.LogInformation(line), + StandardErrorLogger = line => logger.LogError(line), +#pragma warning restore CA2254 + }; runner_ = MongoRunner.Run(options); client_ = new MongoClient(runner_.ConnectionString); diff --git a/Common/tests/ListApplicationsRequestExt/ToApplicationFieldTest.cs b/Common/tests/ListApplicationsRequestExt/ToApplicationFieldTest.cs index 11476681d..bb3cb6ea7 100644 --- a/Common/tests/ListApplicationsRequestExt/ToApplicationFieldTest.cs +++ b/Common/tests/ListApplicationsRequestExt/ToApplicationFieldTest.cs @@ -79,14 +79,6 @@ public class ToApplicationFieldTest public static IEnumerable TestCasesInvoke() { - TestCaseData Case(ApplicationRawEnumField field, - object? expected) - => new TestCaseData(new ApplicationRawField - { - Field = field, - }, - expected).SetArgDisplayNames(field.ToString()); - yield return Case(ApplicationRawEnumField.Service, Options.ApplicationService); yield return Case(ApplicationRawEnumField.Name, @@ -97,6 +89,14 @@ TestCaseData Case(ApplicationRawEnumField field, Options.ApplicationVersion); } + private static TestCaseData Case(ApplicationRawEnumField field, + object? expected) + => new TestCaseData(new ApplicationRawField + { + Field = field, + }, + expected).SetArgDisplayNames(field.ToString()); + [Test] [TestCaseSource(nameof(TestCasesInvoke))] public void InvokeShouldReturnExpectedValue(ApplicationRawField field, diff --git a/Common/tests/ListPartitionsRequestExt/ToPartitionDataFieldTest.cs b/Common/tests/ListPartitionsRequestExt/ToPartitionDataFieldTest.cs index aee239276..06338800c 100644 --- a/Common/tests/ListPartitionsRequestExt/ToPartitionDataFieldTest.cs +++ b/Common/tests/ListPartitionsRequestExt/ToPartitionDataFieldTest.cs @@ -45,14 +45,6 @@ public class ToPartitionDataFieldTest public static IEnumerable TestCasesInvoke() { - TestCaseData Case(PartitionRawEnumField field, - object? expected) - => new TestCaseData(new PartitionRawField - { - Field = field, - }, - expected).SetArgDisplayNames(field.ToString()); - yield return Case(PartitionRawEnumField.ParentPartitionIds, PartitionData.ParentPartitionIds); yield return Case(PartitionRawEnumField.Id, @@ -67,6 +59,14 @@ TestCaseData Case(PartitionRawEnumField field, PartitionData.PreemptionPercentage); } + private static TestCaseData Case(PartitionRawEnumField field, + object? expected) + => new TestCaseData(new PartitionRawField + { + Field = field, + }, + expected).SetArgDisplayNames(field.ToString()); + [Test] [TestCaseSource(nameof(TestCasesInvoke))] public void InvokeShouldReturnExpectedValue(PartitionRawField field, diff --git a/Common/tests/ListResultsRequestExt/ToResultFieldTest.cs b/Common/tests/ListResultsRequestExt/ToResultFieldTest.cs index afa43c069..879cda321 100644 --- a/Common/tests/ListResultsRequestExt/ToResultFieldTest.cs +++ b/Common/tests/ListResultsRequestExt/ToResultFieldTest.cs @@ -44,15 +44,6 @@ public class ToResultFieldTest public static IEnumerable TestCasesInvoke() { - TestCaseData Case(ResultRawEnumField field, - object? expected) - => new TestCaseData(new ResultRawField - { - Field = field, - }, - expected).SetArgDisplayNames(field.ToString()); - - // TODO add completedDate yield return Case(ResultRawEnumField.Status, Result.Status); @@ -68,6 +59,14 @@ TestCaseData Case(ResultRawEnumField field, Result.SessionId); } + private static TestCaseData Case(ResultRawEnumField field, + object? expected) + => new TestCaseData(new ResultRawField + { + Field = field, + }, + expected).SetArgDisplayNames(field.ToString()); + [Test] [TestCaseSource(nameof(TestCasesInvoke))] public void InvokeShouldReturnExpectedValue(ResultRawField field, diff --git a/Common/tests/ListSessionsRequestExt/ToSessionDataFieldTest.cs b/Common/tests/ListSessionsRequestExt/ToSessionDataFieldTest.cs index 987dcc274..11ddeeb35 100644 --- a/Common/tests/ListSessionsRequestExt/ToSessionDataFieldTest.cs +++ b/Common/tests/ListSessionsRequestExt/ToSessionDataFieldTest.cs @@ -55,14 +55,6 @@ public class ToSessionDataFieldTest public static IEnumerable TestCasesInvoke() { - TestCaseData Case(SessionRawEnumField field, - object? expected) - => new TestCaseData(new SessionRawField - { - Field = field, - }, - expected).SetArgDisplayNames(field.ToString()); - // TODO add Duration yield return Case(SessionRawEnumField.Status, SessionData.Status); @@ -78,6 +70,14 @@ TestCaseData Case(SessionRawEnumField field, SessionData.PartitionIds); } + private static TestCaseData Case(SessionRawEnumField field, + object? expected) + => new TestCaseData(new SessionRawField + { + Field = field, + }, + expected).SetArgDisplayNames(field.ToString()); + [Test] [TestCaseSource(nameof(TestCasesInvoke))] public void InvokeShouldReturnExpectedValue(SessionRawField field, diff --git a/Common/tests/Pollster/PollsterTest.cs b/Common/tests/Pollster/PollsterTest.cs index cc26203c3..4844967c7 100644 --- a/Common/tests/Pollster/PollsterTest.cs +++ b/Common/tests/Pollster/PollsterTest.cs @@ -423,6 +423,7 @@ public Task Init(CancellationToken cancellationToken) public void Dispose() { + GC.SuppressFinalize(this); } public IAsyncPipe? Pipe { get; private set; } @@ -441,7 +442,8 @@ public WaitAsyncPipe(double delay) public async Task ReadAsync(CancellationToken cancellationToken) { - await Task.Delay(TimeSpan.FromMilliseconds(delay_)) + await Task.Delay(TimeSpan.FromMilliseconds(delay_), + cancellationToken) .ConfigureAwait(false); return new ProcessReply { @@ -476,11 +478,11 @@ public async Task ExecuteTaskShouldSucceed(double delay) simpleAgentHandler, mockPullQueueStorage.Object); - var tuple = await InitSubmitter(testServiceProvider.Submitter, - testServiceProvider.PartitionTable, - testServiceProvider.ResultTable, - CancellationToken.None) - .ConfigureAwait(false); + var (_, _, taskSubmitted) = await InitSubmitter(testServiceProvider.Submitter, + testServiceProvider.PartitionTable, + testServiceProvider.ResultTable, + CancellationToken.None) + .ConfigureAwait(false); mockPullQueueStorage.Setup(storage => storage.PullMessagesAsync(It.IsAny(), It.IsAny())) @@ -492,7 +494,7 @@ public async Task ExecuteTaskShouldSucceed(double delay) Status = QueueMessageStatus.Waiting, MessageId = Guid.NewGuid() .ToString(), - TaskId = tuple.taskSubmitted, + TaskId = taskSubmitted, }, }.ToAsyncEnumerable()); @@ -508,7 +510,7 @@ await testServiceProvider.Pollster.Init(CancellationToken.None) Assert.AreEqual(TaskStatus.Completed, (await testServiceProvider.TaskTable.GetTaskStatus(new[] { - tuple.taskSubmitted, + taskSubmitted, }, CancellationToken.None) .ConfigureAwait(false)).Single() @@ -530,11 +532,11 @@ public async Task CancelLongTaskShouldSucceed() simpleAgentHandler, mockPullQueueStorage.Object); - var tuple = await InitSubmitter(testServiceProvider.Submitter, - testServiceProvider.PartitionTable, - testServiceProvider.ResultTable, - CancellationToken.None) - .ConfigureAwait(false); + var (_, _, taskSubmitted) = await InitSubmitter(testServiceProvider.Submitter, + testServiceProvider.PartitionTable, + testServiceProvider.ResultTable, + CancellationToken.None) + .ConfigureAwait(false); mockPullQueueStorage.Setup(storage => storage.PullMessagesAsync(It.IsAny(), It.IsAny())) @@ -546,7 +548,7 @@ public async Task CancelLongTaskShouldSucceed() Status = QueueMessageStatus.Waiting, MessageId = Guid.NewGuid() .ToString(), - TaskId = tuple.taskSubmitted, + TaskId = taskSubmitted, }, }.ToAsyncEnumerable()); @@ -563,7 +565,7 @@ await Task.Delay(TimeSpan.FromMilliseconds(200), await testServiceProvider.TaskTable.CancelTaskAsync(new List { - tuple.taskSubmitted, + taskSubmitted, }, CancellationToken.None) .ConfigureAwait(false); @@ -582,7 +584,7 @@ await Task.Delay(TimeSpan.FromMilliseconds(200), Assert.AreEqual(TaskStatus.Cancelled, (await testServiceProvider.TaskTable.GetTaskStatus(new[] { - tuple.taskSubmitted, + taskSubmitted, }, CancellationToken.None) .ConfigureAwait(false)).Single() @@ -685,11 +687,11 @@ public async Task UnavailableWorkerShouldFail() simpleAgentHandler, mockPullQueueStorage.Object); - var tuple = await InitSubmitter(testServiceProvider.Submitter, - testServiceProvider.PartitionTable, - testServiceProvider.ResultTable, - CancellationToken.None) - .ConfigureAwait(false); + var (_, _, taskSubmitted) = await InitSubmitter(testServiceProvider.Submitter, + testServiceProvider.PartitionTable, + testServiceProvider.ResultTable, + CancellationToken.None) + .ConfigureAwait(false); mockPullQueueStorage.Setup(storage => storage.PullMessagesAsync(It.IsAny(), It.IsAny())) @@ -701,7 +703,7 @@ public async Task UnavailableWorkerShouldFail() Status = QueueMessageStatus.Waiting, MessageId = Guid.NewGuid() .ToString(), - TaskId = tuple.taskSubmitted, + TaskId = taskSubmitted, }, }.ToAsyncEnumerable()); @@ -717,7 +719,7 @@ await testServiceProvider.Pollster.Init(CancellationToken.None) Assert.AreEqual(TaskStatus.Submitted, (await testServiceProvider.TaskTable.GetTaskStatus(new[] { - tuple.taskSubmitted, + taskSubmitted, }, CancellationToken.None) .ConfigureAwait(false)).Single() diff --git a/Common/tests/Pollster/TaskHandlerTest.cs b/Common/tests/Pollster/TaskHandlerTest.cs index 6befbfaf1..7317b5faa 100644 --- a/Common/tests/Pollster/TaskHandlerTest.cs +++ b/Common/tests/Pollster/TaskHandlerTest.cs @@ -97,7 +97,7 @@ public async Task AcquireTaskShouldFail() Assert.IsFalse(acquired); } - private async Task<(string taskId, string taskUnresolvedDepId, string taskErrorId, string taskRetriedId, string sessionId)> InitProviderRunnableTask( + private static async Task<(string taskId, string taskUnresolvedDepId, string taskErrorId, string taskRetriedId, string sessionId)> InitProviderRunnableTask( TestTaskHandlerProvider testServiceProvider) { await testServiceProvider.PartitionTable.CreatePartitionsAsync(new[] @@ -558,7 +558,8 @@ public async Task ReadTaskAsync(string taskId, { if (waitMethod_ == WaitMethod.Read) { - await Task.Delay(delay_) + await Task.Delay(delay_, + cancellationToken) .ConfigureAwait(false); } @@ -708,7 +709,8 @@ public async Task AcquireTask(TaskData taskData, { if (waitMethod_ == WaitMethod.Acquire) { - await Task.Delay(delay_) + await Task.Delay(delay_, + cancellationToken) .ConfigureAwait(false); } @@ -843,7 +845,8 @@ public Task SetSessionDataAsync(IEnumerable partitionIds, public async Task GetSessionAsync(string sessionId, CancellationToken cancellationToken = default) { - await Task.Delay(delay_) + await Task.Delay(delay_, + cancellationToken) .ConfigureAwait(false); return sessionData_!; } @@ -997,6 +1000,7 @@ public Task Init(CancellationToken cancellationToken) public void Dispose() { + GC.SuppressFinalize(this); } public IAsyncPipe? Pipe { get; private set; } diff --git a/Common/tests/Submitter/SubmitterTests.cs b/Common/tests/Submitter/SubmitterTests.cs index 3f302885f..60e5ca558 100644 --- a/Common/tests/Submitter/SubmitterTests.cs +++ b/Common/tests/Submitter/SubmitterTests.cs @@ -68,9 +68,11 @@ public async Task SetUp() var options = new MongoRunnerOptions { UseSingleNodeReplicaSet = false, - StandardOuputLogger = line => logger.LogInformation(line), - StandardErrorLogger = line => logger.LogError(line), - }; +#pragma warning disable CA2254 // log inputs should be constant + StandardOuputLogger = line => logger.LogInformation(line), + StandardErrorLogger = line => logger.LogError(line), +#pragma warning restore CA2254 + }; runner_ = MongoRunner.Run(options); client_ = new MongoClient(runner_.ConnectionString); diff --git a/Common/tests/TestBase/ObjectStorageTestBase.cs b/Common/tests/TestBase/ObjectStorageTestBase.cs index 3267ff466..a16cd5503 100644 --- a/Common/tests/TestBase/ObjectStorageTestBase.cs +++ b/Common/tests/TestBase/ObjectStorageTestBase.cs @@ -98,7 +98,7 @@ private static bool CheckForSkipSetup() /* Function be override so it returns the suitable instance * of TaskTable to the corresponding interface implementation */ - public virtual void GetObjectStorageInstance() + protected virtual void GetObjectStorageInstance() { } diff --git a/Common/tests/TestBase/PartitionTableTestBase.cs b/Common/tests/TestBase/PartitionTableTestBase.cs index b4a568227..e058eb87f 100644 --- a/Common/tests/TestBase/PartitionTableTestBase.cs +++ b/Common/tests/TestBase/PartitionTableTestBase.cs @@ -229,16 +229,16 @@ public async Task ListPartitionsEmptyResultShouldSucceed() { if (RunTests) { - var listTasks = await PartitionTable!.ListPartitionsAsync(data => data.PartitionId == "NotExisting", - data => data.ParentPartitionIds, - false, - 0, - 20, - CancellationToken.None) - .ConfigureAwait(false); + var (_, totalCount) = await PartitionTable!.ListPartitionsAsync(data => data.PartitionId == "NotExisting", + data => data.ParentPartitionIds, + false, + 0, + 20, + CancellationToken.None) + .ConfigureAwait(false); Assert.AreEqual(0, - listTasks.totalCount); + totalCount); } } @@ -247,16 +247,16 @@ public async Task ListPartitionsContainsShouldSucceed() { if (RunTests) { - var listTasks = await PartitionTable!.ListPartitionsAsync(data => data.ParentPartitionIds.Contains("ParentPartitionId"), - data => data.PartitionId, - false, - 0, - 20, - CancellationToken.None) - .ConfigureAwait(false); + var (_, totalCount) = await PartitionTable!.ListPartitionsAsync(data => data.ParentPartitionIds.Contains("ParentPartitionId"), + data => data.PartitionId, + false, + 0, + 20, + CancellationToken.None) + .ConfigureAwait(false); Assert.AreEqual(1, - listTasks.totalCount); + totalCount); } } @@ -267,16 +267,16 @@ public async Task ListPartitionFilter(ListPartitionsRequest request, { if (RunTests) { - var listTasks = await PartitionTable!.ListPartitionsAsync(request.Filters.ToPartitionFilter(), - data => data.PartitionId, - false, - 0, - 20, - CancellationToken.None) - .ConfigureAwait(false); + var (_, totalCount) = await PartitionTable!.ListPartitionsAsync(request.Filters.ToPartitionFilter(), + data => data.PartitionId, + false, + 0, + 20, + CancellationToken.None) + .ConfigureAwait(false); Assert.AreEqual(count, - listTasks.totalCount); + totalCount); } } diff --git a/Common/tests/TestBase/QueueStorageTestsBase.cs b/Common/tests/TestBase/QueueStorageTestsBase.cs index e6dc21432..5bce78204 100644 --- a/Common/tests/TestBase/QueueStorageTestsBase.cs +++ b/Common/tests/TestBase/QueueStorageTestsBase.cs @@ -201,7 +201,6 @@ public async Task PullMessagesAsyncSucceedsOnMultipleCalls() await PullQueueStorage!.Init(CancellationToken.None) .ConfigureAwait(false); - const int priority = 1; var testTaskOptions = new TaskOptions(new Dictionary { { diff --git a/Common/tests/TestBase/SessionTableTestBase.cs b/Common/tests/TestBase/SessionTableTestBase.cs index 512b3cc14..5ec4fc43b 100644 --- a/Common/tests/TestBase/SessionTableTestBase.cs +++ b/Common/tests/TestBase/SessionTableTestBase.cs @@ -56,7 +56,7 @@ public async Task SetUp() await SessionTable!.Init(CancellationToken.None) .ConfigureAwait(false); - rootSessionId_ = await SessionTable!.SetSessionDataAsync(new[] + rootSessionId1_ = await SessionTable!.SetSessionDataAsync(new[] { "part1", "part2", @@ -65,16 +65,16 @@ public async Task SetUp() CancellationToken.None) .ConfigureAwait(false); - rootSessionId2_ = await SessionTable!.SetSessionDataAsync(new[] - { - "part1", - "part2", - }, - Options, - CancellationToken.None) - .ConfigureAwait(false); + await SessionTable!.SetSessionDataAsync(new[] + { + "part1", + "part2", + }, + Options, + CancellationToken.None) + .ConfigureAwait(false); - rootSessionId3_ = await SessionTable!.SetSessionDataAsync(new[] + rootSessionId2_ = await SessionTable!.SetSessionDataAsync(new[] { "part1", "part2", @@ -83,20 +83,20 @@ public async Task SetUp() CancellationToken.None) .ConfigureAwait(false); - rootSessionId4_ = await SessionTable!.SetSessionDataAsync(new[] - { - "part1", - "part2", - }, - Options with - { - ApplicationName = "ApplicationName2", - ApplicationVersion = "ApplicationVersion2", - }, - CancellationToken.None) - .ConfigureAwait(false); + await SessionTable!.SetSessionDataAsync(new[] + { + "part1", + "part2", + }, + Options with + { + ApplicationName = "ApplicationName2", + ApplicationVersion = "ApplicationVersion2", + }, + CancellationToken.None) + .ConfigureAwait(false); - await SessionTable.CancelSessionAsync(rootSessionId3_, + await SessionTable.CancelSessionAsync(rootSessionId2_, CancellationToken.None) .ConfigureAwait(false); } @@ -108,21 +108,21 @@ public virtual void TearDown() RunTests = false; } - public static TaskOptions Options = new(new Dictionary - { - { - "key1", "val1" - }, - }, - TimeSpan.FromMinutes(1), - 2, - 1, - "part1", - "ApplicationName", - "ApplicationVersion", - "", - "", - ""); + private static readonly TaskOptions Options = new(new Dictionary + { + { + "key1", "val1" + }, + }, + TimeSpan.FromMinutes(1), + 2, + 1, + "part1", + "ApplicationName", + "ApplicationVersion", + "", + "", + ""); private static bool CheckForSkipSetup() { @@ -134,10 +134,8 @@ private static bool CheckForSkipSetup() protected bool RunTests; - private string? rootSessionId_; + private string? rootSessionId1_; private string? rootSessionId2_; - private string? rootSessionId3_; - private string? rootSessionId4_; public virtual void GetSessionTableInstance() { @@ -179,7 +177,7 @@ public async Task IsSessionCancelledAsyncShouldSucceed() { if (RunTests) { - var res = await SessionTable!.IsSessionCancelledAsync(rootSessionId_!, + var res = await SessionTable!.IsSessionCancelledAsync(rootSessionId1_!, CancellationToken.None) .ConfigureAwait(false); Assert.IsFalse(res); @@ -205,7 +203,7 @@ public async Task GetDefaultTaskOptionAsyncShouldSucceed() { if (RunTests) { - var res = await SessionTable!.GetDefaultTaskOptionAsync(rootSessionId_!, + var res = await SessionTable!.GetDefaultTaskOptionAsync(rootSessionId1_!, CancellationToken.None) .ConfigureAwait(false); Assert.NotNull(res); @@ -231,14 +229,14 @@ public async Task CancelSessionAsyncShouldSucceed() { if (RunTests) { - var sessionData = await SessionTable!.CancelSessionAsync(rootSessionId_!, + var sessionData = await SessionTable!.CancelSessionAsync(rootSessionId1_!, CancellationToken.None) .ConfigureAwait(false); Assert.AreEqual(SessionStatus.Cancelled, sessionData.Status); - var wasSessionCanceled = await SessionTable.IsSessionCancelledAsync(rootSessionId_!, + var wasSessionCanceled = await SessionTable.IsSessionCancelledAsync(rootSessionId1_!, CancellationToken.None) .ConfigureAwait(false); Assert.IsTrue(wasSessionCanceled); @@ -264,13 +262,13 @@ public async Task CancelCancelledSessionAsyncShouldFail() { if (RunTests) { - await SessionTable!.CancelSessionAsync(rootSessionId_!, + await SessionTable!.CancelSessionAsync(rootSessionId1_!, CancellationToken.None) .ConfigureAwait(false); Assert.ThrowsAsync(async () => { - await SessionTable.CancelSessionAsync(rootSessionId_!, + await SessionTable.CancelSessionAsync(rootSessionId1_!, CancellationToken.None) .ConfigureAwait(false); }); @@ -283,7 +281,7 @@ public async Task DeleteSessionAsyncShouldSucceed() { if (RunTests) { - var res = SessionTable!.DeleteSessionAsync(rootSessionId_!, + var res = SessionTable!.DeleteSessionAsync(rootSessionId1_!, CancellationToken.None); await res.ConfigureAwait(false); @@ -338,7 +336,7 @@ public async Task ListSessionAsyncShouldSucceed2() { Sessions = { - rootSessionId_!, + rootSessionId1_!, }, }, CancellationToken.None) @@ -394,7 +392,7 @@ public async Task ListSessionAsyncFilterApplicationNameAndSessionIdShouldSucceed { if (RunTests) { - var res = (await SessionTable!.ListSessionsAsync(data => data.Options.ApplicationName == "ApplicationName" && data.SessionId == rootSessionId_!, + var res = (await SessionTable!.ListSessionsAsync(data => data.Options.ApplicationName == "ApplicationName" && data.SessionId == rootSessionId1_!, data => data.Status, true, 0, diff --git a/Common/tests/TestBase/TaskTableTestBase.cs b/Common/tests/TestBase/TaskTableTestBase.cs index d0859f244..eccb73525 100644 --- a/Common/tests/TestBase/TaskTableTestBase.cs +++ b/Common/tests/TestBase/TaskTableTestBase.cs @@ -15,6 +15,9 @@ // You should have received a copy of the GNU Affero General Public License // along with this program. If not, see . +// in tests, Tasks can be explicitly waited +#pragma warning disable CA2012 + using System; using System.Collections.Generic; using System.Linq; @@ -406,13 +409,13 @@ public async Task UpdateAllTaskStatusAsyncShouldSucceed() TaskStatus.Timeout, CancellationToken.None) .ConfigureAwait(false); - var resCreating = await TaskTable.GetTaskStatus(new[] + var resCreating = await TaskTable!.GetTaskStatus(new[] { "TaskCreatingId", }, CancellationToken.None) .ConfigureAwait(false); - var resProcessing = await TaskTable.GetTaskStatus(new[] + var resProcessing = await TaskTable!.GetTaskStatus(new[] { "TaskProcessingId", }, @@ -445,13 +448,13 @@ public async Task UpdateAllTaskStatusAsyncShouldSucceedIfNoStatusGiven() TaskStatus.Timeout, CancellationToken.None) .ConfigureAwait(false); - var resCreating = await TaskTable.GetTaskStatus(new[] + var resCreating = await TaskTable!.GetTaskStatus(new[] { "TaskCreatingId", }, CancellationToken.None) .ConfigureAwait(false); - var resProcessing = await TaskTable.GetTaskStatus(new[] + var resProcessing = await TaskTable!.GetTaskStatus(new[] { "TaskProcessingId", }, @@ -700,7 +703,7 @@ public async Task SetTaskSuccessAsyncShouldSucceed() CancellationToken.None) .ConfigureAwait(false); - var resStatus = await TaskTable.GetTaskStatus(new[] + var resStatus = await TaskTable!.GetTaskStatus(new[] { taskProcessingData_.TaskId, }, @@ -1332,16 +1335,16 @@ public async Task ListApplicationFromTasksShouldSucceed() Assert.IsTrue(validator.Validate(req) .IsValid); - var listTasks = await TaskTable!.ListApplicationsAsync(req.Filters.ToApplicationFilter(), - req.Sort.Fields.Select(sort => sort.ToField()) - .ToList(), - false, - req.Page, - req.PageSize, - CancellationToken.None) - .ConfigureAwait(false); + var (applications, _) = await TaskTable!.ListApplicationsAsync(req.Filters.ToApplicationFilter(), + req.Sort.Fields.Select(sort => sort.ToField()) + .ToList(), + false, + req.Page, + req.PageSize, + CancellationToken.None) + .ConfigureAwait(false); - var listTasksResponseTaskData = listTasks.applications.ToList(); + var listTasksResponseTaskData = applications.ToList(); foreach (var task in listTasksResponseTaskData) { Console.WriteLine(task); @@ -1508,16 +1511,16 @@ taskData1 with Assert.IsTrue(validator.Validate(req) .IsValid); - var listTasks = await TaskTable.ListApplicationsAsync(req.Filters.ToApplicationFilter(), - req.Sort.Fields.Select(sort => sort.ToField()) - .ToList(), - req.Sort.Direction == SortDirection.Asc, - req.Page, - req.PageSize, - CancellationToken.None) - .ConfigureAwait(false); + var (applications, _) = await TaskTable.ListApplicationsAsync(req.Filters.ToApplicationFilter(), + req.Sort.Fields.Select(sort => sort.ToField()) + .ToList(), + req.Sort.Direction == SortDirection.Asc, + req.Page, + req.PageSize, + CancellationToken.None) + .ConfigureAwait(false); - var listTasksResponseTaskData = listTasks.applications.ToList(); + var listTasksResponseTaskData = applications.ToList(); foreach (var task in listTasksResponseTaskData) { Console.WriteLine(task); @@ -1541,17 +1544,17 @@ public async Task ListTaskWithRequestShouldSucceed() { if (RunTests) { - var listTasks = await TaskTable!.ListTasksAsync(data => data.SessionId == "SessionId", - data => data.SessionId, - data => data, - false, - 0, - 20, - CancellationToken.None) - .ConfigureAwait(false); + var (_, totalCount) = await TaskTable!.ListTasksAsync(data => data.SessionId == "SessionId", + data => data.SessionId, + data => data, + false, + 0, + 20, + CancellationToken.None) + .ConfigureAwait(false); Assert.AreEqual(6, - listTasks.totalCount); + totalCount); } } @@ -1604,17 +1607,17 @@ public async Task ListTaskWithRequestOrderByTaskOptionsOptionsShouldSucceed() }, }; - var listTasks = await TaskTable!.ListTasksAsync(req.Filters.ToTaskDataFilter(), - req.Sort.ToField(), - data => data, - false, - 0, - 20, - CancellationToken.None) - .ConfigureAwait(false); + var (_, totalCount) = await TaskTable!.ListTasksAsync(req.Filters.ToTaskDataFilter(), + req.Sort.ToField(), + data => data, + false, + 0, + 20, + CancellationToken.None) + .ConfigureAwait(false); Assert.AreEqual(6, - listTasks.totalCount); + totalCount); } } @@ -1629,17 +1632,17 @@ public async Task ListTaskWithListInRequestShouldSucceed() TaskStatus.Completed, }; - var listTasks = await TaskTable!.ListTasksAsync(data => statusList.Contains(data.Status), - data => data.SessionId, - data => data, - false, - 0, - 20, - CancellationToken.None) - .ConfigureAwait(false); + var (_, totalCount) = await TaskTable!.ListTasksAsync(data => statusList.Contains(data.Status), + data => data.SessionId, + data => data, + false, + 0, + 20, + CancellationToken.None) + .ConfigureAwait(false); Assert.AreEqual(3, - listTasks.totalCount); + totalCount); } } @@ -1648,17 +1651,17 @@ public async Task ListTaskEmptyResultShouldSucceed() { if (RunTests) { - var listTasks = await TaskTable!.ListTasksAsync(data => data.TaskId == "NotExisting", - data => data.SessionId, - data => data, - false, - 0, - 20, - CancellationToken.None) - .ConfigureAwait(false); + var (_, totalCount) = await TaskTable!.ListTasksAsync(data => data.TaskId == "NotExisting", + data => data.SessionId, + data => data, + false, + 0, + 20, + CancellationToken.None) + .ConfigureAwait(false); Assert.AreEqual(0, - listTasks.totalCount); + totalCount); } } @@ -1669,17 +1672,17 @@ public async Task ListTaskFilter(ListTasksRequest request, { if (RunTests) { - var listTasks = await TaskTable!.ListTasksAsync(request.Filters.ToTaskDataFilter(), - data => data.SessionId, - data => data, - false, - 0, - 20, - CancellationToken.None) - .ConfigureAwait(false); + var (_, totalCount) = await TaskTable!.ListTasksAsync(request.Filters.ToTaskDataFilter(), + data => data.SessionId, + data => data, + false, + 0, + 20, + CancellationToken.None) + .ConfigureAwait(false); Assert.AreEqual(count, - listTasks.totalCount); + totalCount); } } @@ -1896,7 +1899,7 @@ public async Task FindTasksAsyncContainsShouldSucceed() .ConfigureAwait(false); Assert.AreEqual(6, - cancelledTasks.Count()); + cancelledTasks.Count); Assert.AreEqual(6, cancelledTasks.SelectMany(list => list) .Count(s => s == "dependency1")); diff --git a/Common/tests/Validators/CreateLargeTaskRequestValidatorTest.cs b/Common/tests/Validators/CreateLargeTaskRequestValidatorTest.cs index 3abdf8199..f6faa909b 100644 --- a/Common/tests/Validators/CreateLargeTaskRequestValidatorTest.cs +++ b/Common/tests/Validators/CreateLargeTaskRequestValidatorTest.cs @@ -15,6 +15,9 @@ // You should have received a copy of the GNU Affero General Public License // along with this program. If not, see . +// In tests, Random can be used +#pragma warning disable SEC0115 + using System; using ArmoniK.Api.gRPC.V1; diff --git a/Common/tests/WatchToGrpcTests.cs b/Common/tests/WatchToGrpcTests.cs index c3c951726..f6c3a3230 100644 --- a/Common/tests/WatchToGrpcTests.cs +++ b/Common/tests/WatchToGrpcTests.cs @@ -25,8 +25,6 @@ using ArmoniK.Core.Common.Tests.Helpers; using ArmoniK.Utils; -using Microsoft.Extensions.Logging.Abstractions; - using NUnit.Framework; namespace ArmoniK.Core.Common.Tests; @@ -42,8 +40,7 @@ public void WatchShouldSucceed() var watchToGrpcInstance = new WatchToGrpc(new SimpleTaskTable(), new SimpleTaskWatcher(), new SimpleResultTable(), - new SimpleResultWatcher(), - NullLogger.Instance); + new SimpleResultWatcher()); var list = new List(); @@ -53,7 +50,6 @@ public void WatchShouldSucceed() // Simple* that are used to create this instance do not check the session in their implementation await foreach (var eventSubscriptionResponse in watchToGrpcInstance.GetEvents("", cts.Token) - .WithCancellation(cts.Token) .ConfigureAwait(false)) { Console.WriteLine(eventSubscriptionResponse); @@ -80,8 +76,7 @@ public async Task MultipleWatchShouldSucceed(int nTries) var watchToGrpcInstance = new WatchToGrpc(new SimpleTaskTable(), new SimpleTaskWatcher(), new SimpleResultTable(), - new SimpleResultWatcher(), - NullLogger.Instance); + new SimpleResultWatcher()); Assert.ThrowsAsync(async () => { @@ -89,7 +84,6 @@ public async Task MultipleWatchShouldSucceed(int nTries) await foreach (var eventSubscriptionResponse in watchToGrpcInstance .GetEvents("", cts.Token) - .WithCancellation(cts.Token) .ConfigureAwait(false)) { Console.WriteLine(eventSubscriptionResponse); diff --git a/Control/Submitter/src/Program.cs b/Control/Submitter/src/Program.cs index 567103e2a..87ad82fde 100644 --- a/Control/Submitter/src/Program.cs +++ b/Control/Submitter/src/Program.cs @@ -129,10 +129,8 @@ public static async Task Main(string[] args) }); } - builder.Services.AddClientSubmitterAuthenticationStorage(builder.Configuration, - logger.GetLogger()); + builder.Services.AddClientSubmitterAuthenticationStorage(builder.Configuration); builder.Services.AddClientSubmitterAuthServices(builder.Configuration, - logger.GetLogger(), out var authCache); builder.WebHost.UseKestrel(options => diff --git a/Tests/Bench/Client/src/Program.cs b/Tests/Bench/Client/src/Program.cs index 643703def..3f52b0337 100644 --- a/Tests/Bench/Client/src/Program.cs +++ b/Tests/Bench/Client/src/Program.cs @@ -15,6 +15,9 @@ // You should have received a copy of the GNU Affero General Public License // along with this program. If not, see . +// In benchmarks, Random can be used +#pragma warning disable SEC0115 + using System; using System.Diagnostics; using System.Linq; @@ -84,7 +87,7 @@ private static async Task Main() benchOptions); using var _ = logger.BeginPropertyScope(("@benchOptions", benchOptions)); - var channelPool = new ObjectPool(() => GrpcChannelFactory.CreateChannel(options)); + var channelPool = new ObjectPool(() => GrpcChannelFactory.CreateChannel(options!)); // Get List of partitions for logging purpose var partitions = await channelPool.WithInstanceAsync(async channel => diff --git a/Tests/Bench/Server/src/BenchComputerService.cs b/Tests/Bench/Server/src/BenchComputerService.cs index 0578c5e0c..eea585570 100644 --- a/Tests/Bench/Server/src/BenchComputerService.cs +++ b/Tests/Bench/Server/src/BenchComputerService.cs @@ -15,6 +15,9 @@ // You should have received a copy of the GNU Affero General Public License // along with this program. If not, see . +// In samples, Random can be used +#pragma warning disable SEC0115 + using System; using System.Collections.Generic; using System.Threading.Tasks; @@ -30,6 +33,7 @@ using Microsoft.Extensions.Logging; + namespace ArmoniK.Samples.Bench.Server; [UsedImplicitly] diff --git a/Tests/Bench/Server/src/GlobalSuppressions.cs b/Tests/Bench/Server/src/GlobalSuppressions.cs new file mode 100644 index 000000000..2ebdbfefb --- /dev/null +++ b/Tests/Bench/Server/src/GlobalSuppressions.cs @@ -0,0 +1,8 @@ +// This file is used by Code Analysis to maintain SuppressMessage +// attributes that are applied to this project. +// Project-level suppressions either have no target or are given +// a specific target and scoped to a namespace, type, member, etc. + +using System.Diagnostics.CodeAnalysis; + +[assembly: SuppressMessage("CodeQuality", "IDE0079:Remove unnecessary suppression", Justification = "")] diff --git a/Tests/Common/Client/src/ConnectionTest.cs b/Tests/Common/Client/src/ConnectionTest.cs index 7f5a02fe6..892c50e59 100644 --- a/Tests/Common/Client/src/ConnectionTest.cs +++ b/Tests/Common/Client/src/ConnectionTest.cs @@ -43,7 +43,7 @@ public void TearDown() channel_ = null; } - private const string rootFolder = "../../../../../../../"; + private const string RootFolder = "../../../../../../../"; private ChannelBase? channel_; @@ -99,7 +99,7 @@ public void ConnectionShouldSucceed(string endpoint, { "GrpcClient:CertP12", string.IsNullOrEmpty(clientCertP12) ? "" - : Path.GetFullPath(Path.Combine(rootFolder, + : Path.GetFullPath(Path.Combine(RootFolder, clientCertP12)) }, { @@ -107,7 +107,7 @@ public void ConnectionShouldSucceed(string endpoint, ? "" : string.IsNullOrEmpty(caFile) ? "" - : Path.GetFullPath(Path.Combine(rootFolder, + : Path.GetFullPath(Path.Combine(RootFolder, caFile)) }, { diff --git a/Tests/HtcMock/Client/src/Program.cs b/Tests/HtcMock/Client/src/Program.cs index ecc4b13b6..b0f249884 100644 --- a/Tests/HtcMock/Client/src/Program.cs +++ b/Tests/HtcMock/Client/src/Program.cs @@ -57,7 +57,7 @@ private static int Main() var optionsHtcMock = new Options.HtcMock(); configuration.GetSection(Options.HtcMock.SettingSection) .Bind(optionsHtcMock); - var channel = GrpcChannelFactory.CreateChannel(options); + var channel = GrpcChannelFactory.CreateChannel(options!); var gridClient = new GridClient(channel, factory, diff --git a/Tests/HtcMock/Client/src/SessionClient.cs b/Tests/HtcMock/Client/src/SessionClient.cs index 9711d2aec..2cd88b989 100644 --- a/Tests/HtcMock/Client/src/SessionClient.cs +++ b/Tests/HtcMock/Client/src/SessionClient.cs @@ -36,7 +36,7 @@ namespace ArmoniK.Samples.HtcMock.Client; -public class SessionClient : ISessionClient +public sealed class SessionClient : ISessionClient { private readonly ChannelBase channel_; private readonly ILogger logger_; @@ -75,7 +75,9 @@ public byte[] GetResult(string id) Session = sessionId_, }; +#pragma warning disable CS0612 // Type or member is obsolete var availabilityReply = submitterClient_.WaitForAvailability(resultRequest); +#pragma warning restore CS0612 // Type or member is obsolete switch (availabilityReply.TypeCase) { @@ -103,7 +105,9 @@ public Task WaitSubtasksCompletion(string id) Session = sessionId_, }; +#pragma warning disable CS0612 // Type or member is obsolete var availabilityReply = submitterClient_.WaitForAvailability(resultRequest); +#pragma warning restore CS0612 // Type or member is obsolete switch (availabilityReply.TypeCase) { diff --git a/Tests/Stream/Client/CreateSessionTests.cs b/Tests/Stream/Client/CreateSessionTests.cs index d0eea83be..9b693985c 100644 --- a/Tests/Stream/Client/CreateSessionTests.cs +++ b/Tests/Stream/Client/CreateSessionTests.cs @@ -84,7 +84,6 @@ public void NullDefaultTaskOptionShouldThrowException() [Test] public void SessionShouldBeCreated() { - var sessionId = Guid.NewGuid() + "mytestsession"; Console.WriteLine("SessionShouldBeCreated"); var createSessionReply = client_!.CreateSession(new CreateSessionRequest diff --git a/Tests/Stream/Client/GlobalSuppressions.cs b/Tests/Stream/Client/GlobalSuppressions.cs new file mode 100644 index 000000000..2ebdbfefb --- /dev/null +++ b/Tests/Stream/Client/GlobalSuppressions.cs @@ -0,0 +1,8 @@ +// This file is used by Code Analysis to maintain SuppressMessage +// attributes that are applied to this project. +// Project-level suppressions either have no target or are given +// a specific target and scoped to a namespace, type, member, etc. + +using System.Diagnostics.CodeAnalysis; + +[assembly: SuppressMessage("CodeQuality", "IDE0079:Remove unnecessary suppression", Justification = "")] diff --git a/Tests/Stream/Client/StreamWrapperTests.cs b/Tests/Stream/Client/StreamWrapperTests.cs index 9483be2bd..60ce88ee1 100644 --- a/Tests/Stream/Client/StreamWrapperTests.cs +++ b/Tests/Stream/Client/StreamWrapperTests.cs @@ -15,6 +15,9 @@ // You should have received a copy of the GNU Affero General Public License // along with this program. If not, see . +// In test, Random can be used +#pragma warning disable SEC0115 + using System; using System.Collections.Generic; using System.Diagnostics; diff --git a/Tests/Stream/Client/SubmitterExt.cs b/Tests/Stream/Client/SubmitterExt.cs index 6a9a35f02..f9b6cadeb 100644 --- a/Tests/Stream/Client/SubmitterExt.cs +++ b/Tests/Stream/Client/SubmitterExt.cs @@ -66,20 +66,15 @@ public static async Task> CreateTasksAndCheckReplyAsync(this case CreateTaskReply.ResponseOneofCase.None: throw new Exception("Issue with Server !"); case CreateTaskReply.ResponseOneofCase.CreationStatusList: - return createTaskReply.CreationStatusList.CreationStatuses.Select(status => - { - switch (status.StatusCase) - { - case CreateTaskReply.Types.CreationStatus.StatusOneofCase.None: - throw new Exception("Issue with Server !"); - case CreateTaskReply.Types.CreationStatus.StatusOneofCase.TaskInfo: - return status.TaskInfo.TaskId; - case CreateTaskReply.Types.CreationStatus.StatusOneofCase.Error: - return status.Error; - default: - throw new ArgumentOutOfRangeException(); - } - }); + return createTaskReply.CreationStatusList.CreationStatuses.Select(status => status.StatusCase switch + { + CreateTaskReply.Types.CreationStatus.StatusOneofCase.None => + throw new Exception("Issue with Server !"), + CreateTaskReply.Types.CreationStatus.StatusOneofCase.TaskInfo => status.TaskInfo + .TaskId, + CreateTaskReply.Types.CreationStatus.StatusOneofCase.Error => status.Error, + _ => throw new ArgumentOutOfRangeException(), + }); case CreateTaskReply.ResponseOneofCase.Error: throw new Exception("Error : " + createTaskReply.Error); default: diff --git a/Utils/src/IQueryableExt.cs b/Utils/src/IQueryableExt.cs index ed0c53076..7c897858c 100644 --- a/Utils/src/IQueryableExt.cs +++ b/Utils/src/IQueryableExt.cs @@ -22,7 +22,7 @@ namespace ArmoniK.Core.Utils; -public static class IQueryableExt +public static class QueryableExt { public static IOrderedQueryable OrderByList(this IQueryable queryable, ICollection>> orderFields, From 547c46e49e84e0eceef6152da7ea12c6bca71419 Mon Sep 17 00:00:00 2001 From: wkirschenmann Date: Wed, 9 Aug 2023 17:33:36 +0200 Subject: [PATCH 02/21] Update AuthenticationIntegrationTest.cs Revert unused parameter suppression. --- Common/tests/Auth/AuthenticationIntegrationTest.cs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/Common/tests/Auth/AuthenticationIntegrationTest.cs b/Common/tests/Auth/AuthenticationIntegrationTest.cs index 9096104f5..42c8efd5a 100644 --- a/Common/tests/Auth/AuthenticationIntegrationTest.cs +++ b/Common/tests/Auth/AuthenticationIntegrationTest.cs @@ -52,6 +52,8 @@ using Grpc.Core; +using JetBrains.Annotations; + using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Logging; @@ -1151,6 +1153,7 @@ public void TransformResult(IdentityIndex initialUserIndex, } [NonParallelizable] + [PublicAPI] // removes a warning about unused parameter [TestCaseSource(nameof(GetTestReflectionCases), new object?[] { @@ -1179,7 +1182,9 @@ public void TransformResult(IdentityIndex initialUserIndex, false, true, })] - public void AuthenticationShouldMatch(CaseParameters parameters) + public void AuthenticationShouldMatch(CaseParameters parameters, + TRequest requestExample, + TReply replyExample) { TransformResult(parameters.IdentityIndex, parameters.ImpersonationType, From 0a4f2d1a4d0a298be413a19fc5446665b0c771d4 Mon Sep 17 00:00:00 2001 From: wkirschenmann Date: Wed, 9 Aug 2023 22:37:13 +0200 Subject: [PATCH 03/21] Update AuthenticationIntegrationTest.cs Restore some implicit PublicAPI for tests. --- Common/tests/Auth/AuthenticationIntegrationTest.cs | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/Common/tests/Auth/AuthenticationIntegrationTest.cs b/Common/tests/Auth/AuthenticationIntegrationTest.cs index 42c8efd5a..2869edece 100644 --- a/Common/tests/Auth/AuthenticationIntegrationTest.cs +++ b/Common/tests/Auth/AuthenticationIntegrationTest.cs @@ -1182,6 +1182,9 @@ public void TransformResult(IdentityIndex initialUserIndex, false, true, })] + [SuppressMessage("Style", + "IDE0060:Remove unused parameter", + Justification = "Required for TestCaseSource")] public void AuthenticationShouldMatch(CaseParameters parameters, TRequest requestExample, TReply replyExample) @@ -1301,8 +1304,14 @@ public static IEnumerable GetAuthServiceTestCaseSource() return GetCases(methodObjectList); } + [PublicAPI] [TestCaseSource(nameof(GetAuthServiceTestCaseSource))] - public async Task AuthServiceShouldGiveUserInfo(CaseParameters parameters) + [SuppressMessage("Style", + "IDE0060:Remove unused parameter", + Justification = "Required for reflexion")] + public async Task AuthServiceShouldGiveUserInfo(CaseParameters parameters, + object exampleRequest, + object exampleReply) { TransformResult(parameters.IdentityIndex, parameters.ImpersonationType, From eaafe7c79da3878cdac166056f614a8def8bac50 Mon Sep 17 00:00:00 2001 From: wkirschenmann Date: Thu, 10 Aug 2023 10:54:06 +0200 Subject: [PATCH 04/21] Clean some code --- Adaptors/Amqp/src/ConnectionAmqp.cs | 24 +++---- Adaptors/Memory/src/QueueStorage.cs | 14 +++-- Adaptors/MongoDB/src/IMongoQueryableExt.cs | 4 +- Adaptors/RabbitMQ/src/ConnectionRabbit.cs | 25 ++++---- .../Helpers/GrpcSubmitterServiceHelper.cs | 5 +- .../tests/Helpers/TestPollingAgentProvider.cs | 15 ++--- .../ToApplicationFieldTest.cs | 20 +++--- .../ToApplicationFilterTest.cs | 62 +++++++++---------- .../src/{IQueryableExt.cs => QueryableExt.cs} | 0 9 files changed, 84 insertions(+), 85 deletions(-) rename Utils/src/{IQueryableExt.cs => QueryableExt.cs} (100%) diff --git a/Adaptors/Amqp/src/ConnectionAmqp.cs b/Adaptors/Amqp/src/ConnectionAmqp.cs index 80ceb3a58..17a501174 100644 --- a/Adaptors/Amqp/src/ConnectionAmqp.cs +++ b/Adaptors/Amqp/src/ConnectionAmqp.cs @@ -54,17 +54,17 @@ public ConnectionAmqp(QueueCommon.Amqp options, public Task Check(HealthCheckTag tag) => tag switch - { - HealthCheckTag.Startup or HealthCheckTag.Readiness => Task.FromResult(isInitialized_ - ? HealthCheckResult.Healthy() - : HealthCheckResult.Unhealthy($"{nameof(ConnectionAmqp)} is not yet initialized.")), - HealthCheckTag.Liveness => Task.FromResult(isInitialized_ && Connection is not null && Connection.ConnectionState == ConnectionState.Opened - ? HealthCheckResult.Healthy() - : HealthCheckResult.Unhealthy($"{nameof(ConnectionAmqp)} not initialized or connection dropped.")), - _ => throw new ArgumentOutOfRangeException(nameof(tag), + { + HealthCheckTag.Startup or HealthCheckTag.Readiness => Task.FromResult(isInitialized_ + ? HealthCheckResult.Healthy() + : HealthCheckResult.Unhealthy($"{nameof(ConnectionAmqp)} is not yet initialized.")), + HealthCheckTag.Liveness => Task.FromResult(isInitialized_ && Connection is not null && Connection.ConnectionState == ConnectionState.Opened + ? HealthCheckResult.Healthy() + : HealthCheckResult.Unhealthy($"{nameof(ConnectionAmqp)} not initialized or connection dropped.")), + _ => throw new ArgumentOutOfRangeException(nameof(tag), tag, null), - }; + }; public async Task Init(CancellationToken cancellationToken = default) => await connectionTask_; @@ -107,7 +107,7 @@ private static async Task InitTask(ConnectionAmqp conn, { conn.Connection = await connectionFactory.CreateAsync(address) .ConfigureAwait(false); - conn.Connection.AddClosedCallback((x, + conn.Connection.AddClosedCallback((_, e) => OnCloseConnection(e, conn.logger_)); break; @@ -130,8 +130,8 @@ await Task.Delay(1000 * retry, conn.isInitialized_ = true; } - private static void OnCloseConnection(Error? error, - ILogger logger) + private static void OnCloseConnection(Error? error, + ILogger logger) { if (error == null) { diff --git a/Adaptors/Memory/src/QueueStorage.cs b/Adaptors/Memory/src/QueueStorage.cs index 1fb718783..ba4644c0a 100644 --- a/Adaptors/Memory/src/QueueStorage.cs +++ b/Adaptors/Memory/src/QueueStorage.cs @@ -30,7 +30,7 @@ namespace ArmoniK.Core.Adapters.Memory; -public class QueueStorage : IQueueStorage +public class QueueStorage : IPullQueueStorage, IPushQueueStorage { private static readonly MessageHandler DefaultMessage = new(); @@ -53,6 +53,8 @@ public Task Init(CancellationToken cancellationToken) public int MaxPriority => 100; + + /// public async IAsyncEnumerable PullMessagesAsync(int nbMessages, [EnumeratorCancellation] CancellationToken cancellationToken = default) { @@ -91,17 +93,17 @@ await message.Semaphore.WaitAsync(CancellationToken.None) } /// - public Task PushMessagesAsync(IEnumerable messages, - int priority = 1, - CancellationToken cancellationToken = default) + public Task PushMessagesAsync(IEnumerable messages, + string _, + CancellationToken cancellationToken = default) { cancellationToken.ThrowIfCancellationRequested(); var messageHandlers = messages.Select(message => new MessageHandler { IsVisible = true, - Priority = priority, - TaskId = message, + Priority = message.Options.Priority, + TaskId = message.TaskId, CancellationToken = CancellationToken.None, Status = QueueMessageStatus.Waiting, Queues = queues_, diff --git a/Adaptors/MongoDB/src/IMongoQueryableExt.cs b/Adaptors/MongoDB/src/IMongoQueryableExt.cs index a5e828f7a..852b395e2 100644 --- a/Adaptors/MongoDB/src/IMongoQueryableExt.cs +++ b/Adaptors/MongoDB/src/IMongoQueryableExt.cs @@ -46,8 +46,8 @@ public static async IAsyncEnumerable ToAsyncEnumerable(this } - public static async IAsyncEnumerable ToAsyncEnumerable(this IFindFluent findFluent, - [EnumeratorCancellation] CancellationToken cancellationToken = default) + public static async IAsyncEnumerable ToAsyncEnumerable(this IFindFluent findFluent, + [EnumeratorCancellation] CancellationToken cancellationToken = default) { var cursor = await findFluent.ToCursorAsync(cancellationToken) .ConfigureAwait(false); diff --git a/Adaptors/RabbitMQ/src/ConnectionRabbit.cs b/Adaptors/RabbitMQ/src/ConnectionRabbit.cs index d5da38162..ec24043c3 100644 --- a/Adaptors/RabbitMQ/src/ConnectionRabbit.cs +++ b/Adaptors/RabbitMQ/src/ConnectionRabbit.cs @@ -61,17 +61,17 @@ public async Task Init(CancellationToken cancellationToken = default) public Task Check(HealthCheckTag tag) => tag switch - { - HealthCheckTag.Startup or HealthCheckTag.Readiness => Task.FromResult(isInitialized_ - ? HealthCheckResult.Healthy() - : HealthCheckResult.Unhealthy($"{nameof(ConnectionRabbit)} is not yet initialized.")), - HealthCheckTag.Liveness => Task.FromResult(isInitialized_ && Connection is not null && Connection.IsOpen && Channel is not null && Channel.IsOpen - ? HealthCheckResult.Healthy() - : HealthCheckResult.Unhealthy($"{nameof(ConnectionRabbit)} not initialized or connection dropped.")), - _ => throw new ArgumentOutOfRangeException(nameof(tag), + { + HealthCheckTag.Startup or HealthCheckTag.Readiness => Task.FromResult(isInitialized_ + ? HealthCheckResult.Healthy() + : HealthCheckResult.Unhealthy($"{nameof(ConnectionRabbit)} is not yet initialized.")), + HealthCheckTag.Liveness => Task.FromResult(isInitialized_ && Connection is not null && Connection.IsOpen && Channel is not null && Channel.IsOpen + ? HealthCheckResult.Healthy() + : HealthCheckResult.Unhealthy($"{nameof(ConnectionRabbit)} not initialized or connection dropped.")), + _ => throw new ArgumentOutOfRangeException(nameof(tag), tag, null), - }; + }; public void Dispose() { @@ -128,13 +128,13 @@ private async Task InitTask(ConnectionRabbit conn, try { conn.Connection = factory.CreateConnection(); - conn.Connection.ConnectionShutdown += (obj, + conn.Connection.ConnectionShutdown += (_, ea) => OnShutDown(ea, "Connection", logger_); Channel = conn.Connection.CreateModel(); - Channel.ModelShutdown += (obj, + Channel.ModelShutdown += (_, ea) => OnShutDown(ea, "Channel", logger_); @@ -164,7 +164,8 @@ private static void OnShutDown(ShutdownEventArgs ea, { if (ea.Cause is null) { - logger.LogInformation("RabbitMQ {model} closed with no error", model); + logger.LogInformation("RabbitMQ {model} closed with no error", + model); } else { diff --git a/Common/tests/Helpers/GrpcSubmitterServiceHelper.cs b/Common/tests/Helpers/GrpcSubmitterServiceHelper.cs index c390a3be3..9d1a6f20f 100644 --- a/Common/tests/Helpers/GrpcSubmitterServiceHelper.cs +++ b/Common/tests/Helpers/GrpcSubmitterServiceHelper.cs @@ -42,9 +42,9 @@ namespace ArmoniK.Core.Common.Tests.Helpers; public class GrpcSubmitterServiceHelper : IDisposable { private readonly WebApplication app_; + private readonly Mutex channelMutex_ = new(); private readonly ILoggerFactory loggerFactory_; private ChannelBase? channel_; - private readonly Mutex channelMutex_ = new (); private HttpMessageHandler? handler_; private TestServer? server_; @@ -88,8 +88,7 @@ public GrpcSubmitterServiceHelper(ISubmitter submitter, serviceConfigurator?.Invoke(builder.Services); builder.WebHost.UseTestServer(options => options.PreserveExecutionContext = true); - loggerFactory_.CreateLogger("Testing apps"); - app_ = builder.Build(); + app_ = builder.Build(); app_.UseRouting(); app_.UseAuthentication(); app_.UseAuthorization(); diff --git a/Common/tests/Helpers/TestPollingAgentProvider.cs b/Common/tests/Helpers/TestPollingAgentProvider.cs index a4cb85920..56c88ba07 100644 --- a/Common/tests/Helpers/TestPollingAgentProvider.cs +++ b/Common/tests/Helpers/TestPollingAgentProvider.cs @@ -60,7 +60,7 @@ public class TestPollingAgentProvider : IDisposable public TestPollingAgentProvider(IWorkerStreamHandler workerStreamHandler) { - var logger = NullLogger.Instance; + var logger = NullLogger.Instance; var options = new MongoRunnerOptions { UseSingleNodeReplicaSet = false, @@ -68,7 +68,7 @@ public TestPollingAgentProvider(IWorkerStreamHandler workerStreamHandler) StandardOuputLogger = line => logger.LogInformation(line), StandardErrorLogger = line => logger.LogError(line), #pragma warning restore CA2254 - }; + }; runner_ = MongoRunner.Run(options); IMongoClient client = new MongoClient(runner_.ConnectionString); @@ -124,18 +124,15 @@ public TestPollingAgentProvider(IWorkerStreamHandler workerStreamHandler) builder.Services.AddSingleton(computePlanOptions); app_ = builder.Build(); - - app_.Services.GetRequiredService(); - app_.Services.GetRequiredService(); var sessionTable = app_.Services.GetRequiredService(); - Submitter = app_.Services.GetRequiredService(); + Submitter = app_.Services.GetRequiredService(); var pollster = app_.Services.GetRequiredService(); sessionTable.Init(CancellationToken.None) - .Wait(); + .Wait(); pollsterRunningTask_ = Task.Factory.StartNew(() => pollster.MainLoop(pollsterCancellationTokenSource_.Token), - TaskCreationOptions.LongRunning); + TaskCreationOptions.LongRunning); } public void Dispose() @@ -144,7 +141,7 @@ public void Dispose() pollsterRunningTask_?.Wait(); pollsterRunningTask_?.Dispose(); pollsterCancellationTokenSource_?.Dispose(); - ((IDisposable)app_)?.Dispose(); + (app_ as IDisposable)?.Dispose(); loggerFactory_?.Dispose(); runner_?.Dispose(); GC.SuppressFinalize(this); diff --git a/Common/tests/ListApplicationsRequestExt/ToApplicationFieldTest.cs b/Common/tests/ListApplicationsRequestExt/ToApplicationFieldTest.cs index bb3cb6ea7..b58181758 100644 --- a/Common/tests/ListApplicationsRequestExt/ToApplicationFieldTest.cs +++ b/Common/tests/ListApplicationsRequestExt/ToApplicationFieldTest.cs @@ -79,18 +79,18 @@ public class ToApplicationFieldTest public static IEnumerable TestCasesInvoke() { - yield return Case(ApplicationRawEnumField.Service, - Options.ApplicationService); - yield return Case(ApplicationRawEnumField.Name, - Options.ApplicationName); - yield return Case(ApplicationRawEnumField.Namespace, - Options.ApplicationNamespace); - yield return Case(ApplicationRawEnumField.Version, - Options.ApplicationVersion); + yield return FieldToTestCase(ApplicationRawEnumField.Service, + Options.ApplicationService); + yield return FieldToTestCase(ApplicationRawEnumField.Name, + Options.ApplicationName); + yield return FieldToTestCase(ApplicationRawEnumField.Namespace, + Options.ApplicationNamespace); + yield return FieldToTestCase(ApplicationRawEnumField.Version, + Options.ApplicationVersion); } - private static TestCaseData Case(ApplicationRawEnumField field, - object? expected) + private static TestCaseData FieldToTestCase(ApplicationRawEnumField field, + object? expected) => new TestCaseData(new ApplicationRawField { Field = field, diff --git a/Common/tests/ListApplicationsRequestExt/ToApplicationFilterTest.cs b/Common/tests/ListApplicationsRequestExt/ToApplicationFilterTest.cs index ea74721b8..d13a30758 100644 --- a/Common/tests/ListApplicationsRequestExt/ToApplicationFilterTest.cs +++ b/Common/tests/ListApplicationsRequestExt/ToApplicationFilterTest.cs @@ -153,13 +153,6 @@ public void Filter2(IEnumerable filterFields, public static IEnumerable TestCasesFilter() { - TestCaseData CaseTrue(FilterField filterField) - => new TestCaseData(new[] - { - filterField, - }, - true).SetArgDisplayNames(filterField.ToString()); - TestCaseData CaseFalse(FilterField filterField) => new TestCaseData(new[] { @@ -167,44 +160,51 @@ TestCaseData CaseFalse(FilterField filterField) }, false).SetArgDisplayNames(filterField.ToString()); - yield return CaseTrue(CreateListApplicationsFilterString(ApplicationRawEnumField.Name, - FilterStringOperator.Equal, - ApplicationName)); + yield return FieldToTestCaseTrue(CreateListApplicationsFilterString(ApplicationRawEnumField.Name, + FilterStringOperator.Equal, + ApplicationName)); yield return CaseFalse(CreateListApplicationsFilterString(ApplicationRawEnumField.Name, FilterStringOperator.Equal, ApplicationName + "bad")); - yield return CaseTrue(CreateListApplicationsFilterString(ApplicationRawEnumField.Namespace, - FilterStringOperator.Equal, - ApplicationNamespace)); + yield return FieldToTestCaseTrue(CreateListApplicationsFilterString(ApplicationRawEnumField.Namespace, + FilterStringOperator.Equal, + ApplicationNamespace)); yield return CaseFalse(CreateListApplicationsFilterString(ApplicationRawEnumField.Namespace, FilterStringOperator.Equal, ApplicationNamespace + "bad")); - yield return CaseTrue(CreateListApplicationsFilterString(ApplicationRawEnumField.Version, - FilterStringOperator.Equal, - ApplicationVersion)); + yield return FieldToTestCaseTrue(CreateListApplicationsFilterString(ApplicationRawEnumField.Version, + FilterStringOperator.Equal, + ApplicationVersion)); yield return CaseFalse(CreateListApplicationsFilterString(ApplicationRawEnumField.Version, FilterStringOperator.Equal, ApplicationVersion + "bad")); - yield return CaseTrue(CreateListApplicationsFilterString(ApplicationRawEnumField.Service, - FilterStringOperator.Equal, - ApplicationService)); - yield return CaseTrue(CreateListApplicationsFilterString(ApplicationRawEnumField.Service, - FilterStringOperator.StartsWith, - ApplicationService)); - yield return CaseTrue(CreateListApplicationsFilterString(ApplicationRawEnumField.Service, - FilterStringOperator.EndsWith, - ApplicationService)); - yield return CaseTrue(CreateListApplicationsFilterString(ApplicationRawEnumField.Service, - FilterStringOperator.Contains, - ApplicationService)); - yield return CaseTrue(CreateListApplicationsFilterString(ApplicationRawEnumField.Service, - FilterStringOperator.NotContains, - ApplicationService + "bad")); + yield return FieldToTestCaseTrue(CreateListApplicationsFilterString(ApplicationRawEnumField.Service, + FilterStringOperator.Equal, + ApplicationService)); + yield return FieldToTestCaseTrue(CreateListApplicationsFilterString(ApplicationRawEnumField.Service, + FilterStringOperator.StartsWith, + ApplicationService)); + yield return FieldToTestCaseTrue(CreateListApplicationsFilterString(ApplicationRawEnumField.Service, + FilterStringOperator.EndsWith, + ApplicationService)); + yield return FieldToTestCaseTrue(CreateListApplicationsFilterString(ApplicationRawEnumField.Service, + FilterStringOperator.Contains, + ApplicationService)); + yield return FieldToTestCaseTrue(CreateListApplicationsFilterString(ApplicationRawEnumField.Service, + FilterStringOperator.NotContains, + ApplicationService + "bad")); yield return CaseFalse(CreateListApplicationsFilterString(ApplicationRawEnumField.Service, FilterStringOperator.Equal, ApplicationService + "bad")); } + + private static TestCaseData FieldToTestCaseTrue(FilterField filterField) + => new TestCaseData(new[] + { + filterField, + }, + true).SetArgDisplayNames(filterField.ToString()); } diff --git a/Utils/src/IQueryableExt.cs b/Utils/src/QueryableExt.cs similarity index 100% rename from Utils/src/IQueryableExt.cs rename to Utils/src/QueryableExt.cs From dd34c5e5235ca60243772f820e890f793fcb9a5d Mon Sep 17 00:00:00 2001 From: wkirschenmann Date: Thu, 10 Aug 2023 11:07:37 +0200 Subject: [PATCH 05/21] Add missing using --- Common/tests/Auth/AuthenticationIntegrationTest.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/Common/tests/Auth/AuthenticationIntegrationTest.cs b/Common/tests/Auth/AuthenticationIntegrationTest.cs index 2869edece..2ffa048ba 100644 --- a/Common/tests/Auth/AuthenticationIntegrationTest.cs +++ b/Common/tests/Auth/AuthenticationIntegrationTest.cs @@ -19,6 +19,7 @@ using System.Collections; using System.Collections.Generic; using System.Collections.ObjectModel; +using System.Diagnostics.CodeAnalysis; using System.Linq; using System.Reflection; using System.Threading; From 8052a99ccc8d48f668678741adbf7148b340d307 Mon Sep 17 00:00:00 2001 From: wkirschenmann Date: Thu, 10 Aug 2023 12:10:03 +0200 Subject: [PATCH 06/21] Support an unknown version of core Co-authored-by: lemaitre-aneo <91961298+lemaitre-aneo@users.noreply.github.com> --- Common/src/Utils/LoggerInit.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Common/src/Utils/LoggerInit.cs b/Common/src/Utils/LoggerInit.cs index 1fee8c8ee..1f7422131 100644 --- a/Common/src/Utils/LoggerInit.cs +++ b/Common/src/Utils/LoggerInit.cs @@ -38,7 +38,7 @@ public LoggerInit(IConfiguration configuration) .Enrich.FromLogContext() .Enrich.WithProperty("CoreVersion", typeof(LoggerInit).Assembly.GetName() - .Version!) + .Version ?? "Unknown") .CreateLogger(); logger_ = LoggerFactory.Create(builder => builder.AddSerilog(loggerConfiguration_)) From 2ec340b67e0ca6d2dc19cb065c915f8a5d1e48ce Mon Sep 17 00:00:00 2001 From: wkirschenmann Date: Thu, 10 Aug 2023 13:41:58 +0200 Subject: [PATCH 07/21] Cleanup --- Common/src/Pollster/TaskHandler.cs | 38 +++++++------------ .../AdapterLoading/AdapterLoadingTest.cs | 8 ++-- 2 files changed, 17 insertions(+), 29 deletions(-) diff --git a/Common/src/Pollster/TaskHandler.cs b/Common/src/Pollster/TaskHandler.cs index b35775971..3215900e8 100644 --- a/Common/src/Pollster/TaskHandler.cs +++ b/Common/src/Pollster/TaskHandler.cs @@ -651,39 +651,27 @@ await taskTable_.ReleaseTask(taskData, { logger_.LogError(e, "Error during task execution, retrying task"); - - await submitter_.CompleteTaskAsync(taskData, - resubmit, - new Output - { - Error = new Output.Types.Error - { - Details = e.Message, - }, - }, - CancellationToken.None) - .ConfigureAwait(false); - messageHandler_.Status = QueueMessageStatus.Cancelled; } else { logger_.LogError(e, "Error during task execution, cancelling task"); - - await submitter_.CompleteTaskAsync(taskData, - resubmit, - new Output - { - Error = new Output.Types.Error - { - Details = e.Message, - }, - }, - CancellationToken.None) - .ConfigureAwait(false); messageHandler_.Status = QueueMessageStatus.Processed; } + + + await submitter_.CompleteTaskAsync(taskData, + resubmit, + new Output + { + Error = new Output.Types.Error + { + Details = e.Message, + }, + }, + CancellationToken.None) + .ConfigureAwait(false); } } diff --git a/Common/tests/AdapterLoading/AdapterLoadingTest.cs b/Common/tests/AdapterLoading/AdapterLoadingTest.cs index 50ce33a11..ea1017fa2 100644 --- a/Common/tests/AdapterLoading/AdapterLoadingTest.cs +++ b/Common/tests/AdapterLoading/AdapterLoadingTest.cs @@ -58,7 +58,7 @@ public static IEnumerable TestCasesQueueLocation } } - public static void Setup(Dictionary config) + public static void BuildServiceProvider(Dictionary config) { var loggerProvider = new ConsoleForwardingLoggerProvider(); var logger = loggerProvider.CreateLogger("root"); @@ -93,7 +93,7 @@ public void QueueShouldLoad(string path, }, }; - Assert.DoesNotThrow(() => Setup(config)); + Assert.DoesNotThrow(() => BuildServiceProvider(config)); } public static IEnumerable ConfInvalidOperationException @@ -163,7 +163,7 @@ public static IEnumerable ConfInvalidOperationException [Test] [TestCaseSource(nameof(ConfInvalidOperationException))] public void InvalidConfShouldFail(Dictionary config) - => Assert.Throws(() => Setup(config)); + => Assert.Throws(() => BuildServiceProvider(config)); public static IEnumerable ConfTypeLoadException { @@ -189,5 +189,5 @@ public static IEnumerable ConfTypeLoadException [Test] [TestCaseSource(nameof(ConfTypeLoadException))] public void InvalidTypeConfShouldFail(Dictionary config) - => Assert.Throws(() => Setup(config)); + => Assert.Throws(() => BuildServiceProvider(config)); } From c7cbb1b76bc6a8682c467e22c20d222a76e55cf8 Mon Sep 17 00:00:00 2001 From: wkirschenmann Date: Thu, 10 Aug 2023 14:03:23 +0200 Subject: [PATCH 08/21] fix support for unknown version --- Common/src/Utils/LoggerInit.cs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Common/src/Utils/LoggerInit.cs b/Common/src/Utils/LoggerInit.cs index 1f7422131..c2bda5ce5 100644 --- a/Common/src/Utils/LoggerInit.cs +++ b/Common/src/Utils/LoggerInit.cs @@ -15,6 +15,8 @@ // You should have received a copy of the GNU Affero General Public License // along with this program. If not, see . +using System; + using Microsoft.Extensions.Configuration; using Microsoft.Extensions.Logging; @@ -38,7 +40,7 @@ public LoggerInit(IConfiguration configuration) .Enrich.FromLogContext() .Enrich.WithProperty("CoreVersion", typeof(LoggerInit).Assembly.GetName() - .Version ?? "Unknown") + .Version?.ToString() ?? "Unknown") .CreateLogger(); logger_ = LoggerFactory.Create(builder => builder.AddSerilog(loggerConfiguration_)) From b2c4879f239d7673e4da0f4dd2809b59cbb7768e Mon Sep 17 00:00:00 2001 From: wkirschenmann Date: Thu, 10 Aug 2023 16:43:18 +0200 Subject: [PATCH 09/21] Clean code --- Adaptors/MongoDB/src/SessionTable.cs | 2 + Adaptors/MongoDB/src/TaskTable.cs | 3 +- Adaptors/RabbitMQ/src/PullQueueStorage.cs | 36 ++++++------- Adaptors/S3/src/ObjectStorage.cs | 20 ++++--- Base/src/IQueueMessageHandler.cs | 19 +++++++ .../src/Stream/Worker/WorkerStreamHandler.cs | 2 + .../Auth/AuthenticationIntegrationTest.cs | 4 +- .../Helpers/GrpcSubmitterServiceHelper.cs | 6 +-- Common/tests/Helpers/SimpleAgent.cs | 1 + .../tests/Helpers/SimplePullQueueStorage.cs | 52 +++++++++---------- .../ToApplicationFilterTest.cs | 25 ++++----- .../Submitter/GrpcSubmitterServiceTests.cs | 7 +++ .../IntegrationGrpcSubmitterServiceTest.cs | 2 + .../CreateLargeTaskRequestValidatorTest.cs | 3 -- Tests/Bench/Client/src/Program.cs | 4 +- Tests/HtcMock/Client/src/SessionClient.cs | 11 +++- Tests/Stream/Client/GlobalSuppressions.cs | 8 --- Tests/Stream/Client/StreamWrapperTests.cs | 16 +++++- Tests/Stream/Client/SubmitterExt.cs | 40 +++++++------- Tests/Stream/Server/WorkerService.cs | 9 ++-- 20 files changed, 161 insertions(+), 109 deletions(-) delete mode 100644 Tests/Stream/Client/GlobalSuppressions.cs diff --git a/Adaptors/MongoDB/src/SessionTable.cs b/Adaptors/MongoDB/src/SessionTable.cs index ec138edc6..7b24fda44 100644 --- a/Adaptors/MongoDB/src/SessionTable.cs +++ b/Adaptors/MongoDB/src/SessionTable.cs @@ -179,7 +179,9 @@ public async Task CancelSessionAsync(string sessionId, cancellationToken) .ConfigureAwait(false); +#pragma warning disable IDE0270 // null check can be simplified with a less readable approach if (resSession is null) +#pragma warning restore IDE0270 { throw new SessionNotFoundException($"No open session with key '{sessionId}' was found"); } diff --git a/Adaptors/MongoDB/src/TaskTable.cs b/Adaptors/MongoDB/src/TaskTable.cs index 172d2a031..8de871b35 100644 --- a/Adaptors/MongoDB/src/TaskTable.cs +++ b/Adaptors/MongoDB/src/TaskTable.cs @@ -287,8 +287,7 @@ public async IAsyncEnumerable ListTasksAsync(TaskFilter await foreach (var taskId in taskCollection.AsQueryable(sessionHandle) .FilterQuery(filter) .Select(model => model.TaskId) - .ToAsyncEnumerable() - .WithCancellation(cancellationToken) + .ToAsyncEnumerable(cancellationToken) .ConfigureAwait(false)) { yield return taskId; diff --git a/Adaptors/RabbitMQ/src/PullQueueStorage.cs b/Adaptors/RabbitMQ/src/PullQueueStorage.cs index 650dc3fd7..3b4b07d25 100644 --- a/Adaptors/RabbitMQ/src/PullQueueStorage.cs +++ b/Adaptors/RabbitMQ/src/PullQueueStorage.cs @@ -18,6 +18,7 @@ using System; using System.Collections.Concurrent; using System.Collections.Generic; +using System.Linq; using System.Runtime.CompilerServices; using System.Text; using System.Threading; @@ -155,6 +156,7 @@ Task Subscriber(object? model, consumer.Received += Subscriber; + ConnectionRabbit.Channel!.BasicConsume(pullQueue.QueueName, false, consumer); @@ -162,31 +164,29 @@ Task Subscriber(object? model, } } -#pragma warning disable CS1998 - public async IAsyncEnumerable PullMessagesAsync(int nbMessages, - [EnumeratorCancellation] CancellationToken cancellationToken = default) -#pragma warning restore CS1998 + public IAsyncEnumerable PullMessagesAsync(int nbMessages, + CancellationToken cancellationToken = default) { - var nbPulledMessage = 0; - if (!IsInitialized) { throw new InvalidOperationException($"{nameof(PullQueueStorage)} should be initialized before calling this method."); } cancellationToken.ThrowIfCancellationRequested(); - while (nbPulledMessage < nbMessages) - { - if (!queueMessageHandlers_!.TryDequeue(out var qmh)) - { - continue; - } - - nbPulledMessage++; - // Pass the cancellation token to the pulled handler - qmh!.CancellationToken = cancellationToken; - yield return qmh; - } + // using ToAsyncEnumerable avoids using a needless async operator + return Enumerable.Repeat(0, + nbMessages) + .Select(_ => + { + IQueueMessageHandler? qmh; + do + { + cancellationToken.ThrowIfCancellationRequested(); + } while (!queueMessageHandlers_!.TryDequeue(out qmh)); + + return qmh; + }) + .ToAsyncEnumerable(); } } diff --git a/Adaptors/S3/src/ObjectStorage.cs b/Adaptors/S3/src/ObjectStorage.cs index 8f3088d91..ce3d2fd14 100644 --- a/Adaptors/S3/src/ObjectStorage.cs +++ b/Adaptors/S3/src/ObjectStorage.cs @@ -161,10 +161,13 @@ public async Task TryDeleteAsync(string key, { using var _ = logger_.LogFunction(objectStorageName_ + key); var value = await s3Client_.StringGetValueAsync(bucketName_, - $"{objectStorageName_}{key}_count") + $"{objectStorageName_}{key}_count", + cancellationToken) .ConfigureAwait(false); +#pragma warning disable IDE0270 // null check can be simplifier but with a less readable approach if (value == null) +#pragma warning restore IDE0270 { throw new ObjectDataNotFoundException("Key not found"); } @@ -266,19 +269,20 @@ internal static async Task StringByteGetAsync(this AmazonS3Client s3Clie } internal static async Task StringGetValueAsync(this AmazonS3Client s3Client, - string bucketName, - string key) + string bucketName, + string key, + CancellationToken cancellationToken = default) { var response = await s3Client.GetObjectAsync(bucketName, - key); + key, + cancellationToken); // Get the data from the response stream await using var responseStream = response.ResponseStream; - + var retrievedData = new byte[responseStream.Length]; - _ = await responseStream.ReadAsync(retrievedData, - 0, - retrievedData.Length); + _ = await responseStream.ReadAsync(new Memory(retrievedData), + cancellationToken); return Encoding.UTF8.GetString(retrievedData); } } diff --git a/Base/src/IQueueMessageHandler.cs b/Base/src/IQueueMessageHandler.cs index ac6e34d4b..6b2f744c0 100644 --- a/Base/src/IQueueMessageHandler.cs +++ b/Base/src/IQueueMessageHandler.cs @@ -20,15 +20,34 @@ namespace ArmoniK.Core.Base; +/// +/// Interface to handle queue messages lifecycle. +/// public interface IQueueMessageHandler : IAsyncDisposable { + /// + /// Used to signal that the message ownership has been lost + /// + [Obsolete("ArmoniK now manages loss of link with the queue")] CancellationToken CancellationToken { get; set; } + /// + /// Id of the message + /// string MessageId { get; } + /// + /// Task Id contained in the message + /// string TaskId { get; } + /// + /// Status of the message. Used when the handler is disposed to notify the queue. + /// QueueMessageStatus Status { get; set; } + /// + /// Date of reception of the message + /// DateTime ReceptionDateTime { get; init; } } diff --git a/Common/src/Stream/Worker/WorkerStreamHandler.cs b/Common/src/Stream/Worker/WorkerStreamHandler.cs index 021361744..fb953f47c 100644 --- a/Common/src/Stream/Worker/WorkerStreamHandler.cs +++ b/Common/src/Stream/Worker/WorkerStreamHandler.cs @@ -115,7 +115,9 @@ await Task.Delay(optionsInitWorker_.WorkerCheckDelay * retry, var e = new ArmoniKException("Could not get grpc channel"); logger_.LogError(e, +#pragma warning disable CA2254 // string.Empty is constant string.Empty); +#pragma warning restore CA2254 throw e; } diff --git a/Common/tests/Auth/AuthenticationIntegrationTest.cs b/Common/tests/Auth/AuthenticationIntegrationTest.cs index 2ffa048ba..c595c6abb 100644 --- a/Common/tests/Auth/AuthenticationIntegrationTest.cs +++ b/Common/tests/Auth/AuthenticationIntegrationTest.cs @@ -1248,7 +1248,7 @@ public void AuthenticationShouldMatch(CaseParameters parameter ((RpcException)finalException!).StatusCode); } - helper_.DeleteChannel(channel) + GrpcSubmitterServiceHelper.DeleteChannel(channel) .Wait(); return; @@ -1391,7 +1391,7 @@ public async Task AuthServiceShouldGiveUserInfo(CaseParameters parameters, ((RpcException)exception.InnerException!).StatusCode); } - await helper_.DeleteChannel(channel) + await GrpcSubmitterServiceHelper.DeleteChannel(channel) .ConfigureAwait(false); } } diff --git a/Common/tests/Helpers/GrpcSubmitterServiceHelper.cs b/Common/tests/Helpers/GrpcSubmitterServiceHelper.cs index 9d1a6f20f..e3ec95272 100644 --- a/Common/tests/Helpers/GrpcSubmitterServiceHelper.cs +++ b/Common/tests/Helpers/GrpcSubmitterServiceHelper.cs @@ -27,6 +27,7 @@ using ArmoniK.Core.Common.Injection; using ArmoniK.Core.Common.Storage; using ArmoniK.Core.Common.Tests.Auth; +using ArmoniK.Utils; using Grpc.Core; using Grpc.Net.Client; @@ -116,8 +117,7 @@ public GrpcSubmitterServiceHelper(ISubmitter submitter, public void Dispose() { app_.DisposeAsync() - .GetAwaiter() - .GetResult(); + .WaitSync(); server_?.Dispose(); server_ = null; handler_?.Dispose(); @@ -159,7 +159,7 @@ await StartServer() ; } - public async Task DeleteChannel(ChannelBase channel) + public static async Task DeleteChannel(ChannelBase channel) => await channel.ShutdownAsync() .ConfigureAwait(false); diff --git a/Common/tests/Helpers/SimpleAgent.cs b/Common/tests/Helpers/SimpleAgent.cs index 7b7f4c136..9f9eed8e8 100644 --- a/Common/tests/Helpers/SimpleAgent.cs +++ b/Common/tests/Helpers/SimpleAgent.cs @@ -72,5 +72,6 @@ public Task CreateResults(CreateResultsRequest request, public void Dispose() { + GC.SuppressFinalize(this); } } diff --git a/Common/tests/Helpers/SimplePullQueueStorage.cs b/Common/tests/Helpers/SimplePullQueueStorage.cs index 045428979..0a243c454 100644 --- a/Common/tests/Helpers/SimplePullQueueStorage.cs +++ b/Common/tests/Helpers/SimplePullQueueStorage.cs @@ -18,6 +18,7 @@ using System; using System.Collections.Concurrent; using System.Collections.Generic; +using System.Linq; using System.Runtime.CompilerServices; using System.Threading; using System.Threading.Tasks; @@ -31,10 +32,7 @@ namespace ArmoniK.Core.Common.Tests.Helpers; public class SimplePullQueueStorage : IPullQueueStorage { - public readonly ConcurrentBag Messages; - - public SimplePullQueueStorage() - => Messages = new ConcurrentBag(); + public readonly ConcurrentBag Messages = new(); public Task Check(HealthCheckTag tag) => Task.FromResult(HealthCheckResult.Healthy()); @@ -42,27 +40,29 @@ public Task Check(HealthCheckTag tag) public Task Init(CancellationToken cancellationToken) => Task.CompletedTask; - public int MaxPriority { get; } = 10; + public int MaxPriority => 10; + -#pragma warning disable CS1998 - public async IAsyncEnumerable PullMessagesAsync(int nbMessages, -#pragma warning restore CS1998 - [EnumeratorCancellation] CancellationToken cancellationToken = default) - { - var i = 0; - while (i < nbMessages && Messages.TryTake(out var m)) - { - i++; - cancellationToken.ThrowIfCancellationRequested(); - yield return new SimpleQueueMessageHandler - { - CancellationToken = CancellationToken.None, - TaskId = m, - MessageId = Guid.NewGuid() - .ToString(), - Status = QueueMessageStatus.Running, - ReceptionDateTime = DateTime.UtcNow, - }; - } - } + public IAsyncEnumerable PullMessagesAsync(int nbMessages, + CancellationToken cancellationToken = default) + // using ToAsyncEnumerable avoids using an async function needlessly + => Enumerable.Repeat(0, + nbMessages) + .Select(_ => + { + var success = Messages.TryTake(out var m); + cancellationToken.ThrowIfCancellationRequested(); + return (success, message: m); + }) + .Where(tuple => tuple.success) + .Select(tuple => new SimpleQueueMessageHandler + { + CancellationToken = CancellationToken.None, + TaskId = tuple.message!, + MessageId = Guid.NewGuid() + .ToString(), + Status = QueueMessageStatus.Running, + ReceptionDateTime = DateTime.UtcNow, + } as IQueueMessageHandler) + .ToAsyncEnumerable(); } diff --git a/Common/tests/ListApplicationsRequestExt/ToApplicationFilterTest.cs b/Common/tests/ListApplicationsRequestExt/ToApplicationFilterTest.cs index d13a30758..d029055a5 100644 --- a/Common/tests/ListApplicationsRequestExt/ToApplicationFilterTest.cs +++ b/Common/tests/ListApplicationsRequestExt/ToApplicationFilterTest.cs @@ -153,31 +153,24 @@ public void Filter2(IEnumerable filterFields, public static IEnumerable TestCasesFilter() { - TestCaseData CaseFalse(FilterField filterField) - => new TestCaseData(new[] - { - filterField, - }, - false).SetArgDisplayNames(filterField.ToString()); - yield return FieldToTestCaseTrue(CreateListApplicationsFilterString(ApplicationRawEnumField.Name, FilterStringOperator.Equal, ApplicationName)); - yield return CaseFalse(CreateListApplicationsFilterString(ApplicationRawEnumField.Name, + yield return FieldToTestCaseFalse(CreateListApplicationsFilterString(ApplicationRawEnumField.Name, FilterStringOperator.Equal, ApplicationName + "bad")); yield return FieldToTestCaseTrue(CreateListApplicationsFilterString(ApplicationRawEnumField.Namespace, FilterStringOperator.Equal, ApplicationNamespace)); - yield return CaseFalse(CreateListApplicationsFilterString(ApplicationRawEnumField.Namespace, + yield return FieldToTestCaseFalse(CreateListApplicationsFilterString(ApplicationRawEnumField.Namespace, FilterStringOperator.Equal, ApplicationNamespace + "bad")); yield return FieldToTestCaseTrue(CreateListApplicationsFilterString(ApplicationRawEnumField.Version, FilterStringOperator.Equal, ApplicationVersion)); - yield return CaseFalse(CreateListApplicationsFilterString(ApplicationRawEnumField.Version, + yield return FieldToTestCaseFalse(CreateListApplicationsFilterString(ApplicationRawEnumField.Version, FilterStringOperator.Equal, ApplicationVersion + "bad")); @@ -196,15 +189,23 @@ TestCaseData CaseFalse(FilterField filterField) yield return FieldToTestCaseTrue(CreateListApplicationsFilterString(ApplicationRawEnumField.Service, FilterStringOperator.NotContains, ApplicationService + "bad")); - yield return CaseFalse(CreateListApplicationsFilterString(ApplicationRawEnumField.Service, + yield return FieldToTestCaseFalse(CreateListApplicationsFilterString(ApplicationRawEnumField.Service, FilterStringOperator.Equal, ApplicationService + "bad")); + yield break; } + private static TestCaseData FieldToTestCaseFalse(FilterField filterField) + => new TestCaseData(new[] + { + filterField, + }, + false).SetArgDisplayNames(filterField.ToString()!); + private static TestCaseData FieldToTestCaseTrue(FilterField filterField) => new TestCaseData(new[] { filterField, }, - true).SetArgDisplayNames(filterField.ToString()); + true).SetArgDisplayNames(filterField.ToString()!); } diff --git a/Common/tests/Submitter/GrpcSubmitterServiceTests.cs b/Common/tests/Submitter/GrpcSubmitterServiceTests.cs index c50c80d6b..8c371a305 100644 --- a/Common/tests/Submitter/GrpcSubmitterServiceTests.cs +++ b/Common/tests/Submitter/GrpcSubmitterServiceTests.cs @@ -1346,6 +1346,7 @@ await service.WaitForCompletion(new WaitRequest } [Test] + [Obsolete("Method tested is obsolete")] public async Task WaitForAvailabilityShouldSucceed() { var mockSubmitter = new Mock(); @@ -1376,6 +1377,7 @@ public async Task WaitForAvailabilityShouldSucceed() } [Test] + [Obsolete("Method tested is obsolete")] public async Task WaitForAvailabilityExceptionShouldThrow() { var mockSubmitter = new Mock(); @@ -1410,6 +1412,7 @@ await service.WaitForAvailability(new ResultRequest } [Test] + [Obsolete("Method tested is obsolete")] public async Task WaitForAvailabilityArmonikExceptionShouldThrow() { var mockSubmitter = new Mock(); @@ -1444,6 +1447,7 @@ await service.WaitForAvailability(new ResultRequest } [Test] + [Obsolete("Method tested is obsolete")] public async Task WaitForAvailabilityTaskNotFoundExceptionShouldThrow() { var mockSubmitter = new Mock(); @@ -1478,6 +1482,7 @@ await service.WaitForAvailability(new ResultRequest } [Test] + [Obsolete("Method tested is obsolete")] public async Task WaitForAvailabilityResultNotFoundExceptionShouldThrow() { var mockSubmitter = new Mock(); @@ -1804,6 +1809,7 @@ await service.ListTasks(new TaskFilter } [Test] + [Obsolete("Method tested is obsolete")] public async Task GetResultStatusAsyncArmoniKNotFoundExceptionShouldThrow() { var mock = new Mock(); @@ -1841,6 +1847,7 @@ await service.GetResultStatus(new GetResultStatusRequest } [Test] + [Obsolete("Method tested is obsolete")] public async Task GetResultStatusShouldSucceed() { var mock = new Mock(); diff --git a/Common/tests/Submitter/IntegrationGrpcSubmitterServiceTest.cs b/Common/tests/Submitter/IntegrationGrpcSubmitterServiceTest.cs index 94cd86887..a5e8878d8 100644 --- a/Common/tests/Submitter/IntegrationGrpcSubmitterServiceTest.cs +++ b/Common/tests/Submitter/IntegrationGrpcSubmitterServiceTest.cs @@ -617,6 +617,7 @@ await streamingCall.RequestStream.CompleteAsync() nameof(TestCasesOutputSessionNotFoundInternal))] [TestCaseSource(typeof(IntegrationGrpcSubmitterServiceTest), nameof(TestCasesOutputTaskNotFound))] + [Obsolete("Method tested is obsolete")] public async Task WaitForAvailabilityThrowsException(ISubmitter submitter) { helper_ = new GrpcSubmitterServiceHelper(submitter); @@ -686,6 +687,7 @@ await streamingCall.RequestStream.CompleteAsync() [Test] [TestCaseSource(typeof(IntegrationGrpcSubmitterServiceTest), nameof(TestCasesResultTable))] + [Obsolete("Method tested is obsolete")] public async Task GetResultStatusAsyncThrowsException(IResultTable resultTable) { helper_ = new GrpcSubmitterServiceHelper(mockSubmitter_.Object, diff --git a/Common/tests/Validators/CreateLargeTaskRequestValidatorTest.cs b/Common/tests/Validators/CreateLargeTaskRequestValidatorTest.cs index f6faa909b..3abdf8199 100644 --- a/Common/tests/Validators/CreateLargeTaskRequestValidatorTest.cs +++ b/Common/tests/Validators/CreateLargeTaskRequestValidatorTest.cs @@ -15,9 +15,6 @@ // You should have received a copy of the GNU Affero General Public License // along with this program. If not, see . -// In tests, Random can be used -#pragma warning disable SEC0115 - using System; using ArmoniK.Api.gRPC.V1; diff --git a/Tests/Bench/Client/src/Program.cs b/Tests/Bench/Client/src/Program.cs index 3f52b0337..b52a68521 100644 --- a/Tests/Bench/Client/src/Program.cs +++ b/Tests/Bench/Client/src/Program.cs @@ -15,8 +15,6 @@ // You should have received a copy of the GNU Affero General Public License // along with this program. If not, see . -// In benchmarks, Random can be used -#pragma warning disable SEC0115 using System; using System.Diagnostics; @@ -384,7 +382,9 @@ await results.ParallelForEach(new ParallelTaskOptions(benchOptions.DegreeOfParal Session = createSessionReply.SessionId, }; +#pragma warning disable CS0612 // Type or member is obsolete var availabilityReply = await submitterClient.WaitForAvailabilityAsync(resultRequest); +#pragma warning restore CS0612 // Type or member is obsolete switch (availabilityReply.TypeCase) { diff --git a/Tests/HtcMock/Client/src/SessionClient.cs b/Tests/HtcMock/Client/src/SessionClient.cs index 2cd88b989..663628c0e 100644 --- a/Tests/HtcMock/Client/src/SessionClient.cs +++ b/Tests/HtcMock/Client/src/SessionClient.cs @@ -67,6 +67,9 @@ public void Dispose() .Wait(); } + [System.Diagnostics.CodeAnalysis.SuppressMessage("Style", + "CA2208", + Justification = "availabilityReply.TypeCase is not a real argument")] public byte[] GetResult(string id) { var resultRequest = new ResultRequest @@ -97,6 +100,9 @@ public byte[] GetResult(string id) return response.Result; } + [System.Diagnostics.CodeAnalysis.SuppressMessage("Style", + "CA2208", + Justification = "availabilityReply.TypeCase is not a real argument")] public Task WaitSubtasksCompletion(string id) { var resultRequest = new ResultRequest @@ -126,6 +132,9 @@ public Task WaitSubtasksCompletion(string id) return Task.CompletedTask; } + [System.Diagnostics.CodeAnalysis.SuppressMessage("Style", + "CA2208", + Justification = "createTaskReply.ResponseCase is not a real argument")] public IEnumerable SubmitTasksWithDependencies(IEnumerable>> payloadsWithDependencies) { var taskRequests = new List(); @@ -180,7 +189,7 @@ public IEnumerable SubmitTasksWithDependencies(IEnumerable. -// In test, Random can be used -#pragma warning disable SEC0115 using System; using System.Collections.Generic; @@ -146,7 +144,9 @@ public async Task Square(int input) Session = sessionId, }; +#pragma warning disable CS0612 // Type or member is obsolete var availabilityReply = client_!.WaitForAvailability(resultRequest); +#pragma warning restore CS0612 // Type or member is obsolete Assert.AreEqual(availabilityReply.TypeCase, AvailabilityReply.TypeOneofCase.Ok); @@ -355,7 +355,9 @@ public async Task MultipleTasks([Values(4, ResultId = request.ExpectedOutputKeys.Single(), Session = sessionId, }; +#pragma warning disable CS0612 // Type or member is obsolete var availabilityReply = client_!.WaitForAvailability(resultRequest); +#pragma warning restore CS0612 // Type or member is obsolete return availabilityReply.TypeCase; }); @@ -449,7 +451,9 @@ public async Task MultipleDataDependencies([Values(1, ResultId = request.ExpectedOutputKeys.First(), Session = sessionId, }; +#pragma warning disable CS0612 // Type or member is obsolete var availabilityReply = client_!.WaitForAvailability(resultRequest); +#pragma warning restore CS0612 // Type or member is obsolete return availabilityReply.TypeCase; }); @@ -462,7 +466,9 @@ public async Task MultipleDataDependencies([Values(1, ResultId = request.ExpectedOutputKeys.Last(), Session = sessionId, }; +#pragma warning disable CS0612 // Type or member is obsolete var availabilityReply = client_!.WaitForAvailability(resultRequest); +#pragma warning restore CS0612 // Type or member is obsolete return availabilityReply.TypeCase; }); @@ -562,7 +568,9 @@ public async Task LargePayloads([Values(2, ResultId = request.ExpectedOutputKeys.Single(), Session = sessionId, }; +#pragma warning disable CS0612 // Type or member is obsolete var availabilityReply = client_!.WaitForAvailability(resultRequest); +#pragma warning restore CS0612 // Type or member is obsolete return availabilityReply.TypeCase; }); @@ -627,7 +635,9 @@ public async Task EmptyPayload() ResultId = outputId, Session = sessionId, }; +#pragma warning disable CS0612 // Type or member is obsolete var availabilityReply = client_!.WaitForAvailability(resultRequest); +#pragma warning restore CS0612 // Type or member is obsolete Assert.AreEqual(AvailabilityReply.TypeOneofCase.Error, availabilityReply.TypeCase); @@ -728,7 +738,9 @@ private async Task RunForPriority(string sessionId, ResultId = request.ExpectedOutputKeys.Single(), Session = sessionId, }; +#pragma warning disable CS0612 // Type or member is obsolete var availabilityReply = client_!.WaitForAvailability(resultRequest); +#pragma warning restore CS0612 // Type or member is obsolete return availabilityReply.TypeCase; }); diff --git a/Tests/Stream/Client/SubmitterExt.cs b/Tests/Stream/Client/SubmitterExt.cs index f9b6cadeb..b41936195 100644 --- a/Tests/Stream/Client/SubmitterExt.cs +++ b/Tests/Stream/Client/SubmitterExt.cs @@ -52,6 +52,10 @@ public static string CreateSessionAndCheckReply(this Submitter.SubmitterClient c return session.SessionId; } + + [System.Diagnostics.CodeAnalysis.SuppressMessage("Reliability", + "CA2208: Call the ArgumentOutOfRangeException constructor that contains a message and/or paramName parameter", + Justification = "createTaskReply.ResponseCase is not a real argument")] public static async Task> CreateTasksAndCheckReplyAsync(this Submitter.SubmitterClient client, string sessionId, TaskOptions? taskOptions, @@ -61,24 +65,22 @@ public static async Task> CreateTasksAndCheckReplyAsync(this taskOptions, taskRequestList) .ConfigureAwait(false); - switch (createTaskReply.ResponseCase) - { - case CreateTaskReply.ResponseOneofCase.None: - throw new Exception("Issue with Server !"); - case CreateTaskReply.ResponseOneofCase.CreationStatusList: - return createTaskReply.CreationStatusList.CreationStatuses.Select(status => status.StatusCase switch - { - CreateTaskReply.Types.CreationStatus.StatusOneofCase.None => - throw new Exception("Issue with Server !"), - CreateTaskReply.Types.CreationStatus.StatusOneofCase.TaskInfo => status.TaskInfo - .TaskId, - CreateTaskReply.Types.CreationStatus.StatusOneofCase.Error => status.Error, - _ => throw new ArgumentOutOfRangeException(), - }); - case CreateTaskReply.ResponseOneofCase.Error: - throw new Exception("Error : " + createTaskReply.Error); - default: - throw new ArgumentOutOfRangeException(); - } + + return createTaskReply.ResponseCase switch + { + CreateTaskReply.ResponseOneofCase.None => throw new Exception("Issue with Server !"), + CreateTaskReply.ResponseOneofCase.CreationStatusList => createTaskReply.CreationStatusList.CreationStatuses.Select(StatusToString), + CreateTaskReply.ResponseOneofCase.Error => throw new Exception("Error : " + createTaskReply.Error), + _ => throw new ArgumentOutOfRangeException(), + }; } + + private static string StatusToString(CreateTaskReply.Types.CreationStatus status) + => status.StatusCase switch + { + CreateTaskReply.Types.CreationStatus.StatusOneofCase.None => throw new Exception("Issue with Server !"), + CreateTaskReply.Types.CreationStatus.StatusOneofCase.TaskInfo => status.TaskInfo.TaskId, + CreateTaskReply.Types.CreationStatus.StatusOneofCase.Error => status.Error, + _ => throw new ArgumentOutOfRangeException(nameof(status)), + }; } diff --git a/Tests/Stream/Server/WorkerService.cs b/Tests/Stream/Server/WorkerService.cs index b86be9164..9b804845e 100644 --- a/Tests/Stream/Server/WorkerService.cs +++ b/Tests/Stream/Server/WorkerService.cs @@ -40,6 +40,9 @@ public WorkerService(ILoggerFactory loggerFactory, { } + [System.Diagnostics.CodeAnalysis.SuppressMessage("Style", + "CA2208: Call the ArgumentOutOfRangeException constructor that contains a message and/or paramName parameter", + Justification = "taskHandler.ExpectedResults.Count is not a real argument")] public override async Task Process(ITaskHandler taskHandler) { var output = new Output(); @@ -112,7 +115,7 @@ await taskHandler.CreateTasksAsync(new[] req, }) .ConfigureAwait(false); - logger_.LogDebug("Sub Task created : {subtaskid}", + logger_.LogDebug("Sub Task created : {subtaskId}", taskId); output = new Output { @@ -122,7 +125,7 @@ await taskHandler.CreateTasksAsync(new[] break; case TestPayload.TaskType.DatadepTransfer: { - var taskId = "DatadepTransfer-" + Guid.NewGuid(); + var taskId = "DataDepTransfer-" + Guid.NewGuid(); TaskRequest req; if (taskHandler.ExpectedResults.Count != 2) { @@ -164,7 +167,7 @@ await taskHandler.CreateTasksAsync(new[] req, }) .ConfigureAwait(false); - logger_.LogDebug("Sub Task created : {subtaskid}", + logger_.LogDebug("Sub Task created : {subtaskId}", taskId); output = new Output From 0ab246814596601e08c924496001434d6c2419d3 Mon Sep 17 00:00:00 2001 From: wkirschenmann Date: Thu, 10 Aug 2023 17:32:18 +0200 Subject: [PATCH 10/21] Full Cleanup With Headers --- Adaptors/Amqp/src/PullQueueStorage.cs | 8 +- Adaptors/Amqp/src/QueueMessageHandler.cs | 2 - .../ArmoniK.Core.Adapters.Amqp.Tests.csproj | 42 +-- .../ArmoniK.Core.Adapters.LocalStorage.csproj | 2 +- Adaptors/LocalStorage/src/ObjectStorage.cs | 18 +- Adaptors/Memory/src/PushQueueStorage.cs | 2 +- Adaptors/Memory/src/SessionTable.cs | 13 +- Adaptors/Memory/src/TaskTable.cs | 38 +-- .../ArmoniK.Core.Adapters.Memory.Tests.csproj | 4 +- .../src/Common/MongoCollectionProvider.cs | 22 +- .../MongoDB/src/Common/SessionProvider.cs | 18 +- Adaptors/MongoDB/src/ServiceCollectionExt.cs | 3 +- .../src/Table/DataModel/IndexHelper.cs | 18 +- .../MongoDB/tests/AuthenticationTableTest.cs | 12 +- ...sionsBuildersFieldFilterExpressionTests.cs | 18 +- Adaptors/MongoDB/tests/IndexTest.cs | 2 +- .../MongoDB/tests/MongoDatabaseProvider.cs | 2 +- .../MongoDB/tests/SessionProviderTests.cs | 2 +- Adaptors/MongoDB/tests/SessionTableTests.cs | 4 +- Adaptors/RabbitMQ/src/PullQueueStorage.cs | 1 - Adaptors/RabbitMQ/src/QueueMessageHandler.cs | 2 - Adaptors/Redis/src/ObjectStorage.cs | 18 +- .../ArmoniK.Core.Adapters.Redis.Tests.csproj | 4 +- Adaptors/S3/src/ObjectStorage.cs | 24 +- Base/src/IQueueMessageHandler.cs | 12 +- .../src/Auth/Authentication/Authenticator.cs | 8 +- Common/src/Pollster/AgentHandler.cs | 3 +- Common/src/Pollster/Pollster.cs | 3 +- Common/src/Pollster/TaskHandler.cs | 22 +- Common/src/Utils/LoggerInit.cs | 2 - Common/src/gRPC/ExpressionBuilders.cs | 8 +- Common/src/gRPC/ListApplicationsRequestExt.cs | 9 +- Common/src/gRPC/ListPartitionsRequestExt.cs | 33 +- Common/src/gRPC/ListResultsRequestExt.cs | 13 +- Common/src/gRPC/ListSessionsRequestExt.cs | 17 +- Common/src/gRPC/ListTasksRequestExt.cs | 12 +- Common/src/gRPC/Services/Agent.cs | 9 +- Common/src/gRPC/Services/GrpcAgentService.cs | 4 +- .../gRPC/Services/GrpcApplicationsService.cs | 40 +-- Common/src/gRPC/Services/GrpcAuthService.cs | 5 +- .../src/gRPC/Services/GrpcSessionsService.cs | 20 +- Common/src/gRPC/Services/GrpcTasksService.cs | 86 +++--- Common/src/gRPC/Services/Submitter.cs | 9 +- Common/src/gRPC/Services/WatchToGrpc.cs | 2 - .../Auth/AuthenticationIntegrationTest.cs | 28 +- Common/tests/Helpers/SimpleAgent.cs | 4 +- .../tests/Helpers/SimplePullQueueStorage.cs | 6 +- .../Helpers/SimpleWorkerStreamHandler.cs | 4 +- Common/tests/Helpers/TestDatabaseProvider.cs | 2 +- Common/tests/Helpers/TestPollsterProvider.cs | 2 +- .../tests/Helpers/TestTaskHandlerProvider.cs | 2 +- .../ToApplicationFilterTest.cs | 17 +- Common/tests/Pollster/AgentTest.cs | 15 +- Common/tests/Pollster/DataPrefetcherTest.cs | 84 ++--- Common/tests/Pollster/PollsterTest.cs | 28 +- Common/tests/Pollster/TaskHandlerTest.cs | 6 +- Common/tests/Submitter/SubmitterTests.cs | 14 +- .../TestBase/AuthenticationTableTestBase.cs | 56 ++-- .../tests/TestBase/PartitionTableTestBase.cs | 36 +-- Common/tests/TestBase/SessionTableTestBase.cs | 42 +-- Common/tests/TestBase/TaskTableTestBase.cs | 155 +++++----- .../src/ArmoniK.Core.Control.Metrics.csproj | 4 +- ...rmoniK.Core.Control.Submitter.Tests.csproj | 2 +- .../src/ArmoniK.Core.ProfilingTools.csproj | 2 +- Tests/Bench/Client/src/Program.cs | 1 - .../Bench/Server/src/BenchComputerService.cs | 2 +- Tests/Bench/Server/src/GlobalSuppressions.cs | 24 +- .../src/ArmoniK.Samples.HtcMock.Client.csproj | 64 ++-- Tests/HtcMock/Client/src/SessionClient.cs | 19 +- Tests/Stream/Client/StreamWrapperTests.cs | 35 +-- Tests/Stream/Client/SubmitterExt.cs | 7 +- ...s.Common.StreamWrapper.Tests.Common.csproj | 4 +- Tests/Stream/Server/WorkerService.cs | 7 +- dotnet-coverage.runsettings.xml | 47 +-- terraform/activemq/activemq.xml | 147 ++++----- terraform/activemq/jetty.xml | 291 +++++++++--------- terraform/artemis/broker.xml | 268 ++++++++-------- 77 files changed, 977 insertions(+), 1044 deletions(-) diff --git a/Adaptors/Amqp/src/PullQueueStorage.cs b/Adaptors/Amqp/src/PullQueueStorage.cs index 9ace93128..bc2165b05 100644 --- a/Adaptors/Amqp/src/PullQueueStorage.cs +++ b/Adaptors/Amqp/src/PullQueueStorage.cs @@ -79,10 +79,10 @@ await ConnectionAmqp.Init(cancellationToken) $"{Options.PartitionId}###q{i}"); /* linkCredit_: the maximum number of messages the - * remote peer can send to the receiver. - * With the goal of minimizing/deactivating - * prefetching, a value of 1 gave us the desired - * behavior. We pick a default value of 2 to have "some cache". */ + * remote peer can send to the receiver. + * With the goal of minimizing/deactivating + * prefetching, a value of 1 gave us the desired + * behavior. We pick a default value of 2 to have "some cache". */ rl.SetCredit(Options.LinkCredit); return rl; })) diff --git a/Adaptors/Amqp/src/QueueMessageHandler.cs b/Adaptors/Amqp/src/QueueMessageHandler.cs index 8dc555c29..869e73176 100644 --- a/Adaptors/Amqp/src/QueueMessageHandler.cs +++ b/Adaptors/Amqp/src/QueueMessageHandler.cs @@ -24,8 +24,6 @@ using ArmoniK.Core.Base; -using Microsoft.Extensions.Logging; - namespace ArmoniK.Core.Adapters.Amqp; public class QueueMessageHandler : IQueueMessageHandler diff --git a/Adaptors/Amqp/tests/ArmoniK.Core.Adapters.Amqp.Tests.csproj b/Adaptors/Amqp/tests/ArmoniK.Core.Adapters.Amqp.Tests.csproj index 7b7fab604..087dc53af 100644 --- a/Adaptors/Amqp/tests/ArmoniK.Core.Adapters.Amqp.Tests.csproj +++ b/Adaptors/Amqp/tests/ArmoniK.Core.Adapters.Amqp.Tests.csproj @@ -1,30 +1,30 @@ - - net6.0 - false + + net6.0 + false enable - + - - Embedded - true - DEBUG;TRACE - + + Embedded + true + DEBUG;TRACE + - - - - - + + + + + - - - + + + - - - - + + + + diff --git a/Adaptors/LocalStorage/src/ArmoniK.Core.Adapters.LocalStorage.csproj b/Adaptors/LocalStorage/src/ArmoniK.Core.Adapters.LocalStorage.csproj index 1f0a19a16..47e67bc85 100644 --- a/Adaptors/LocalStorage/src/ArmoniK.Core.Adapters.LocalStorage.csproj +++ b/Adaptors/LocalStorage/src/ArmoniK.Core.Adapters.LocalStorage.csproj @@ -14,7 +14,7 @@ - + diff --git a/Adaptors/LocalStorage/src/ObjectStorage.cs b/Adaptors/LocalStorage/src/ObjectStorage.cs index a870a04bb..d1e7cbfc3 100644 --- a/Adaptors/LocalStorage/src/ObjectStorage.cs +++ b/Adaptors/LocalStorage/src/ObjectStorage.cs @@ -81,17 +81,17 @@ public Task Init(CancellationToken cancellationToken) /// public Task Check(HealthCheckTag tag) => tag switch - { - HealthCheckTag.Startup or HealthCheckTag.Readiness => Task.FromResult(isInitialized_ - ? HealthCheckResult.Healthy() - : HealthCheckResult.Unhealthy("Local storage not initialized yet.")), - HealthCheckTag.Liveness => Task.FromResult(isInitialized_ && Directory.Exists(path_) - ? HealthCheckResult.Healthy() - : HealthCheckResult.Unhealthy("Local storage not initialized or folder has been deleted.")), - _ => throw new ArgumentOutOfRangeException(nameof(tag), + { + HealthCheckTag.Startup or HealthCheckTag.Readiness => Task.FromResult(isInitialized_ + ? HealthCheckResult.Healthy() + : HealthCheckResult.Unhealthy("Local storage not initialized yet.")), + HealthCheckTag.Liveness => Task.FromResult(isInitialized_ && Directory.Exists(path_) + ? HealthCheckResult.Healthy() + : HealthCheckResult.Unhealthy("Local storage not initialized or folder has been deleted.")), + _ => throw new ArgumentOutOfRangeException(nameof(tag), tag, null), - }; + }; /// public async Task AddOrUpdateAsync(string key, diff --git a/Adaptors/Memory/src/PushQueueStorage.cs b/Adaptors/Memory/src/PushQueueStorage.cs index 02fcb95d2..05152fa4f 100644 --- a/Adaptors/Memory/src/PushQueueStorage.cs +++ b/Adaptors/Memory/src/PushQueueStorage.cs @@ -59,7 +59,7 @@ await Task.WhenAll(priorityGroups.Select(group => PushMessagesAsync(group, } private Task PushMessagesAsync(IEnumerable messages, - int priority = 1) + int priority = 1) { var messageHandlers = messages.Select(message => new MessageHandler { diff --git a/Adaptors/Memory/src/SessionTable.cs b/Adaptors/Memory/src/SessionTable.cs index af5661b14..a2de371b5 100644 --- a/Adaptors/Memory/src/SessionTable.cs +++ b/Adaptors/Memory/src/SessionTable.cs @@ -107,8 +107,7 @@ public Task GetDefaultTaskOptionAsync(string sessionId, throw new SessionNotFoundException($"Key '{sessionId}' not found"); } - return Task.FromResult(storage_[sessionId] - .Options); + return Task.FromResult(storage_[sessionId].Options); } /// @@ -161,12 +160,10 @@ public IAsyncEnumerable ListSessionsAsync(SessionFilter sessionFilte return rawList.Where(sessionId => sessionFilter.StatusesCase switch { - SessionFilter.StatusesOneofCase.None => true, - SessionFilter.StatusesOneofCase.Included => sessionFilter.Included.Statuses.Contains(storage_[sessionId] - .Status), - SessionFilter.StatusesOneofCase.Excluded => !sessionFilter.Excluded.Statuses.Contains(storage_[sessionId] - .Status), - _ => throw new ArgumentException("Filter is set to an unknown StatusesCase."), + SessionFilter.StatusesOneofCase.None => true, + SessionFilter.StatusesOneofCase.Included => sessionFilter.Included.Statuses.Contains(storage_[sessionId].Status), + SessionFilter.StatusesOneofCase.Excluded => !sessionFilter.Excluded.Statuses.Contains(storage_[sessionId].Status), + _ => throw new ArgumentException("Filter is set to an unknown StatusesCase."), }); } diff --git a/Adaptors/Memory/src/TaskTable.cs b/Adaptors/Memory/src/TaskTable.cs index 4497fb48d..986143cc0 100644 --- a/Adaptors/Memory/src/TaskTable.cs +++ b/Adaptors/Memory/src/TaskTable.cs @@ -81,9 +81,10 @@ public Task CreateTasks(IEnumerable tasks, public Task ReadTaskAsync(string taskId, CancellationToken cancellationToken = default) { - if (taskId2TaskData_.ContainsKey(taskId)) + if (taskId2TaskData_.TryGetValue(taskId, + out var value)) { - return Task.FromResult(taskId2TaskData_[taskId]); + return Task.FromResult(value); } throw new TaskNotFoundException($"Key '{taskId}' not found"); @@ -93,26 +94,21 @@ public Task ReadTaskAsync(string taskId, public Task IsTaskCancelledAsync(string taskId, CancellationToken cancellationToken = default) { - if (!taskId2TaskData_.ContainsKey(taskId)) + if (!taskId2TaskData_.TryGetValue(taskId, + out var value)) { throw new TaskNotFoundException($"Key '{taskId}' not found"); } - return Task.FromResult(taskId2TaskData_[taskId] - .Status is TaskStatus.Cancelling or TaskStatus.Cancelled); + return Task.FromResult(value.Status is TaskStatus.Cancelling or TaskStatus.Cancelled); } /// public Task StartTask(TaskData taskData, CancellationToken cancellationToken = default) { - if (!taskId2TaskData_.ContainsKey(taskData.TaskId)) - { - throw new TaskNotFoundException($"Key '{taskData.TaskId}' not found"); - } - taskId2TaskData_.AddOrUpdate(taskData.TaskId, - _ => throw new InvalidOperationException("The task does not exist."), + _ => throw new TaskNotFoundException($"Key '{taskData.TaskId}' not found"), (_, data) => data with { @@ -128,8 +124,7 @@ public async Task> CountTasksAsync(TaskFilter CancellationToken cancellationToken = default) => await ListTasksAsync(filter, cancellationToken) - .Select(taskId => taskId2TaskData_[taskId] - .Status) + .Select(taskId => taskId2TaskData_[taskId].Status) .GroupBy(status => status) .SelectAwait(async grouping => new TaskStatusCount(grouping.Key, await grouping.CountAsync(cancellationToken) @@ -229,12 +224,10 @@ public IAsyncEnumerable ListTasksAsync(TaskFilter filter, return rawList.Where(taskId => filter.StatusesCase switch { - TaskFilter.StatusesOneofCase.None => true, - TaskFilter.StatusesOneofCase.Included => filter.Included.Statuses.Contains(taskId2TaskData_[taskId] - .Status), - TaskFilter.StatusesOneofCase.Excluded => !filter.Excluded.Statuses.Contains(taskId2TaskData_[taskId] - .Status), - _ => throw new ArgumentException("Filter is set to an unknown StatusesCase."), + TaskFilter.StatusesOneofCase.None => true, + TaskFilter.StatusesOneofCase.Included => filter.Included.Statuses.Contains(taskId2TaskData_[taskId].Status), + TaskFilter.StatusesOneofCase.Excluded => !filter.Excluded.Statuses.Contains(taskId2TaskData_[taskId].Status), + _ => throw new ArgumentException("Filter is set to an unknown StatusesCase."), }) .ToAsyncEnumerable(); } @@ -363,8 +356,7 @@ public Task GetTaskOutput(string taskId, throw new TaskNotFoundException($"Key '{taskId}' not found"); } - return Task.FromResult(taskId2TaskData_[taskId] - .Output); + return Task.FromResult(taskId2TaskData_[taskId].Output); } /// @@ -437,8 +429,7 @@ public Task> GetParentTaskIds(string taskId, throw new TaskNotFoundException($"Key '{taskId}' not found"); } - return Task.FromResult(taskId2TaskData_[taskId] - .ParentTaskIds as IEnumerable); + return Task.FromResult(taskId2TaskData_[taskId].ParentTaskIds as IEnumerable); } /// @@ -504,5 +495,4 @@ public Task Check(HealthCheckTag tag) => Task.FromResult(isInitialized_ ? HealthCheckResult.Healthy() : HealthCheckResult.Unhealthy()); - } diff --git a/Adaptors/Memory/tests/ArmoniK.Core.Adapters.Memory.Tests.csproj b/Adaptors/Memory/tests/ArmoniK.Core.Adapters.Memory.Tests.csproj index cb83986cc..1b20277cc 100644 --- a/Adaptors/Memory/tests/ArmoniK.Core.Adapters.Memory.Tests.csproj +++ b/Adaptors/Memory/tests/ArmoniK.Core.Adapters.Memory.Tests.csproj @@ -17,11 +17,11 @@ - + - + diff --git a/Adaptors/MongoDB/src/Common/MongoCollectionProvider.cs b/Adaptors/MongoDB/src/Common/MongoCollectionProvider.cs index c2006360a..4519689e2 100644 --- a/Adaptors/MongoDB/src/Common/MongoCollectionProvider.cs +++ b/Adaptors/MongoDB/src/Common/MongoCollectionProvider.cs @@ -36,8 +36,8 @@ namespace ArmoniK.Core.Adapters.MongoDB.Common; public class MongoCollectionProvider : IInitializable, IAsyncInitialization> where TModelMapping : IMongoDataModelMapping, new() { - private bool isInitialized_; - private IMongoCollection? mongoCollection_; + private bool isInitialized_; + private IMongoCollection? mongoCollection_; public MongoCollectionProvider(Options.MongoDB options, SessionProvider sessionProvider, @@ -64,17 +64,17 @@ public MongoCollectionProvider(Options.MongoDB options, /// public Task Check(HealthCheckTag tag) => tag switch - { - HealthCheckTag.Startup or HealthCheckTag.Readiness => Task.FromResult(isInitialized_ - ? HealthCheckResult.Healthy() - : HealthCheckResult.Unhealthy("MongoCollection not initialized yet.")), - HealthCheckTag.Liveness => Task.FromResult(isInitialized_ && mongoCollection_ is null - ? HealthCheckResult.Healthy() - : HealthCheckResult.Unhealthy("MongoCollection not initialized yet.")), - _ => throw new ArgumentOutOfRangeException(nameof(tag), + { + HealthCheckTag.Startup or HealthCheckTag.Readiness => Task.FromResult(isInitialized_ + ? HealthCheckResult.Healthy() + : HealthCheckResult.Unhealthy("MongoCollection not initialized yet.")), + HealthCheckTag.Liveness => Task.FromResult(isInitialized_ && mongoCollection_ is null + ? HealthCheckResult.Healthy() + : HealthCheckResult.Unhealthy("MongoCollection not initialized yet.")), + _ => throw new ArgumentOutOfRangeException(nameof(tag), tag, null), - }; + }; /// public async Task Init(CancellationToken cancellationToken) diff --git a/Adaptors/MongoDB/src/Common/SessionProvider.cs b/Adaptors/MongoDB/src/Common/SessionProvider.cs index 65140238e..fbbc41599 100644 --- a/Adaptors/MongoDB/src/Common/SessionProvider.cs +++ b/Adaptors/MongoDB/src/Common/SessionProvider.cs @@ -43,17 +43,17 @@ public SessionProvider(IMongoClient client) public Task Check(HealthCheckTag tag) => tag switch - { - HealthCheckTag.Readiness or HealthCheckTag.Startup => Task.FromResult(clientSessionHandle_ is not null - ? HealthCheckResult.Healthy() - : HealthCheckResult.Degraded($"{nameof(clientSessionHandle_)} is still null")), - HealthCheckTag.Liveness => Task.FromResult(clientSessionHandle_ is not null && client_.Cluster.Description.State == ClusterState.Connected - ? HealthCheckResult.Healthy() - : HealthCheckResult.Unhealthy("Connection to MongoDB cluster dropped.")), - _ => throw new ArgumentOutOfRangeException(nameof(tag), + { + HealthCheckTag.Readiness or HealthCheckTag.Startup => Task.FromResult(clientSessionHandle_ is not null + ? HealthCheckResult.Healthy() + : HealthCheckResult.Degraded($"{nameof(clientSessionHandle_)} is still null")), + HealthCheckTag.Liveness => Task.FromResult(clientSessionHandle_ is not null && client_.Cluster.Description.State == ClusterState.Connected + ? HealthCheckResult.Healthy() + : HealthCheckResult.Unhealthy("Connection to MongoDB cluster dropped.")), + _ => throw new ArgumentOutOfRangeException(nameof(tag), tag, null), - }; + }; public Task Init(CancellationToken cancellationToken) { diff --git a/Adaptors/MongoDB/src/ServiceCollectionExt.cs b/Adaptors/MongoDB/src/ServiceCollectionExt.cs index 1e1ba127f..5d19dea50 100644 --- a/Adaptors/MongoDB/src/ServiceCollectionExt.cs +++ b/Adaptors/MongoDB/src/ServiceCollectionExt.cs @@ -242,11 +242,10 @@ public static IServiceCollection AddClientSubmitterAuthenticationStorage(this IS /// Services /// Configuration /// Created authentication cache - /// /// Services [PublicAPI] public static IServiceCollection AddClientSubmitterAuthServices(this IServiceCollection services, - ConfigurationManager configuration, + ConfigurationManager configuration, out AuthenticationCache authCache) { authCache = new AuthenticationCache(); diff --git a/Adaptors/MongoDB/src/Table/DataModel/IndexHelper.cs b/Adaptors/MongoDB/src/Table/DataModel/IndexHelper.cs index 80b1aa34e..482095a6d 100644 --- a/Adaptors/MongoDB/src/Table/DataModel/IndexHelper.cs +++ b/Adaptors/MongoDB/src/Table/DataModel/IndexHelper.cs @@ -203,26 +203,20 @@ public static CreateIndexModel CreateIndex(bool if (field.Length == 1) { - if (unique && field[0] - .type == IndexType.Hashed) + if (unique && field[0].type == IndexType.Hashed) { throw new ArgumentOutOfRangeException(nameof(unique), "A hashed index cannot be constrained to be unique"); } - return field[0] - .type switch + return field[0].type switch { - IndexType.Ascending => CreateAscendingIndex(field[0] - .expression, + IndexType.Ascending => CreateAscendingIndex(field[0].expression, unique), - IndexType.Descending => CreateAscendingIndex(field[0] - .expression, + IndexType.Descending => CreateAscendingIndex(field[0].expression, unique), - IndexType.Hashed => CreateHashedIndex(field[0] - .expression), - IndexType.Text => CreateTextIndex(field[0] - .expression, + IndexType.Hashed => CreateHashedIndex(field[0].expression), + IndexType.Text => CreateTextIndex(field[0].expression, unique), _ => throw new ArgumentOutOfRangeException(nameof(field), "Invalid IndexType"), diff --git a/Adaptors/MongoDB/tests/AuthenticationTableTest.cs b/Adaptors/MongoDB/tests/AuthenticationTableTest.cs index bd7328242..da3dea53e 100644 --- a/Adaptors/MongoDB/tests/AuthenticationTableTest.cs +++ b/Adaptors/MongoDB/tests/AuthenticationTableTest.cs @@ -29,12 +29,6 @@ namespace ArmoniK.Core.Adapters.MongoDB.Tests; public class AuthenticationTableTest : AuthenticationTableTestBase { - public override void TearDown() - { - tableProvider_?.Dispose(); - RunTests = false; - } - private MongoDatabaseProvider? tableProvider_; static AuthenticationTableTest() @@ -63,6 +57,12 @@ static AuthenticationTableTest() } } + public override void TearDown() + { + tableProvider_?.Dispose(); + RunTests = false; + } + public override void GetAuthSource() { tableProvider_ = new MongoDatabaseProvider(); diff --git a/Adaptors/MongoDB/tests/ExpressionsBuildersFieldFilterExpressionTests.cs b/Adaptors/MongoDB/tests/ExpressionsBuildersFieldFilterExpressionTests.cs index 186d021f1..7c790156e 100644 --- a/Adaptors/MongoDB/tests/ExpressionsBuildersFieldFilterExpressionTests.cs +++ b/Adaptors/MongoDB/tests/ExpressionsBuildersFieldFilterExpressionTests.cs @@ -33,15 +33,15 @@ namespace ArmoniK.Core.Adapters.MongoDB.Tests; internal class ExpressionsBuildersFieldFilterExpressionTests { private static readonly TaskOptions TaskOptions = new(new Dictionary(), - TimeSpan.Zero, - 0, - 0, - "part1", - "ApplicationName", - "ApplicationVersion", - "applicationNamespace", - "applicationService", - "engineType"); + TimeSpan.Zero, + 0, + 0, + "part1", + "ApplicationName", + "ApplicationVersion", + "applicationNamespace", + "applicationService", + "engineType"); [Test] public void ShouldRecognizeSession() diff --git a/Adaptors/MongoDB/tests/IndexTest.cs b/Adaptors/MongoDB/tests/IndexTest.cs index 53af2ce77..6646fa143 100644 --- a/Adaptors/MongoDB/tests/IndexTest.cs +++ b/Adaptors/MongoDB/tests/IndexTest.cs @@ -50,7 +50,7 @@ public void StartUp() StandardOuputLogger = line => logger.LogInformation(line), StandardErrorLogger = line => logger.LogError(line), #pragma warning restore CA2254 - }; + }; runner_ = MongoRunner.Run(options); client_ = new MongoClient(runner_.ConnectionString); diff --git a/Adaptors/MongoDB/tests/MongoDatabaseProvider.cs b/Adaptors/MongoDB/tests/MongoDatabaseProvider.cs index 6c516b9ad..cdc85b977 100644 --- a/Adaptors/MongoDB/tests/MongoDatabaseProvider.cs +++ b/Adaptors/MongoDB/tests/MongoDatabaseProvider.cs @@ -59,7 +59,7 @@ public MongoDatabaseProvider(bool useSingleNodeReplicaSet StandardOuputLogger = line => logger.LogInformation(line), StandardErrorLogger = line => logger.LogError(line), #pragma warning restore CA2254 - ReplicaSetSetupTimeout = TimeSpan.FromSeconds(30), + ReplicaSetSetupTimeout = TimeSpan.FromSeconds(30), }; runner_ = MongoRunner.Run(options); diff --git a/Adaptors/MongoDB/tests/SessionProviderTests.cs b/Adaptors/MongoDB/tests/SessionProviderTests.cs index 8c2baea8c..7069a188c 100644 --- a/Adaptors/MongoDB/tests/SessionProviderTests.cs +++ b/Adaptors/MongoDB/tests/SessionProviderTests.cs @@ -61,7 +61,7 @@ public void SetUp() StandardOuputLogger = line => logger.LogInformation(line), StandardErrorLogger = line => logger.LogError(line), #pragma warning restore CA2254 - }; + }; runner_ = MongoRunner.Run(options); client_ = new MongoClient(runner_.ConnectionString); diff --git a/Adaptors/MongoDB/tests/SessionTableTests.cs b/Adaptors/MongoDB/tests/SessionTableTests.cs index b94ed9159..921334b36 100644 --- a/Adaptors/MongoDB/tests/SessionTableTests.cs +++ b/Adaptors/MongoDB/tests/SessionTableTests.cs @@ -24,14 +24,14 @@ namespace ArmoniK.Core.Adapters.MongoDB.Tests; public class SessionTableTests : SessionTableTestBase { + private MongoDatabaseProvider? tableProvider_; + public override void TearDown() { tableProvider_?.Dispose(); RunTests = false; } - private MongoDatabaseProvider? tableProvider_; - public override void GetSessionTableInstance() { tableProvider_ = new MongoDatabaseProvider(); diff --git a/Adaptors/RabbitMQ/src/PullQueueStorage.cs b/Adaptors/RabbitMQ/src/PullQueueStorage.cs index 3b4b07d25..183876da5 100644 --- a/Adaptors/RabbitMQ/src/PullQueueStorage.cs +++ b/Adaptors/RabbitMQ/src/PullQueueStorage.cs @@ -19,7 +19,6 @@ using System.Collections.Concurrent; using System.Collections.Generic; using System.Linq; -using System.Runtime.CompilerServices; using System.Text; using System.Threading; using System.Threading.Tasks; diff --git a/Adaptors/RabbitMQ/src/QueueMessageHandler.cs b/Adaptors/RabbitMQ/src/QueueMessageHandler.cs index abae5b31f..111f6eee1 100644 --- a/Adaptors/RabbitMQ/src/QueueMessageHandler.cs +++ b/Adaptors/RabbitMQ/src/QueueMessageHandler.cs @@ -21,8 +21,6 @@ using ArmoniK.Core.Base; -using Microsoft.Extensions.Logging; - using RabbitMQ.Client; using RabbitMQ.Client.Events; diff --git a/Adaptors/Redis/src/ObjectStorage.cs b/Adaptors/Redis/src/ObjectStorage.cs index b966b711b..c9db37674 100644 --- a/Adaptors/Redis/src/ObjectStorage.cs +++ b/Adaptors/Redis/src/ObjectStorage.cs @@ -74,17 +74,17 @@ await redis_.PingAsync() /// public Task Check(HealthCheckTag tag) => tag switch - { - HealthCheckTag.Startup or HealthCheckTag.Readiness => Task.FromResult(isInitialized_ - ? HealthCheckResult.Healthy() - : HealthCheckResult.Unhealthy("Redis not initialized yet.")), - HealthCheckTag.Liveness => Task.FromResult(isInitialized_ && redis_.Multiplexer.IsConnected - ? HealthCheckResult.Healthy() - : HealthCheckResult.Unhealthy("Redis not initialized or connection dropped.")), - _ => throw new ArgumentOutOfRangeException(nameof(tag), + { + HealthCheckTag.Startup or HealthCheckTag.Readiness => Task.FromResult(isInitialized_ + ? HealthCheckResult.Healthy() + : HealthCheckResult.Unhealthy("Redis not initialized yet.")), + HealthCheckTag.Liveness => Task.FromResult(isInitialized_ && redis_.Multiplexer.IsConnected + ? HealthCheckResult.Healthy() + : HealthCheckResult.Unhealthy("Redis not initialized or connection dropped.")), + _ => throw new ArgumentOutOfRangeException(nameof(tag), tag, null), - }; + }; /// public async Task AddOrUpdateAsync(string key, diff --git a/Adaptors/Redis/tests/ArmoniK.Core.Adapters.Redis.Tests.csproj b/Adaptors/Redis/tests/ArmoniK.Core.Adapters.Redis.Tests.csproj index 782c01c19..663af2339 100644 --- a/Adaptors/Redis/tests/ArmoniK.Core.Adapters.Redis.Tests.csproj +++ b/Adaptors/Redis/tests/ArmoniK.Core.Adapters.Redis.Tests.csproj @@ -11,11 +11,11 @@ - + - + diff --git a/Adaptors/S3/src/ObjectStorage.cs b/Adaptors/S3/src/ObjectStorage.cs index ce3d2fd14..d2d68a149 100644 --- a/Adaptors/S3/src/ObjectStorage.cs +++ b/Adaptors/S3/src/ObjectStorage.cs @@ -77,17 +77,17 @@ await AmazonS3Util.DoesS3BucketExistV2Async(s3Client_, /// public Task Check(HealthCheckTag tag) => tag switch - { - HealthCheckTag.Startup or HealthCheckTag.Readiness => Task.FromResult(isInitialized_ - ? HealthCheckResult.Healthy() - : HealthCheckResult.Unhealthy("S3 not initialized yet.")), - HealthCheckTag.Liveness => Task.FromResult(isInitialized_ - ? HealthCheckResult.Healthy() - : HealthCheckResult.Unhealthy("S3 not initialized or connection dropped.")), - _ => throw new ArgumentOutOfRangeException(nameof(tag), + { + HealthCheckTag.Startup or HealthCheckTag.Readiness => Task.FromResult(isInitialized_ + ? HealthCheckResult.Healthy() + : HealthCheckResult.Unhealthy("S3 not initialized yet.")), + HealthCheckTag.Liveness => Task.FromResult(isInitialized_ + ? HealthCheckResult.Healthy() + : HealthCheckResult.Unhealthy("S3 not initialized or connection dropped.")), + _ => throw new ArgumentOutOfRangeException(nameof(tag), tag, null), - }; + }; /// public async Task AddOrUpdateAsync(string key, @@ -252,8 +252,8 @@ internal static Task WriteStringAsync(this AmazonS3Client s3C } internal static async Task StringByteGetAsync(this AmazonS3Client s3Client, - string bucketName, - string key) + string bucketName, + string key) { var request = new GetObjectRequest { @@ -279,7 +279,7 @@ internal static async Task StringByteGetAsync(this AmazonS3Client s3Clie // Get the data from the response stream await using var responseStream = response.ResponseStream; - + var retrievedData = new byte[responseStream.Length]; _ = await responseStream.ReadAsync(new Memory(retrievedData), cancellationToken); diff --git a/Base/src/IQueueMessageHandler.cs b/Base/src/IQueueMessageHandler.cs index 6b2f744c0..387b97f11 100644 --- a/Base/src/IQueueMessageHandler.cs +++ b/Base/src/IQueueMessageHandler.cs @@ -21,33 +21,33 @@ namespace ArmoniK.Core.Base; /// -/// Interface to handle queue messages lifecycle. +/// Interface to handle queue messages lifecycle. /// public interface IQueueMessageHandler : IAsyncDisposable { /// - /// Used to signal that the message ownership has been lost + /// Used to signal that the message ownership has been lost /// [Obsolete("ArmoniK now manages loss of link with the queue")] CancellationToken CancellationToken { get; set; } /// - /// Id of the message + /// Id of the message /// string MessageId { get; } /// - /// Task Id contained in the message + /// Task Id contained in the message /// string TaskId { get; } /// - /// Status of the message. Used when the handler is disposed to notify the queue. + /// Status of the message. Used when the handler is disposed to notify the queue. /// QueueMessageStatus Status { get; set; } /// - /// Date of reception of the message + /// Date of reception of the message /// DateTime ReceptionDateTime { get; init; } } diff --git a/Common/src/Auth/Authentication/Authenticator.cs b/Common/src/Auth/Authentication/Authenticator.cs index f8c3d62bd..3e4d092bb 100644 --- a/Common/src/Auth/Authentication/Authenticator.cs +++ b/Common/src/Auth/Authentication/Authenticator.cs @@ -253,8 +253,7 @@ protected override async Task HandleAuthenticateAsync() (prevIdentity.Identity as UserIdentity)!.UserName, (identity.Identity as UserIdentity)!.UserId, (identity.Identity as UserIdentity)!.UserName, - keyHash - ); + keyHash); } catch (AuthenticationException e) { @@ -363,9 +362,8 @@ public async Task GetImpersonatedIdentityAsync(ClaimsPrincipal /// Value of the header if found and not empty, null otherwise private string? TryGetHeader(string headerName) { - if (!string.IsNullOrEmpty(headerName) && Request.Headers.TryGetValue(headerName, - out var values) && - !string.IsNullOrWhiteSpace(values.First())) + if (!string.IsNullOrEmpty(headerName) && Request.Headers.TryGetValue(headerName, + out var values) && !string.IsNullOrWhiteSpace(values.First())) { return values.First(); } diff --git a/Common/src/Pollster/AgentHandler.cs b/Common/src/Pollster/AgentHandler.cs index 1fc3dc9e1..0eb9a11e7 100644 --- a/Common/src/Pollster/AgentHandler.cs +++ b/Common/src/Pollster/AgentHandler.cs @@ -86,7 +86,8 @@ public AgentHandler(LoggerInit loggerInit, { if (computePlaneOptions.AgentChannel?.Address == null) { - throw new ArgumentNullException(nameof(computePlaneOptions), $"{nameof(computePlaneOptions.AgentChannel)} is null"); + throw new ArgumentNullException(nameof(computePlaneOptions), + $"{nameof(computePlaneOptions.AgentChannel)} is null"); } logger.LogDebug("Agent address is {address}", diff --git a/Common/src/Pollster/Pollster.cs b/Common/src/Pollster/Pollster.cs index b29d4c257..493987c6c 100644 --- a/Common/src/Pollster/Pollster.cs +++ b/Common/src/Pollster/Pollster.cs @@ -249,8 +249,7 @@ void RecordError(Exception e) var messages = pullQueueStorage_.PullMessagesAsync(messageBatchSize_, cancellationToken); - await foreach (var message in messages - .ConfigureAwait(false)) + await foreach (var message in messages.ConfigureAwait(false)) { using var scopedLogger = logger_.BeginNamedScope("Prefetch messageHandler", ("messageHandler", message.MessageId), diff --git a/Common/src/Pollster/TaskHandler.cs b/Common/src/Pollster/TaskHandler.cs index 3215900e8..b90fc1aee 100644 --- a/Common/src/Pollster/TaskHandler.cs +++ b/Common/src/Pollster/TaskHandler.cs @@ -181,13 +181,13 @@ public async Task AcquireTask() } /* - * Check preconditions: - * - Session is not cancelled - * - Task is not cancelled - * - Task status is OK - * - Dependencies have been checked - * - Max number of retries has not been reached - */ + * Check preconditions: + * - Session is not cancelled + * - Task is not cancelled + * - Task status is OK + * - Dependencies have been checked + * - Max number of retries has not been reached + */ logger_.LogDebug("Handling the task status ({status})", taskData_.Status); @@ -632,12 +632,12 @@ private async Task HandleErrorInternalAsync(Exception e, if (cancellationToken.IsCancellationRequested) { logger_.LogWarning(e, - "Cancellation triggered, task cancelled here and re executed elsewhere"); + "Cancellation triggered, task cancelled here and re executed elsewhere"); } else { logger_.LogWarning(e, - "Worker not available, task cancelled here and re executed elsewhere"); + "Worker not available, task cancelled here and re executed elsewhere"); } await taskTable_.ReleaseTask(taskData, @@ -650,13 +650,13 @@ await taskTable_.ReleaseTask(taskData, if (resubmit) { logger_.LogError(e, - "Error during task execution, retrying task"); + "Error during task execution, retrying task"); messageHandler_.Status = QueueMessageStatus.Cancelled; } else { logger_.LogError(e, - "Error during task execution, cancelling task"); + "Error during task execution, cancelling task"); messageHandler_.Status = QueueMessageStatus.Processed; } diff --git a/Common/src/Utils/LoggerInit.cs b/Common/src/Utils/LoggerInit.cs index c2bda5ce5..348d4ca7d 100644 --- a/Common/src/Utils/LoggerInit.cs +++ b/Common/src/Utils/LoggerInit.cs @@ -15,8 +15,6 @@ // You should have received a copy of the GNU Affero General Public License // along with this program. If not, see . -using System; - using Microsoft.Extensions.Configuration; using Microsoft.Extensions.Logging; diff --git a/Common/src/gRPC/ExpressionBuilders.cs b/Common/src/gRPC/ExpressionBuilders.cs index 428b43cff..77ff09ad7 100644 --- a/Common/src/gRPC/ExpressionBuilders.cs +++ b/Common/src/gRPC/ExpressionBuilders.cs @@ -147,10 +147,10 @@ public static Expression> MakeCallString(Expression m.Name == method && m.GetParameters() - .Length == 1 && m.GetParameters() - .First() - .ParameterType == typeof(string)); + .First(m => m.Name == method && m.GetParameters() + .Length == 1 && m.GetParameters() + .First() + .ParameterType == typeof(string)); var call = Expression.Call(member, methodInfo, diff --git a/Common/src/gRPC/ListApplicationsRequestExt.cs b/Common/src/gRPC/ListApplicationsRequestExt.cs index 5b8e7ab7f..618c2df94 100644 --- a/Common/src/gRPC/ListApplicationsRequestExt.cs +++ b/Common/src/gRPC/ListApplicationsRequestExt.cs @@ -16,6 +16,7 @@ // along with this program. If not, see . using System; +using System.Diagnostics.CodeAnalysis; using System.Linq; using System.Linq.Expressions; @@ -34,7 +35,9 @@ public static class ListApplicationsRequestExt /// The that access the field from the object /// /// the given message is not recognized - [System.Diagnostics.CodeAnalysis.SuppressMessage("Style", "IDE0066:Convert switch statement to expression", Justification = "Readibility with nested switch")] + [SuppressMessage("Style", + "IDE0066:Convert switch statement to expression", + Justification = "Readibility with nested switch")] public static Expression> ToField(this ApplicationField field) { switch (field.FieldCase) @@ -64,7 +67,9 @@ public static class ListApplicationsRequestExt /// The that represents the filter conditions /// /// the given message is not recognized - [System.Diagnostics.CodeAnalysis.SuppressMessage("Style", "IDE0066:Convert switch statement to expression", Justification = "Readibility with nested switch")] + [SuppressMessage("Style", + "IDE0066:Convert switch statement to expression", + Justification = "Readibility with nested switch")] public static Expression> ToApplicationFilter(this Filters filters) { Expression> expr = data => false; diff --git a/Common/src/gRPC/ListPartitionsRequestExt.cs b/Common/src/gRPC/ListPartitionsRequestExt.cs index 5fa1b0473..383039c61 100644 --- a/Common/src/gRPC/ListPartitionsRequestExt.cs +++ b/Common/src/gRPC/ListPartitionsRequestExt.cs @@ -37,10 +37,10 @@ public static class ListPartitionsRequestExt /// the given message is not recognized public static Expression> ToField(this ListPartitionsRequest.Types.Sort sort) => sort.Field.FieldCase switch - { - PartitionField.FieldOneofCase.PartitionRawField => sort.Field.PartitionRawField.Field.ToField(), - _ => throw new ArgumentOutOfRangeException(nameof(sort)), - }; + { + PartitionField.FieldOneofCase.PartitionRawField => sort.Field.PartitionRawField.Field.ToField(), + _ => throw new ArgumentOutOfRangeException(nameof(sort)), + }; public static Expression> ToField(this PartitionField taskField) => taskField.FieldCase switch @@ -73,17 +73,20 @@ public static Expression> ToPartitionFilter(this Filte foreach (var filterField in filtersAnd.And) { exprAnd = filterField.ValueConditionCase switch - { - FilterField.ValueConditionOneofCase.FilterString => exprAnd.ExpressionAnd(filterField.FilterString.Operator.ToFilter(filterField.Field.ToField(), - filterField.FilterString.Value)), - FilterField.ValueConditionOneofCase.FilterNumber => exprAnd.ExpressionAnd(filterField.FilterNumber.Operator.ToFilter(filterField.Field.ToField(), - filterField.FilterNumber.Value)), - FilterField.ValueConditionOneofCase.FilterBoolean => exprAnd.ExpressionAnd(filterField.FilterBoolean.Operator.ToFilter(filterField.Field.ToField(), - filterField.FilterBoolean.Value)), - FilterField.ValueConditionOneofCase.FilterArray => exprAnd.ExpressionAnd(filterField.FilterArray.Operator.ToFilter(filterField.Field.ToField(), - filterField.FilterArray.Value)), - _ => throw new ArgumentOutOfRangeException(nameof(filters)), - }; + { + FilterField.ValueConditionOneofCase.FilterString => exprAnd.ExpressionAnd(filterField.FilterString.Operator.ToFilter(filterField.Field.ToField(), + filterField.FilterString + .Value)), + FilterField.ValueConditionOneofCase.FilterNumber => exprAnd.ExpressionAnd(filterField.FilterNumber.Operator.ToFilter(filterField.Field.ToField(), + filterField.FilterNumber + .Value)), + FilterField.ValueConditionOneofCase.FilterBoolean => exprAnd.ExpressionAnd(filterField.FilterBoolean.Operator.ToFilter(filterField.Field.ToField(), + filterField.FilterBoolean + .Value)), + FilterField.ValueConditionOneofCase.FilterArray => exprAnd.ExpressionAnd(filterField.FilterArray.Operator.ToFilter(filterField.Field.ToField(), + filterField.FilterArray.Value)), + _ => throw new ArgumentOutOfRangeException(nameof(filters)), + }; } expr = expr.ExpressionOr(exprAnd); diff --git a/Common/src/gRPC/ListResultsRequestExt.cs b/Common/src/gRPC/ListResultsRequestExt.cs index 1edce455b..e1e074f5c 100644 --- a/Common/src/gRPC/ListResultsRequestExt.cs +++ b/Common/src/gRPC/ListResultsRequestExt.cs @@ -16,6 +16,7 @@ // along with this program. If not, see . using System; +using System.Diagnostics.CodeAnalysis; using System.Linq; using System.Linq.Expressions; @@ -36,10 +37,10 @@ public static class ListResultsRequestExt /// the given message is not recognized public static Expression> ToField(this ListResultsRequest.Types.Sort sort) => sort.Field.FieldCase switch - { - ResultField.FieldOneofCase.ResultRawField => sort.Field.ResultRawField.Field.ToField(), - _ => throw new ArgumentOutOfRangeException(nameof(sort)), - }; + { + ResultField.FieldOneofCase.ResultRawField => sort.Field.ResultRawField.Field.ToField(), + _ => throw new ArgumentOutOfRangeException(nameof(sort)), + }; public static Expression> ToField(this ResultField taskField) => taskField.FieldCase switch @@ -57,7 +58,9 @@ public static class ListResultsRequestExt /// The that represents the filter conditions /// /// the given message is not recognized - [System.Diagnostics.CodeAnalysis.SuppressMessage("Style", "IDE0066:Convert switch statement to expression", Justification = "Readibility for nested switch")] + [SuppressMessage("Style", + "IDE0066:Convert switch statement to expression", + Justification = "Readibility for nested switch")] public static Expression> ToResultFilter(this Filters filters) { Expression> expr = data => false; diff --git a/Common/src/gRPC/ListSessionsRequestExt.cs b/Common/src/gRPC/ListSessionsRequestExt.cs index 91f3dfd1a..3c23a8a15 100644 --- a/Common/src/gRPC/ListSessionsRequestExt.cs +++ b/Common/src/gRPC/ListSessionsRequestExt.cs @@ -16,6 +16,7 @@ // along with this program. If not, see . using System; +using System.Diagnostics.CodeAnalysis; using System.Linq; using System.Linq.Expressions; @@ -36,12 +37,12 @@ public static class ListSessionsRequestExt /// the given message is not recognized public static Expression> ToField(this ListSessionsRequest.Types.Sort sort) => sort.Field.FieldCase switch - { - SessionField.FieldOneofCase.SessionRawField => sort.Field.SessionRawField.Field.ToField(), - SessionField.FieldOneofCase.TaskOptionField => sort.Field.TaskOptionField.Field.ToField(), - SessionField.FieldOneofCase.TaskOptionGenericField => sort.Field.TaskOptionGenericField.ToField(), - _ => throw new ArgumentOutOfRangeException(nameof(sort)), - }; + { + SessionField.FieldOneofCase.SessionRawField => sort.Field.SessionRawField.Field.ToField(), + SessionField.FieldOneofCase.TaskOptionField => sort.Field.TaskOptionField.Field.ToField(), + SessionField.FieldOneofCase.TaskOptionGenericField => sort.Field.TaskOptionGenericField.ToField(), + _ => throw new ArgumentOutOfRangeException(nameof(sort)), + }; public static Expression> ToField(this SessionField taskField) => taskField.FieldCase switch @@ -61,7 +62,9 @@ public static class ListSessionsRequestExt /// The that represents the filter conditions /// /// the given message is not recognized - [System.Diagnostics.CodeAnalysis.SuppressMessage("Style", "IDE0066:Convert switch statement to expression", Justification = "Readibility for nested switch")] + [SuppressMessage("Style", + "IDE0066:Convert switch statement to expression", + Justification = "Readibility for nested switch")] public static Expression> ToSessionDataFilter(this Filters filters) { Expression> expr = data => false; diff --git a/Common/src/gRPC/ListTasksRequestExt.cs b/Common/src/gRPC/ListTasksRequestExt.cs index 13c337d03..5975d57aa 100644 --- a/Common/src/gRPC/ListTasksRequestExt.cs +++ b/Common/src/gRPC/ListTasksRequestExt.cs @@ -38,12 +38,12 @@ public static class ListTasksRequestExt /// the given message is not recognized public static Expression> ToField(this ListTasksRequest.Types.Sort sort) => sort.Field.FieldCase switch - { - TaskField.FieldOneofCase.TaskSummaryField => sort.Field.TaskSummaryField.Field.ToField(), - TaskField.FieldOneofCase.TaskOptionField => sort.Field.TaskOptionField.Field.ToField(), - TaskField.FieldOneofCase.TaskOptionGenericField => sort.Field.TaskOptionGenericField.ToField(), - _ => throw new ArgumentOutOfRangeException(nameof(sort)), - }; + { + TaskField.FieldOneofCase.TaskSummaryField => sort.Field.TaskSummaryField.Field.ToField(), + TaskField.FieldOneofCase.TaskOptionField => sort.Field.TaskOptionField.Field.ToField(), + TaskField.FieldOneofCase.TaskOptionGenericField => sort.Field.TaskOptionGenericField.ToField(), + _ => throw new ArgumentOutOfRangeException(nameof(sort)), + }; public static Expression> ToField(this TaskField taskField) => taskField.FieldCase switch diff --git a/Common/src/gRPC/Services/Agent.cs b/Common/src/gRPC/Services/Agent.cs index 9e4f8334e..1db7530fa 100644 --- a/Common/src/gRPC/Services/Agent.cs +++ b/Common/src/gRPC/Services/Agent.cs @@ -17,6 +17,7 @@ using System; using System.Collections.Generic; +using System.Diagnostics.CodeAnalysis; using System.Linq; using System.Threading; using System.Threading.Channels; @@ -187,7 +188,9 @@ await taskTable_.FinalizeTaskCreation(ids, } /// - [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2208:Instantiate argument exceptions correctly", Justification = "No correct value for ArgumentOutOfRange Exception in nested code")] + [SuppressMessage("Usage", + "CA2208:Instantiate argument exceptions correctly", + Justification = "No correct value for ArgumentOutOfRange Exception in nested code")] public async Task CreateTask(IAsyncStreamReader requestStream, CancellationToken cancellationToken) { @@ -509,7 +512,9 @@ await responseStream.WriteAsync(new DataReply } /// - [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2208:Instantiate argument exceptions correctly", Justification = "")] + [SuppressMessage("Usage", + "CA2208:Instantiate argument exceptions correctly", + Justification = "")] public async Task SendResult(IAsyncStreamReader requestStream, CancellationToken cancellationToken) { diff --git a/Common/src/gRPC/Services/GrpcAgentService.cs b/Common/src/gRPC/Services/GrpcAgentService.cs index 322387fff..9182a864d 100644 --- a/Common/src/gRPC/Services/GrpcAgentService.cs +++ b/Common/src/gRPC/Services/GrpcAgentService.cs @@ -22,14 +22,12 @@ using Grpc.Core; -using Microsoft.Extensions.Logging; - namespace ArmoniK.Core.Common.gRPC.Services; [IgnoreAuthentication] public class GrpcAgentService : Api.gRPC.V1.Agent.Agent.AgentBase { - private IAgent? agent_; + private IAgent? agent_; public Task Start(IAgent agent) { diff --git a/Common/src/gRPC/Services/GrpcApplicationsService.cs b/Common/src/gRPC/Services/GrpcApplicationsService.cs index 0ade41d98..dfa7ec5a1 100644 --- a/Common/src/gRPC/Services/GrpcApplicationsService.cs +++ b/Common/src/gRPC/Services/GrpcApplicationsService.cs @@ -55,20 +55,20 @@ public override async Task ListApplications(ListApplic ServerCallContext context) { var (applications, totalCount) = await taskTable_.ListApplicationsAsync(request.Filters is null - ? data => true - : request.Filters.ToApplicationFilter(), - request.Sort is null - ? new List>> - { - application => application.Name, - } - : request.Sort.Fields.Select(field => field.ToField()) - .ToList(), - request.Sort is null || request.Sort.Direction == SortDirection.Asc, - request.Page, - request.PageSize, - context.CancellationToken) - .ConfigureAwait(false); + ? data => true + : request.Filters.ToApplicationFilter(), + request.Sort is null + ? new List>> + { + application => application.Name, + } + : request.Sort.Fields.Select(field => field.ToField()) + .ToList(), + request.Sort is null || request.Sort.Direction == SortDirection.Asc, + request.Page, + request.PageSize, + context.CancellationToken) + .ConfigureAwait(false); return new ListApplicationsResponse { Page = request.Page, @@ -76,12 +76,12 @@ request.Sort is null Applications = { applications.Select(data => new ApplicationRaw - { - Name = data.Name, - Namespace = data.Namespace, - Version = data.Version, - Service = data.Service, - }), + { + Name = data.Name, + Namespace = data.Namespace, + Version = data.Version, + Service = data.Service, + }), }, Total = totalCount, }; diff --git a/Common/src/gRPC/Services/GrpcAuthService.cs b/Common/src/gRPC/Services/GrpcAuthService.cs index 5a4ead027..e10513a5d 100644 --- a/Common/src/gRPC/Services/GrpcAuthService.cs +++ b/Common/src/gRPC/Services/GrpcAuthService.cs @@ -28,7 +28,6 @@ using Grpc.Core; using Microsoft.AspNetCore.Authorization; -using Microsoft.Extensions.Logging; using Microsoft.Extensions.Options; namespace ArmoniK.Core.Common.gRPC.Services; @@ -36,8 +35,8 @@ namespace ArmoniK.Core.Common.gRPC.Services; [Authorize(AuthenticationSchemes = Authenticator.SchemeName)] public class GrpcAuthService : Authentication.AuthenticationBase { - private readonly bool requireAuthentication_; - private readonly bool requireAuthorization_; + private readonly bool requireAuthentication_; + private readonly bool requireAuthorization_; public GrpcAuthService(IOptionsMonitor options) { diff --git a/Common/src/gRPC/Services/GrpcSessionsService.cs b/Common/src/gRPC/Services/GrpcSessionsService.cs index bf37ff121..8faf20fdf 100644 --- a/Common/src/gRPC/Services/GrpcSessionsService.cs +++ b/Common/src/gRPC/Services/GrpcSessionsService.cs @@ -130,16 +130,16 @@ public override async Task ListSessions(ListSessionsReques try { var (sessions, totalCount) = await sessionTable_.ListSessionsAsync(request.Filters is null - ? data => true - : request.Filters.ToSessionDataFilter(), - request.Sort is null - ? data => data.SessionId - : request.Sort.ToField(), - request.Sort is null || request.Sort.Direction == SortDirection.Asc, - request.Page, - request.PageSize, - context.CancellationToken) - .ConfigureAwait(false); + ? data => true + : request.Filters.ToSessionDataFilter(), + request.Sort is null + ? data => data.SessionId + : request.Sort.ToField(), + request.Sort is null || request.Sort.Direction == SortDirection.Asc, + request.Page, + request.PageSize, + context.CancellationToken) + .ConfigureAwait(false); return new ListSessionsResponse { diff --git a/Common/src/gRPC/Services/GrpcTasksService.cs b/Common/src/gRPC/Services/GrpcTasksService.cs index f5860aeaa..d67bfd063 100644 --- a/Common/src/gRPC/Services/GrpcTasksService.cs +++ b/Common/src/gRPC/Services/GrpcTasksService.cs @@ -114,38 +114,38 @@ public override async Task ListTasks(ListTasksRequest reques } var (tasks, totalCount) = await taskTable_.ListTasksAsync(request.Filters is null - ? data => true - : request.Filters.ToTaskDataFilter(), - request.Sort is null - ? data => data.TaskId - : request.Sort.ToField(), - data => new TaskDataSummary(data.SessionId, - data.TaskId, - data.OwnerPodId, - data.OwnerPodName, - data.ParentTaskIds.Count, - data.DataDependencies.Count, - data.ExpectedOutputIds.Count, - data.InitialTaskId, - data.RetryOfIds.Count, - data.Status, - data.StatusMessage, - data.Options, - data.CreationDate, - data.SubmittedDate, - data.StartDate, - data.EndDate, - data.ReceptionDate, - data.AcquisitionDate, - data.PodTtl, - data.ProcessingToEndDuration, - data.CreationToEndDuration, - data.Output), - request.Sort is null || request.Sort.Direction == SortDirection.Asc, - request.Page, - request.PageSize, - context.CancellationToken) - .ConfigureAwait(false); + ? data => true + : request.Filters.ToTaskDataFilter(), + request.Sort is null + ? data => data.TaskId + : request.Sort.ToField(), + data => new TaskDataSummary(data.SessionId, + data.TaskId, + data.OwnerPodId, + data.OwnerPodName, + data.ParentTaskIds.Count, + data.DataDependencies.Count, + data.ExpectedOutputIds.Count, + data.InitialTaskId, + data.RetryOfIds.Count, + data.Status, + data.StatusMessage, + data.Options, + data.CreationDate, + data.SubmittedDate, + data.StartDate, + data.EndDate, + data.ReceptionDate, + data.AcquisitionDate, + data.PodTtl, + data.ProcessingToEndDuration, + data.CreationToEndDuration, + data.Output), + request.Sort is null || request.Sort.Direction == SortDirection.Asc, + request.Page, + request.PageSize, + context.CancellationToken) + .ConfigureAwait(false); return new ListTasksResponse { @@ -327,17 +327,17 @@ public override async Task ListTasksRaw(ListTasksRequest } var (tasks, totalCount) = await taskTable_.ListTasksAsync(request.Filters is null - ? data => true - : request.Filters.ToTaskDataFilter(), - request.Sort is null - ? data => data.TaskId - : request.Sort.ToField(), - data => data, - request.Sort is null || request.Sort.Direction == SortDirection.Asc, - request.Page, - request.PageSize, - context.CancellationToken) - .ConfigureAwait(false); + ? data => true + : request.Filters.ToTaskDataFilter(), + request.Sort is null + ? data => data.TaskId + : request.Sort.ToField(), + data => data, + request.Sort is null || request.Sort.Direction == SortDirection.Asc, + request.Page, + request.PageSize, + context.CancellationToken) + .ConfigureAwait(false); return new ListTasksRawResponse { diff --git a/Common/src/gRPC/Services/Submitter.cs b/Common/src/gRPC/Services/Submitter.cs index dbd7686a3..19df2449e 100644 --- a/Common/src/gRPC/Services/Submitter.cs +++ b/Common/src/gRPC/Services/Submitter.cs @@ -18,6 +18,7 @@ using System; using System.Collections.Generic; using System.Diagnostics; +using System.Diagnostics.CodeAnalysis; using System.Linq; using System.Threading; using System.Threading.Tasks; @@ -176,7 +177,9 @@ public async Task CreateSession(IList partitionI } /// - [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2208:Instantiate argument exceptions correctly", Justification = $"{nameof(ArgumentOutOfRangeException)} is used in nested code")] + [SuppressMessage("Usage", + "CA2208:Instantiate argument exceptions correctly", + Justification = $"{nameof(ArgumentOutOfRangeException)} is used in nested code")] public async Task TryGetResult(ResultRequest request, IServerStreamWriter responseStream, CancellationToken cancellationToken) @@ -451,7 +454,9 @@ await ResultLifeCycleHelper.AbortTaskAndResults(taskTable_, } /// - [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2208:Instantiate argument exceptions correctly", Justification = $"{nameof(ArgumentOutOfRangeException)} is used in nested code")] + [SuppressMessage("Usage", + "CA2208:Instantiate argument exceptions correctly", + Justification = $"{nameof(ArgumentOutOfRangeException)} is used in nested code")] public async Task WaitForAvailabilityAsync(ResultRequest request, CancellationToken contextCancellationToken) { diff --git a/Common/src/gRPC/Services/WatchToGrpc.cs b/Common/src/gRPC/Services/WatchToGrpc.cs index b09e43487..d9521457c 100644 --- a/Common/src/gRPC/Services/WatchToGrpc.cs +++ b/Common/src/gRPC/Services/WatchToGrpc.cs @@ -24,8 +24,6 @@ using ArmoniK.Core.Common.Storage; using ArmoniK.Core.Common.Storage.Events; -using Microsoft.Extensions.Logging; - namespace ArmoniK.Core.Common.gRPC.Services; /// diff --git a/Common/tests/Auth/AuthenticationIntegrationTest.cs b/Common/tests/Auth/AuthenticationIntegrationTest.cs index c595c6abb..4a0ff829b 100644 --- a/Common/tests/Auth/AuthenticationIntegrationTest.cs +++ b/Common/tests/Auth/AuthenticationIntegrationTest.cs @@ -421,16 +421,14 @@ public static Metadata GetHeaders(IdentityIndex index, headers.Add(AuthenticatorOptions.DefaultAuth.ImpersonationIdHeader, (int)impersonate < 0 ? "DoesntExist" - : Identities[(int)impersonate] - .UserId); + : Identities[(int)impersonate].UserId); } else if (impersonationType == ImpersonationType.ImpersonateUsername) { headers.Add(AuthenticatorOptions.DefaultAuth.ImpersonationUsernameHeader, (int)impersonate < 0 ? "DoesntExist" - : Identities[(int)impersonate] - .UserName); + : Identities[(int)impersonate].UserName); } return headers; @@ -656,7 +654,8 @@ public static Metadata GetHeaders(IdentityIndex index, new() { Id = - new UploadResultDataRequest.Types.ResultIdentifier + new UploadResultDataRequest.Types. + ResultIdentifier { ResultId = ResultKey, SessionId = SessionId, @@ -672,7 +671,8 @@ public static Metadata GetHeaders(IdentityIndex index, typeof(TaskFilter), new TaskFilter { Session = - new TaskFilter.Types.IdsRequest + new TaskFilter.Types. + IdsRequest { Ids = { @@ -842,15 +842,13 @@ public static IEnumerable GetTestReflectionCases(bool isAsync, ? "Async" : ""), // - The parameter of the method - GetParameters(m.GetParameters()[0] - .ParameterType, + GetParameters(m.GetParameters()[0].ParameterType, clientStream), // - The Request type clientStream ? m.GetParameters()[0] .ParameterType.GetGenericArguments()[0] - : m.GetParameters()[0] - .ParameterType, + : m.GetParameters()[0].ParameterType, // - The Response type serverStream ? m.GetParameters()[1] @@ -895,7 +893,8 @@ public static IEnumerable GetTestReflectionCases(bool isAsync, public static readonly IReadOnlyDictionary ClientServerTypeMapping = new ReadOnlyDictionary(new Dictionary { { - typeof(Api.gRPC.V1.Submitter.Submitter.SubmitterClient), + typeof(Api.gRPC.V1.Submitter.Submitter. + SubmitterClient), typeof(GrpcSubmitterService) }, { @@ -1249,7 +1248,7 @@ public void AuthenticationShouldMatch(CaseParameters parameter } GrpcSubmitterServiceHelper.DeleteChannel(channel) - .Wait(); + .Wait(); return; async Task TestFunction() @@ -1354,8 +1353,7 @@ public async Task AuthServiceShouldGiveUserInfo(CaseParameters parameters, var castedResponse = (GetCurrentUserResponse)response!; // Check if the returned username is correct Assert.AreEqual(options_!.RequireAuthentication - ? Identities[finalUserIndex] - .UserName + ? Identities[finalUserIndex].UserName : "Anonymous", castedResponse.User.Username); // Check if the role list is empty when there is no authorization, otherwise returns the roles @@ -1392,6 +1390,6 @@ public async Task AuthServiceShouldGiveUserInfo(CaseParameters parameters, } await GrpcSubmitterServiceHelper.DeleteChannel(channel) - .ConfigureAwait(false); + .ConfigureAwait(false); } } diff --git a/Common/tests/Helpers/SimpleAgent.cs b/Common/tests/Helpers/SimpleAgent.cs index 9f9eed8e8..dc3b41da8 100644 --- a/Common/tests/Helpers/SimpleAgent.cs +++ b/Common/tests/Helpers/SimpleAgent.cs @@ -71,7 +71,5 @@ public Task CreateResults(CreateResultsRequest request, => Task.FromResult(new CreateResultsResponse()); public void Dispose() - { - GC.SuppressFinalize(this); - } + => GC.SuppressFinalize(this); } diff --git a/Common/tests/Helpers/SimplePullQueueStorage.cs b/Common/tests/Helpers/SimplePullQueueStorage.cs index 0a243c454..4fdf0ff9c 100644 --- a/Common/tests/Helpers/SimplePullQueueStorage.cs +++ b/Common/tests/Helpers/SimplePullQueueStorage.cs @@ -19,7 +19,6 @@ using System.Collections.Concurrent; using System.Collections.Generic; using System.Linq; -using System.Runtime.CompilerServices; using System.Threading; using System.Threading.Tasks; @@ -40,12 +39,13 @@ public Task Check(HealthCheckTag tag) public Task Init(CancellationToken cancellationToken) => Task.CompletedTask; - public int MaxPriority => 10; + public int MaxPriority + => 10; public IAsyncEnumerable PullMessagesAsync(int nbMessages, CancellationToken cancellationToken = default) - // using ToAsyncEnumerable avoids using an async function needlessly + // using ToAsyncEnumerable avoids using an async function needlessly => Enumerable.Repeat(0, nbMessages) .Select(_ => diff --git a/Common/tests/Helpers/SimpleWorkerStreamHandler.cs b/Common/tests/Helpers/SimpleWorkerStreamHandler.cs index 8f60ab0ea..c57742a32 100644 --- a/Common/tests/Helpers/SimpleWorkerStreamHandler.cs +++ b/Common/tests/Helpers/SimpleWorkerStreamHandler.cs @@ -41,9 +41,7 @@ public Task Init(CancellationToken cancellationToken) => Task.CompletedTask; public void Dispose() - { - GC.SuppressFinalize(this); - } + => GC.SuppressFinalize(this); public void StartTaskProcessing(TaskData taskData, CancellationToken cancellationToken) diff --git a/Common/tests/Helpers/TestDatabaseProvider.cs b/Common/tests/Helpers/TestDatabaseProvider.cs index 16e221b68..45deb8bcd 100644 --- a/Common/tests/Helpers/TestDatabaseProvider.cs +++ b/Common/tests/Helpers/TestDatabaseProvider.cs @@ -64,7 +64,7 @@ public TestDatabaseProvider(Action? collectionConfigurato StandardOuputLogger = line => logger.LogInformation(line), StandardErrorLogger = line => logger.LogError(line), #pragma warning restore CA2254 - }; + }; var loggerProvider = new ConsoleForwardingLoggerProvider(); var loggerDb = loggerProvider.CreateLogger("db commands"); diff --git a/Common/tests/Helpers/TestPollsterProvider.cs b/Common/tests/Helpers/TestPollsterProvider.cs index a94fec441..4e478c994 100644 --- a/Common/tests/Helpers/TestPollsterProvider.cs +++ b/Common/tests/Helpers/TestPollsterProvider.cs @@ -72,7 +72,7 @@ public TestPollsterProvider(IWorkerStreamHandler workerStreamHandler, StandardOuputLogger = line => logger.LogInformation(line), StandardErrorLogger = line => logger.LogError(line), #pragma warning restore CA2254 - }; + }; runner_ = MongoRunner.Run(options); client_ = new MongoClient(runner_.ConnectionString); diff --git a/Common/tests/Helpers/TestTaskHandlerProvider.cs b/Common/tests/Helpers/TestTaskHandlerProvider.cs index 5e82e65a3..d0521bee9 100644 --- a/Common/tests/Helpers/TestTaskHandlerProvider.cs +++ b/Common/tests/Helpers/TestTaskHandlerProvider.cs @@ -77,7 +77,7 @@ public TestTaskHandlerProvider(IWorkerStreamHandler workerStreamHandler, StandardOuputLogger = line => logger.LogInformation(line), StandardErrorLogger = line => logger.LogError(line), #pragma warning restore CA2254 - }; + }; runner_ = MongoRunner.Run(options); client_ = new MongoClient(runner_.ConnectionString); diff --git a/Common/tests/ListApplicationsRequestExt/ToApplicationFilterTest.cs b/Common/tests/ListApplicationsRequestExt/ToApplicationFilterTest.cs index d029055a5..6dfcde2d1 100644 --- a/Common/tests/ListApplicationsRequestExt/ToApplicationFilterTest.cs +++ b/Common/tests/ListApplicationsRequestExt/ToApplicationFilterTest.cs @@ -157,22 +157,22 @@ public static IEnumerable TestCasesFilter() FilterStringOperator.Equal, ApplicationName)); yield return FieldToTestCaseFalse(CreateListApplicationsFilterString(ApplicationRawEnumField.Name, - FilterStringOperator.Equal, - ApplicationName + "bad")); + FilterStringOperator.Equal, + ApplicationName + "bad")); yield return FieldToTestCaseTrue(CreateListApplicationsFilterString(ApplicationRawEnumField.Namespace, FilterStringOperator.Equal, ApplicationNamespace)); yield return FieldToTestCaseFalse(CreateListApplicationsFilterString(ApplicationRawEnumField.Namespace, - FilterStringOperator.Equal, - ApplicationNamespace + "bad")); + FilterStringOperator.Equal, + ApplicationNamespace + "bad")); yield return FieldToTestCaseTrue(CreateListApplicationsFilterString(ApplicationRawEnumField.Version, FilterStringOperator.Equal, ApplicationVersion)); yield return FieldToTestCaseFalse(CreateListApplicationsFilterString(ApplicationRawEnumField.Version, - FilterStringOperator.Equal, - ApplicationVersion + "bad")); + FilterStringOperator.Equal, + ApplicationVersion + "bad")); yield return FieldToTestCaseTrue(CreateListApplicationsFilterString(ApplicationRawEnumField.Service, FilterStringOperator.Equal, @@ -190,9 +190,8 @@ public static IEnumerable TestCasesFilter() FilterStringOperator.NotContains, ApplicationService + "bad")); yield return FieldToTestCaseFalse(CreateListApplicationsFilterString(ApplicationRawEnumField.Service, - FilterStringOperator.Equal, - ApplicationService + "bad")); - yield break; + FilterStringOperator.Equal, + ApplicationService + "bad")); } private static TestCaseData FieldToTestCaseFalse(FilterField filterField) diff --git a/Common/tests/Pollster/AgentTest.cs b/Common/tests/Pollster/AgentTest.cs index 81363525c..fe57e1b0f 100644 --- a/Common/tests/Pollster/AgentTest.cs +++ b/Common/tests/Pollster/AgentTest.cs @@ -528,8 +528,7 @@ await holder.Agent.FinalizeTaskCreation(CancellationToken.None) Assert.Contains(holder.TaskWithDependencies2, holder.QueueStorage.Messages[Partition]); Assert.AreEqual(2, - holder.QueueStorage.Messages[Partition] - .Count); + holder.QueueStorage.Messages[Partition].Count); var taskData1 = await holder.TaskTable.ReadTaskAsync(holder.TaskWithDependencies1, CancellationToken.None) @@ -720,8 +719,7 @@ await holder.Agent.FinalizeTaskCreation(CancellationToken.None) .ConfigureAwait(false); Assert.AreEqual(3, - holder.QueueStorage.Messages[Partition] - .Count); + holder.QueueStorage.Messages[Partition].Count); taskData3 = await holder.TaskTable.ReadTaskAsync(taskId3, CancellationToken.None) @@ -812,13 +810,10 @@ await holder.Agent.GetResourceData(new DataRequest Assert.AreEqual(3, resourceData.Messages.Count); Assert.AreEqual("Data1", - resourceData.Messages[0] - .Data.Data); + resourceData.Messages[0].Data.Data); Assert.AreEqual("Data2", - resourceData.Messages[1] - .Data.Data); - Assert.IsTrue(resourceData.Messages[2] - .Data.DataComplete); + resourceData.Messages[1].Data.Data); + Assert.IsTrue(resourceData.Messages[2].Data.DataComplete); } [Test] diff --git a/Common/tests/Pollster/DataPrefetcherTest.cs b/Common/tests/Pollster/DataPrefetcherTest.cs index 54eaacd92..e7eef5b94 100644 --- a/Common/tests/Pollster/DataPrefetcherTest.cs +++ b/Common/tests/Pollster/DataPrefetcherTest.cs @@ -122,101 +122,73 @@ public async Task EmptyPayloadAndOneDependency() Console.WriteLine(request); } - Assert.AreEqual(computeRequests[0] - .TypeCase, + Assert.AreEqual(computeRequests[0].TypeCase, ProcessRequest.Types.ComputeRequest.TypeOneofCase.InitRequest); - Assert.AreEqual(computeRequests[0] - .InitRequest.SessionId, + Assert.AreEqual(computeRequests[0].InitRequest.SessionId, sessionId); - Assert.AreEqual(computeRequests[0] - .InitRequest.TaskId, + Assert.AreEqual(computeRequests[0].InitRequest.TaskId, taskId); Assert.AreEqual(computeRequests[0] .InitRequest.ExpectedOutputKeys.First(), output1); - Assert.AreEqual(computeRequests[1] - .TypeCase, + Assert.AreEqual(computeRequests[1].TypeCase, ProcessRequest.Types.ComputeRequest.TypeOneofCase.Payload); - Assert.AreEqual(computeRequests[1] - .Payload.TypeCase, + Assert.AreEqual(computeRequests[1].Payload.TypeCase, DataChunk.TypeOneofCase.Data); - Assert.AreEqual(computeRequests[2] - .TypeCase, + Assert.AreEqual(computeRequests[2].TypeCase, ProcessRequest.Types.ComputeRequest.TypeOneofCase.Payload); - Assert.AreEqual(computeRequests[2] - .Payload.TypeCase, + Assert.AreEqual(computeRequests[2].Payload.TypeCase, DataChunk.TypeOneofCase.Data); - Assert.AreEqual(computeRequests[3] - .TypeCase, + Assert.AreEqual(computeRequests[3].TypeCase, ProcessRequest.Types.ComputeRequest.TypeOneofCase.Payload); - Assert.AreEqual(computeRequests[3] - .Payload.TypeCase, + Assert.AreEqual(computeRequests[3].Payload.TypeCase, DataChunk.TypeOneofCase.Data); - Assert.AreEqual(computeRequests[4] - .TypeCase, + Assert.AreEqual(computeRequests[4].TypeCase, ProcessRequest.Types.ComputeRequest.TypeOneofCase.Payload); - Assert.AreEqual(computeRequests[4] - .Payload.TypeCase, + Assert.AreEqual(computeRequests[4].Payload.TypeCase, DataChunk.TypeOneofCase.DataComplete); - Assert.IsTrue(computeRequests[4] - .Payload.DataComplete); + Assert.IsTrue(computeRequests[4].Payload.DataComplete); - Assert.AreEqual(computeRequests[5] - .TypeCase, + Assert.AreEqual(computeRequests[5].TypeCase, ProcessRequest.Types.ComputeRequest.TypeOneofCase.InitData); - Assert.AreEqual(computeRequests[5] - .InitData.Key, + Assert.AreEqual(computeRequests[5].InitData.Key, dependency1); - Assert.AreEqual(computeRequests[6] - .TypeCase, + Assert.AreEqual(computeRequests[6].TypeCase, ProcessRequest.Types.ComputeRequest.TypeOneofCase.Data); - Assert.AreEqual(computeRequests[6] - .Data.TypeCase, + Assert.AreEqual(computeRequests[6].Data.TypeCase, DataChunk.TypeOneofCase.Data); - Assert.AreEqual(computeRequests[7] - .TypeCase, + Assert.AreEqual(computeRequests[7].TypeCase, ProcessRequest.Types.ComputeRequest.TypeOneofCase.Data); - Assert.AreEqual(computeRequests[7] - .Data.TypeCase, + Assert.AreEqual(computeRequests[7].Data.TypeCase, DataChunk.TypeOneofCase.Data); - Assert.AreEqual(computeRequests[8] - .TypeCase, + Assert.AreEqual(computeRequests[8].TypeCase, ProcessRequest.Types.ComputeRequest.TypeOneofCase.Data); - Assert.AreEqual(computeRequests[8] - .Data.TypeCase, + Assert.AreEqual(computeRequests[8].Data.TypeCase, DataChunk.TypeOneofCase.Data); - Assert.AreEqual(computeRequests[9] - .TypeCase, + Assert.AreEqual(computeRequests[9].TypeCase, ProcessRequest.Types.ComputeRequest.TypeOneofCase.Data); - Assert.AreEqual(computeRequests[9] - .Data.TypeCase, + Assert.AreEqual(computeRequests[9].Data.TypeCase, DataChunk.TypeOneofCase.Data); - Assert.AreEqual(computeRequests[10] - .TypeCase, + Assert.AreEqual(computeRequests[10].TypeCase, ProcessRequest.Types.ComputeRequest.TypeOneofCase.Data); - Assert.AreEqual(computeRequests[10] - .Data.TypeCase, + Assert.AreEqual(computeRequests[10].Data.TypeCase, DataChunk.TypeOneofCase.DataComplete); - Assert.IsTrue(computeRequests[10] - .Data.DataComplete); + Assert.IsTrue(computeRequests[10].Data.DataComplete); - Assert.AreEqual(computeRequests[11] - .TypeCase, + Assert.AreEqual(computeRequests[11].TypeCase, ProcessRequest.Types.ComputeRequest.TypeOneofCase.InitData); - Assert.AreEqual(computeRequests[11] - .InitData.TypeCase, + Assert.AreEqual(computeRequests[11].InitData.TypeCase, ProcessRequest.Types.ComputeRequest.Types.InitData.TypeOneofCase.LastData); - Assert.IsTrue(computeRequests[11] - .InitData.LastData); + Assert.IsTrue(computeRequests[11].InitData.LastData); } [Test] diff --git a/Common/tests/Pollster/PollsterTest.cs b/Common/tests/Pollster/PollsterTest.cs index 4844967c7..9f8367fac 100644 --- a/Common/tests/Pollster/PollsterTest.cs +++ b/Common/tests/Pollster/PollsterTest.cs @@ -422,9 +422,7 @@ public Task Init(CancellationToken cancellationToken) => Task.CompletedTask; public void Dispose() - { - GC.SuppressFinalize(this); - } + => GC.SuppressFinalize(this); public IAsyncPipe? Pipe { get; private set; } @@ -479,10 +477,10 @@ public async Task ExecuteTaskShouldSucceed(double delay) mockPullQueueStorage.Object); var (_, _, taskSubmitted) = await InitSubmitter(testServiceProvider.Submitter, - testServiceProvider.PartitionTable, - testServiceProvider.ResultTable, - CancellationToken.None) - .ConfigureAwait(false); + testServiceProvider.PartitionTable, + testServiceProvider.ResultTable, + CancellationToken.None) + .ConfigureAwait(false); mockPullQueueStorage.Setup(storage => storage.PullMessagesAsync(It.IsAny(), It.IsAny())) @@ -533,10 +531,10 @@ public async Task CancelLongTaskShouldSucceed() mockPullQueueStorage.Object); var (_, _, taskSubmitted) = await InitSubmitter(testServiceProvider.Submitter, - testServiceProvider.PartitionTable, - testServiceProvider.ResultTable, - CancellationToken.None) - .ConfigureAwait(false); + testServiceProvider.PartitionTable, + testServiceProvider.ResultTable, + CancellationToken.None) + .ConfigureAwait(false); mockPullQueueStorage.Setup(storage => storage.PullMessagesAsync(It.IsAny(), It.IsAny())) @@ -688,10 +686,10 @@ public async Task UnavailableWorkerShouldFail() mockPullQueueStorage.Object); var (_, _, taskSubmitted) = await InitSubmitter(testServiceProvider.Submitter, - testServiceProvider.PartitionTable, - testServiceProvider.ResultTable, - CancellationToken.None) - .ConfigureAwait(false); + testServiceProvider.PartitionTable, + testServiceProvider.ResultTable, + CancellationToken.None) + .ConfigureAwait(false); mockPullQueueStorage.Setup(storage => storage.PullMessagesAsync(It.IsAny(), It.IsAny())) diff --git a/Common/tests/Pollster/TaskHandlerTest.cs b/Common/tests/Pollster/TaskHandlerTest.cs index 7317b5faa..a473d5c2e 100644 --- a/Common/tests/Pollster/TaskHandlerTest.cs +++ b/Common/tests/Pollster/TaskHandlerTest.cs @@ -999,11 +999,9 @@ public Task Init(CancellationToken cancellationToken) => Task.CompletedTask; public void Dispose() - { - GC.SuppressFinalize(this); - } + => GC.SuppressFinalize(this); - public IAsyncPipe? Pipe { get; private set; } + public IAsyncPipe? Pipe { get; } public void StartTaskProcessing(TaskData taskData, CancellationToken cancellationToken) diff --git a/Common/tests/Submitter/SubmitterTests.cs b/Common/tests/Submitter/SubmitterTests.cs index 60e5ca558..2165e20a5 100644 --- a/Common/tests/Submitter/SubmitterTests.cs +++ b/Common/tests/Submitter/SubmitterTests.cs @@ -72,7 +72,7 @@ public async Task SetUp() StandardOuputLogger = line => logger.LogInformation(line), StandardErrorLogger = line => logger.LogError(line), #pragma warning restore CA2254 - }; + }; runner_ = MongoRunner.Run(options); client_ = new MongoClient(runner_.ConnectionString); @@ -774,16 +774,12 @@ await submitter_.TryGetResult(resultRequest, .ConfigureAwait(false); Assert.AreEqual(ResultReply.TypeOneofCase.Result, - writer.Messages[0] - .TypeCase); + writer.Messages[0].TypeCase); Assert.AreEqual(ResultReply.TypeOneofCase.Result, - writer.Messages[1] - .TypeCase); + writer.Messages[1].TypeCase); Assert.AreEqual(ResultReply.TypeOneofCase.Result, - writer.Messages[2] - .TypeCase); - Assert.IsTrue(writer.Messages[2] - .Result.DataComplete); + writer.Messages[2].TypeCase); + Assert.IsTrue(writer.Messages[2].Result.DataComplete); } [Test] diff --git a/Common/tests/TestBase/AuthenticationTableTestBase.cs b/Common/tests/TestBase/AuthenticationTableTestBase.cs index e90917e22..31fe0e1a4 100644 --- a/Common/tests/TestBase/AuthenticationTableTestBase.cs +++ b/Common/tests/TestBase/AuthenticationTableTestBase.cs @@ -99,33 +99,27 @@ static AuthenticationTableTestBase() "User1", new[] { - Roles[0] - .RoleId, + Roles[0].RoleId, }), new("UserId2".ToOidString(), "User2", new[] { - Roles[0] - .RoleId, - Roles[1] - .RoleId, + Roles[0].RoleId, + Roles[1].RoleId, }), new("UserId3".ToOidString(), "User3", new[] { - Roles[0] - .RoleId, - Roles[2] - .RoleId, + Roles[0].RoleId, + Roles[2].RoleId, }), new("UserId4".ToOidString(), "User4", new[] { - Roles[0] - .RoleId, + Roles[0].RoleId, "RoleIdDontExist".ToOidString(), }), new("UserId5".ToOidString(), @@ -135,28 +129,23 @@ static AuthenticationTableTestBase() Auths = new List { new("AuthId1".ToOidString(), - Users[0] - .UserId, + Users[0].UserId, "CNUser1", "Fingerprint1"), new("AuthId2".ToOidString(), - Users[1] - .UserId, + Users[1].UserId, "CNUser2", "Fingerprint2"), new("AuthId3".ToOidString(), - Users[1] - .UserId, + Users[1].UserId, "CNUser3", "Fingerprint3"), new("AuthId4".ToOidString(), - Users[2] - .UserId, + Users[2].UserId, "CNUser4", "Fingerprint4"), new("AuthId5".ToOidString(), - Users[3] - .UserId, + Users[3].UserId, "CNUser5", "Fingerprint5"), new("AuthId6".ToOidString(), @@ -164,18 +153,15 @@ static AuthenticationTableTestBase() "CNUser6", "Fingerprint6"), new("AuthId7".ToOidString(), - Users[1] - .UserId, + Users[1].UserId, "CNUser2", "Fingerprint7"), new("AuthId8".ToOidString(), - Users[2] - .UserId, + Users[2].UserId, "CNUserCommon", null), new("AuthId9".ToOidString(), - Users[3] - .UserId, + Users[3].UserId, "CNUser2", null), }; @@ -194,7 +180,7 @@ static AuthenticationTableTestBase() protected bool RunTests; /* Function be override so it returns the suitable instance - * of AuthenticationTable to the corresponding interface implementation */ + * of AuthenticationTable to the corresponding interface implementation */ public virtual void GetAuthSource() { } @@ -270,8 +256,7 @@ public void GetIdentityFromCnAndFingerprintShouldSucceed(string cn, CancellationToken.None) .Result; Assert.NotNull(ident); - Assert.AreEqual(Users[userid] - .UserId, + Assert.AreEqual(Users[userid].UserId, ident!.Id); } @@ -305,13 +290,11 @@ public void GetIdentityFromIdShouldSucceed(int id, return; } - var ident = AuthenticationTable!.GetIdentityFromUserAsync(Users[id] - .UserId, + var ident = AuthenticationTable!.GetIdentityFromUserAsync(Users[id].UserId, null) .Result; Assert.NotNull(ident); - Assert.AreEqual(Users[id] - .UserId, + Assert.AreEqual(Users[id].UserId, ident!.Id); Assert.AreEqual(username, ident.Username); @@ -348,8 +331,7 @@ public void GetIdentityFromNameShouldSucceed(string name, Assert.NotNull(identity); Assert.AreEqual(name, identity!.Username); - Assert.AreEqual(Users[id] - .UserId, + Assert.AreEqual(Users[id].UserId, identity.Id); } diff --git a/Common/tests/TestBase/PartitionTableTestBase.cs b/Common/tests/TestBase/PartitionTableTestBase.cs index e058eb87f..8429ada58 100644 --- a/Common/tests/TestBase/PartitionTableTestBase.cs +++ b/Common/tests/TestBase/PartitionTableTestBase.cs @@ -230,12 +230,12 @@ public async Task ListPartitionsEmptyResultShouldSucceed() if (RunTests) { var (_, totalCount) = await PartitionTable!.ListPartitionsAsync(data => data.PartitionId == "NotExisting", - data => data.ParentPartitionIds, - false, - 0, - 20, - CancellationToken.None) - .ConfigureAwait(false); + data => data.ParentPartitionIds, + false, + 0, + 20, + CancellationToken.None) + .ConfigureAwait(false); Assert.AreEqual(0, totalCount); @@ -248,12 +248,12 @@ public async Task ListPartitionsContainsShouldSucceed() if (RunTests) { var (_, totalCount) = await PartitionTable!.ListPartitionsAsync(data => data.ParentPartitionIds.Contains("ParentPartitionId"), - data => data.PartitionId, - false, - 0, - 20, - CancellationToken.None) - .ConfigureAwait(false); + data => data.PartitionId, + false, + 0, + 20, + CancellationToken.None) + .ConfigureAwait(false); Assert.AreEqual(1, totalCount); @@ -268,12 +268,12 @@ public async Task ListPartitionFilter(ListPartitionsRequest request, if (RunTests) { var (_, totalCount) = await PartitionTable!.ListPartitionsAsync(request.Filters.ToPartitionFilter(), - data => data.PartitionId, - false, - 0, - 20, - CancellationToken.None) - .ConfigureAwait(false); + data => data.PartitionId, + false, + 0, + 20, + CancellationToken.None) + .ConfigureAwait(false); Assert.AreEqual(count, totalCount); diff --git a/Common/tests/TestBase/SessionTableTestBase.cs b/Common/tests/TestBase/SessionTableTestBase.cs index 5ec4fc43b..607f02265 100644 --- a/Common/tests/TestBase/SessionTableTestBase.cs +++ b/Common/tests/TestBase/SessionTableTestBase.cs @@ -57,13 +57,13 @@ public async Task SetUp() .ConfigureAwait(false); rootSessionId1_ = await SessionTable!.SetSessionDataAsync(new[] - { - "part1", - "part2", - }, - Options, - CancellationToken.None) - .ConfigureAwait(false); + { + "part1", + "part2", + }, + Options, + CancellationToken.None) + .ConfigureAwait(false); await SessionTable!.SetSessionDataAsync(new[] { @@ -109,20 +109,20 @@ public virtual void TearDown() } private static readonly TaskOptions Options = new(new Dictionary - { - { - "key1", "val1" - }, - }, - TimeSpan.FromMinutes(1), - 2, - 1, - "part1", - "ApplicationName", - "ApplicationVersion", - "", - "", - ""); + { + { + "key1", "val1" + }, + }, + TimeSpan.FromMinutes(1), + 2, + 1, + "part1", + "ApplicationName", + "ApplicationVersion", + "", + "", + ""); private static bool CheckForSkipSetup() { diff --git a/Common/tests/TestBase/TaskTableTestBase.cs b/Common/tests/TestBase/TaskTableTestBase.cs index eccb73525..3ad906c2b 100644 --- a/Common/tests/TestBase/TaskTableTestBase.cs +++ b/Common/tests/TestBase/TaskTableTestBase.cs @@ -16,6 +16,7 @@ // along with this program. If not, see . // in tests, Tasks can be explicitly waited + #pragma warning disable CA2012 using System; @@ -399,9 +400,9 @@ public async Task UpdateAllTaskStatusAsyncShouldSucceed() Ids = { "SessionId", /* Task with TaskStatus.Processing was given this Id, - * for the Memory interface, adding it here is necessary for the test - * to succeed. For the MongoDB interface it may be ignored. - * TODO: Check filter definitions */ + * for the Memory interface, adding it here is necessary for the test + * to succeed. For the MongoDB interface it may be ignored. + * TODO: Check filter definitions */ }, }, }; @@ -410,17 +411,17 @@ public async Task UpdateAllTaskStatusAsyncShouldSucceed() CancellationToken.None) .ConfigureAwait(false); var resCreating = await TaskTable!.GetTaskStatus(new[] - { - "TaskCreatingId", - }, - CancellationToken.None) - .ConfigureAwait(false); + { + "TaskCreatingId", + }, + CancellationToken.None) + .ConfigureAwait(false); var resProcessing = await TaskTable!.GetTaskStatus(new[] - { - "TaskProcessingId", - }, - CancellationToken.None) - .ConfigureAwait(false); + { + "TaskProcessingId", + }, + CancellationToken.None) + .ConfigureAwait(false); Assert.IsTrue(resCreating.Single() .Status == TaskStatus.Timeout && resProcessing.Single() @@ -449,17 +450,17 @@ public async Task UpdateAllTaskStatusAsyncShouldSucceedIfNoStatusGiven() CancellationToken.None) .ConfigureAwait(false); var resCreating = await TaskTable!.GetTaskStatus(new[] - { - "TaskCreatingId", - }, - CancellationToken.None) - .ConfigureAwait(false); + { + "TaskCreatingId", + }, + CancellationToken.None) + .ConfigureAwait(false); var resProcessing = await TaskTable!.GetTaskStatus(new[] - { - "TaskProcessingId", - }, - CancellationToken.None) - .ConfigureAwait(false); + { + "TaskProcessingId", + }, + CancellationToken.None) + .ConfigureAwait(false); Assert.IsTrue(resCreating.Single() .Status == TaskStatus.Timeout && resProcessing.Single() @@ -704,11 +705,11 @@ public async Task SetTaskSuccessAsyncShouldSucceed() .ConfigureAwait(false); var resStatus = await TaskTable!.GetTaskStatus(new[] - { - taskProcessingData_.TaskId, - }, - CancellationToken.None) - .ConfigureAwait(false); + { + taskProcessingData_.TaskId, + }, + CancellationToken.None) + .ConfigureAwait(false); Assert.AreEqual(TaskStatus.Completed, resStatus.Single() @@ -1336,13 +1337,13 @@ public async Task ListApplicationFromTasksShouldSucceed() .IsValid); var (applications, _) = await TaskTable!.ListApplicationsAsync(req.Filters.ToApplicationFilter(), - req.Sort.Fields.Select(sort => sort.ToField()) - .ToList(), - false, - req.Page, - req.PageSize, - CancellationToken.None) - .ConfigureAwait(false); + req.Sort.Fields.Select(sort => sort.ToField()) + .ToList(), + false, + req.Page, + req.PageSize, + CancellationToken.None) + .ConfigureAwait(false); var listTasksResponseTaskData = applications.ToList(); foreach (var task in listTasksResponseTaskData) @@ -1512,13 +1513,13 @@ taskData1 with .IsValid); var (applications, _) = await TaskTable.ListApplicationsAsync(req.Filters.ToApplicationFilter(), - req.Sort.Fields.Select(sort => sort.ToField()) - .ToList(), - req.Sort.Direction == SortDirection.Asc, - req.Page, - req.PageSize, - CancellationToken.None) - .ConfigureAwait(false); + req.Sort.Fields.Select(sort => sort.ToField()) + .ToList(), + req.Sort.Direction == SortDirection.Asc, + req.Page, + req.PageSize, + CancellationToken.None) + .ConfigureAwait(false); var listTasksResponseTaskData = applications.ToList(); foreach (var task in listTasksResponseTaskData) @@ -1545,13 +1546,13 @@ public async Task ListTaskWithRequestShouldSucceed() if (RunTests) { var (_, totalCount) = await TaskTable!.ListTasksAsync(data => data.SessionId == "SessionId", - data => data.SessionId, - data => data, - false, - 0, - 20, - CancellationToken.None) - .ConfigureAwait(false); + data => data.SessionId, + data => data, + false, + 0, + 20, + CancellationToken.None) + .ConfigureAwait(false); Assert.AreEqual(6, totalCount); @@ -1608,13 +1609,13 @@ public async Task ListTaskWithRequestOrderByTaskOptionsOptionsShouldSucceed() }; var (_, totalCount) = await TaskTable!.ListTasksAsync(req.Filters.ToTaskDataFilter(), - req.Sort.ToField(), - data => data, - false, - 0, - 20, - CancellationToken.None) - .ConfigureAwait(false); + req.Sort.ToField(), + data => data, + false, + 0, + 20, + CancellationToken.None) + .ConfigureAwait(false); Assert.AreEqual(6, totalCount); @@ -1633,13 +1634,13 @@ public async Task ListTaskWithListInRequestShouldSucceed() }; var (_, totalCount) = await TaskTable!.ListTasksAsync(data => statusList.Contains(data.Status), - data => data.SessionId, - data => data, - false, - 0, - 20, - CancellationToken.None) - .ConfigureAwait(false); + data => data.SessionId, + data => data, + false, + 0, + 20, + CancellationToken.None) + .ConfigureAwait(false); Assert.AreEqual(3, totalCount); @@ -1652,13 +1653,13 @@ public async Task ListTaskEmptyResultShouldSucceed() if (RunTests) { var (_, totalCount) = await TaskTable!.ListTasksAsync(data => data.TaskId == "NotExisting", - data => data.SessionId, - data => data, - false, - 0, - 20, - CancellationToken.None) - .ConfigureAwait(false); + data => data.SessionId, + data => data, + false, + 0, + 20, + CancellationToken.None) + .ConfigureAwait(false); Assert.AreEqual(0, totalCount); @@ -1673,13 +1674,13 @@ public async Task ListTaskFilter(ListTasksRequest request, if (RunTests) { var (_, totalCount) = await TaskTable!.ListTasksAsync(request.Filters.ToTaskDataFilter(), - data => data.SessionId, - data => data, - false, - 0, - 20, - CancellationToken.None) - .ConfigureAwait(false); + data => data.SessionId, + data => data, + false, + 0, + 20, + CancellationToken.None) + .ConfigureAwait(false); Assert.AreEqual(count, totalCount); diff --git a/Control/Metrics/src/ArmoniK.Core.Control.Metrics.csproj b/Control/Metrics/src/ArmoniK.Core.Control.Metrics.csproj index 4a9bd17c3..5e7b32ff5 100644 --- a/Control/Metrics/src/ArmoniK.Core.Control.Metrics.csproj +++ b/Control/Metrics/src/ArmoniK.Core.Control.Metrics.csproj @@ -41,8 +41,8 @@ - + - + diff --git a/Control/Submitter/tests/ArmoniK.Core.Control.Submitter.Tests.csproj b/Control/Submitter/tests/ArmoniK.Core.Control.Submitter.Tests.csproj index f12a2d145..ae7d4573d 100644 --- a/Control/Submitter/tests/ArmoniK.Core.Control.Submitter.Tests.csproj +++ b/Control/Submitter/tests/ArmoniK.Core.Control.Submitter.Tests.csproj @@ -16,7 +16,7 @@ - + diff --git a/ProfilingTools/src/ArmoniK.Core.ProfilingTools.csproj b/ProfilingTools/src/ArmoniK.Core.ProfilingTools.csproj index bdb2ca4eb..10083c1d3 100644 --- a/ProfilingTools/src/ArmoniK.Core.ProfilingTools.csproj +++ b/ProfilingTools/src/ArmoniK.Core.ProfilingTools.csproj @@ -38,7 +38,7 @@ - + diff --git a/Tests/Bench/Client/src/Program.cs b/Tests/Bench/Client/src/Program.cs index b52a68521..a32f1d9d0 100644 --- a/Tests/Bench/Client/src/Program.cs +++ b/Tests/Bench/Client/src/Program.cs @@ -15,7 +15,6 @@ // You should have received a copy of the GNU Affero General Public License // along with this program. If not, see . - using System; using System.Diagnostics; using System.Linq; diff --git a/Tests/Bench/Server/src/BenchComputerService.cs b/Tests/Bench/Server/src/BenchComputerService.cs index eea585570..34d2293d1 100644 --- a/Tests/Bench/Server/src/BenchComputerService.cs +++ b/Tests/Bench/Server/src/BenchComputerService.cs @@ -16,6 +16,7 @@ // along with this program. If not, see . // In samples, Random can be used + #pragma warning disable SEC0115 using System; @@ -33,7 +34,6 @@ using Microsoft.Extensions.Logging; - namespace ArmoniK.Samples.Bench.Server; [UsedImplicitly] diff --git a/Tests/Bench/Server/src/GlobalSuppressions.cs b/Tests/Bench/Server/src/GlobalSuppressions.cs index 2ebdbfefb..6b6edd0db 100644 --- a/Tests/Bench/Server/src/GlobalSuppressions.cs +++ b/Tests/Bench/Server/src/GlobalSuppressions.cs @@ -1,8 +1,22 @@ -// This file is used by Code Analysis to maintain SuppressMessage -// attributes that are applied to this project. -// Project-level suppressions either have no target or are given -// a specific target and scoped to a namespace, type, member, etc. +// 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.Diagnostics.CodeAnalysis; -[assembly: SuppressMessage("CodeQuality", "IDE0079:Remove unnecessary suppression", Justification = "")] +[assembly: SuppressMessage("CodeQuality", + "IDE0079:Remove unnecessary suppression", + Justification = "")] diff --git a/Tests/HtcMock/Client/src/ArmoniK.Samples.HtcMock.Client.csproj b/Tests/HtcMock/Client/src/ArmoniK.Samples.HtcMock.Client.csproj index 90631aeac..50ec59c92 100644 --- a/Tests/HtcMock/Client/src/ArmoniK.Samples.HtcMock.Client.csproj +++ b/Tests/HtcMock/Client/src/ArmoniK.Samples.HtcMock.Client.csproj @@ -1,45 +1,45 @@  - - Exe - net6.0 - true - ANEO - Copyright (C) ANEO, 2021-2021 - AGPL-3.0-or-later - True - Linux - ..\..\..\.. + + Exe + net6.0 + true + ANEO + Copyright (C) ANEO, 2021-2021 + AGPL-3.0-or-later + True + Linux + ..\..\..\.. enable - + - - embedded - true - snupkg - DEBUG;TRACE - + + embedded + true + snupkg + DEBUG;TRACE + - - true - + + true + - - + + - - - - - - - - - - + + + + + + + + + + diff --git a/Tests/HtcMock/Client/src/SessionClient.cs b/Tests/HtcMock/Client/src/SessionClient.cs index 663628c0e..ebbb5423b 100644 --- a/Tests/HtcMock/Client/src/SessionClient.cs +++ b/Tests/HtcMock/Client/src/SessionClient.cs @@ -17,6 +17,7 @@ using System; using System.Collections.Generic; +using System.Diagnostics.CodeAnalysis; using System.Linq; using System.Threading.Tasks; @@ -67,9 +68,9 @@ public void Dispose() .Wait(); } - [System.Diagnostics.CodeAnalysis.SuppressMessage("Style", - "CA2208", - Justification = "availabilityReply.TypeCase is not a real argument")] + [SuppressMessage("Style", + "CA2208", + Justification = "availabilityReply.TypeCase is not a real argument")] public byte[] GetResult(string id) { var resultRequest = new ResultRequest @@ -100,9 +101,9 @@ public byte[] GetResult(string id) return response.Result; } - [System.Diagnostics.CodeAnalysis.SuppressMessage("Style", - "CA2208", - Justification = "availabilityReply.TypeCase is not a real argument")] + [SuppressMessage("Style", + "CA2208", + Justification = "availabilityReply.TypeCase is not a real argument")] public Task WaitSubtasksCompletion(string id) { var resultRequest = new ResultRequest @@ -132,9 +133,9 @@ public Task WaitSubtasksCompletion(string id) return Task.CompletedTask; } - [System.Diagnostics.CodeAnalysis.SuppressMessage("Style", - "CA2208", - Justification = "createTaskReply.ResponseCase is not a real argument")] + [SuppressMessage("Style", + "CA2208", + Justification = "createTaskReply.ResponseCase is not a real argument")] public IEnumerable SubmitTasksWithDependencies(IEnumerable>> payloadsWithDependencies) { var taskRequests = new List(); diff --git a/Tests/Stream/Client/StreamWrapperTests.cs b/Tests/Stream/Client/StreamWrapperTests.cs index bb2381035..51ddb3fb1 100644 --- a/Tests/Stream/Client/StreamWrapperTests.cs +++ b/Tests/Stream/Client/StreamWrapperTests.cs @@ -15,7 +15,6 @@ // 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.Generic; using System.Diagnostics; @@ -260,8 +259,7 @@ public async Task TaskFailed() Payload = ByteString.CopyFrom(payload.Serialize()), ExpectedOutputKeys = { - results.Results[i] - .ResultId, + results.Results[i].ResultId, }, }; taskRequests.Add(req); @@ -325,8 +323,7 @@ public async Task MultipleTasks([Values(4, { Type = taskType, DataBytes = BitConverter.GetBytes(i), - ResultKey = results.Results[i] - .ResultId, + ResultKey = results.Results[i].ResultId, }; var req = new TaskRequest @@ -334,8 +331,7 @@ public async Task MultipleTasks([Values(4, Payload = ByteString.CopyFrom(payload.Serialize()), ExpectedOutputKeys = { - results.Results[i] - .ResultId, + results.Results[i].ResultId, }, }; taskRequestList.Add(req); @@ -415,12 +411,10 @@ public async Task MultipleDataDependencies([Values(1, { var payload = new TestPayload { - Type = TestPayload.TaskType.DatadepTransfer, - DataBytes = BitConverter.GetBytes(i + 5), - ResultKey = resultsMetaData.Results[2 * i] - .ResultId, - ResultKey2 = resultsMetaData.Results[2 * i + 1] - .ResultId, + Type = TestPayload.TaskType.DatadepTransfer, + DataBytes = BitConverter.GetBytes(i + 5), + ResultKey = resultsMetaData.Results[2 * i].ResultId, + ResultKey2 = resultsMetaData.Results[2 * i + 1].ResultId, }; var req = new TaskRequest @@ -428,10 +422,8 @@ public async Task MultipleDataDependencies([Values(1, Payload = ByteString.CopyFrom(payload.Serialize()), ExpectedOutputKeys = { - resultsMetaData.Results[2 * i] - .ResultId, - resultsMetaData.Results[2 * i + 1] - .ResultId, + resultsMetaData.Results[2 * i].ResultId, + resultsMetaData.Results[2 * i + 1].ResultId, }, }; taskRequestList.Add(req); @@ -546,8 +538,7 @@ public async Task LargePayloads([Values(2, Payload = byteString, ExpectedOutputKeys = { - resultsMetaData.Results[i] - .ResultId, + resultsMetaData.Results[i].ResultId, }, }; @@ -709,8 +700,7 @@ private async Task RunForPriority(string sessionId, { Type = TestPayload.TaskType.Compute, DataBytes = BitConverter.GetBytes(1), - ResultKey = resultsMetaData.Results[i] - .ResultId, + ResultKey = resultsMetaData.Results[i].ResultId, }; var req = new TaskRequest @@ -718,8 +708,7 @@ private async Task RunForPriority(string sessionId, Payload = ByteString.CopyFrom(payload.Serialize()), ExpectedOutputKeys = { - resultsMetaData.Results[i] - .ResultId, + resultsMetaData.Results[i].ResultId, }, }; diff --git a/Tests/Stream/Client/SubmitterExt.cs b/Tests/Stream/Client/SubmitterExt.cs index b41936195..352ad4af0 100644 --- a/Tests/Stream/Client/SubmitterExt.cs +++ b/Tests/Stream/Client/SubmitterExt.cs @@ -17,6 +17,7 @@ using System; using System.Collections.Generic; +using System.Diagnostics.CodeAnalysis; using System.Linq; using System.Threading.Tasks; @@ -53,9 +54,9 @@ public static string CreateSessionAndCheckReply(this Submitter.SubmitterClient c } - [System.Diagnostics.CodeAnalysis.SuppressMessage("Reliability", - "CA2208: Call the ArgumentOutOfRangeException constructor that contains a message and/or paramName parameter", - Justification = "createTaskReply.ResponseCase is not a real argument")] + [SuppressMessage("Reliability", + "CA2208: Call the ArgumentOutOfRangeException constructor that contains a message and/or paramName parameter", + Justification = "createTaskReply.ResponseCase is not a real argument")] public static async Task> CreateTasksAndCheckReplyAsync(this Submitter.SubmitterClient client, string sessionId, TaskOptions? taskOptions, diff --git a/Tests/Stream/Common/ArmoniK.Extensions.Common.StreamWrapper.Tests.Common.csproj b/Tests/Stream/Common/ArmoniK.Extensions.Common.StreamWrapper.Tests.Common.csproj index 3577dd00c..27f702b83 100644 --- a/Tests/Stream/Common/ArmoniK.Extensions.Common.StreamWrapper.Tests.Common.csproj +++ b/Tests/Stream/Common/ArmoniK.Extensions.Common.StreamWrapper.Tests.Common.csproj @@ -5,9 +5,9 @@ enable enable - + - + diff --git a/Tests/Stream/Server/WorkerService.cs b/Tests/Stream/Server/WorkerService.cs index 9b804845e..31ec169bc 100644 --- a/Tests/Stream/Server/WorkerService.cs +++ b/Tests/Stream/Server/WorkerService.cs @@ -16,6 +16,7 @@ // along with this program. If not, see . using System; +using System.Diagnostics.CodeAnalysis; using System.Linq; using System.Security.Cryptography; using System.Threading.Tasks; @@ -40,9 +41,9 @@ public WorkerService(ILoggerFactory loggerFactory, { } - [System.Diagnostics.CodeAnalysis.SuppressMessage("Style", - "CA2208: Call the ArgumentOutOfRangeException constructor that contains a message and/or paramName parameter", - Justification = "taskHandler.ExpectedResults.Count is not a real argument")] + [SuppressMessage("Style", + "CA2208: Call the ArgumentOutOfRangeException constructor that contains a message and/or paramName parameter", + Justification = "taskHandler.ExpectedResults.Count is not a real argument")] public override async Task Process(ITaskHandler taskHandler) { var output = new Output(); diff --git a/dotnet-coverage.runsettings.xml b/dotnet-coverage.runsettings.xml index 788f38e05..5f6bab48c 100644 --- a/dotnet-coverage.runsettings.xml +++ b/dotnet-coverage.runsettings.xml @@ -1,26 +1,27 @@ + - - - - .*\.dll$ - .*\.exe$ - - - .*Moq.dll$ - .*Mongo2Go.dll$ - .*FluentValidation.dll$ - .*NUnit3.TestAdapter.dll$ - .*System.*\.dll$ - .*StackExchange.Redis.dll$ - .*Protobuf.MSBuild.dll$ - .*Pipelines.Sockets.Unofficial.dll$ - - - - - ^System\.Diagnostics\.CodeAnalysis\.ExcludeFromCodeCoverageAttribute$ - - - + + + + .*\.dll$ + .*\.exe$ + + + .*Moq.dll$ + .*Mongo2Go.dll$ + .*FluentValidation.dll$ + .*NUnit3.TestAdapter.dll$ + .*System.*\.dll$ + .*StackExchange.Redis.dll$ + .*Protobuf.MSBuild.dll$ + .*Pipelines.Sockets.Unofficial.dll$ + + + + + ^System\.Diagnostics\.CodeAnalysis\.ExcludeFromCodeCoverageAttribute$ + + + diff --git a/terraform/activemq/activemq.xml b/terraform/activemq/activemq.xml index 0b7b98e96..fb3b95321 100644 --- a/terraform/activemq/activemq.xml +++ b/terraform/activemq/activemq.xml @@ -4,30 +4,30 @@ xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://activemq.apache.org/schema/core http://activemq.apache.org/schema/core/activemq-core.xsd"> - - - - file:${activemq.conf}/credentials.properties - - - - - - - - + + + file:${activemq.conf}/credentials.properties + + + + + + + + - - - - - - - - - - - - - - - + + + + + + + - - - - + + + - - - - + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + - + diff --git a/terraform/activemq/jetty.xml b/terraform/activemq/jetty.xml index bf99de33e..f0f3865ef 100644 --- a/terraform/activemq/jetty.xml +++ b/terraform/activemq/jetty.xml @@ -1,5 +1,4 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - index.html - - - - - - - - - + xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd"> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - + index.html - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - + + + + + + + - - - - - - - - - - - - - - - + + + + - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + - - - + + + diff --git a/terraform/artemis/broker.xml b/terraform/artemis/broker.xml index 43fbfc28c..8f16fb5c5 100644 --- a/terraform/artemis/broker.xml +++ b/terraform/artemis/broker.xml @@ -1,4 +1,5 @@ + - ASYNCIO + ASYNCIO - data/paging + data/paging - data/bindings + data/bindings - data/journal + data/journal - data/large-messages + data/large-messages - + true - true - - 2 + 2 - 10 + 10 - 4096 + 4096 - 10M + 10M - - 112000 + 112000 - - 4096 - - - - + + - - - - - - - - + + + + + - - 5000 + + 5000 - - 90 + 90 - - true - 120000 - 60000 - HALT - 592000 + + true + 120000 + 60000 + HALT + 592000 - - - -1 + -1 - + - - - - + + + - - - - tcp://0.0.0.0:5672?tcpSendBufferSize=1048576;tcpReceiveBufferSize=1048576;protocols=AMQP;useEpoll=true;amqpCredits=100000;amqpLowCredits=30000;amqpMinLargeMessageSize=102400;amqpDuplicateDetection=false - - - - - - - - - - - - - - - - - - - - - - - DLQ - ExpiryQueue - 0 - - -1 - 10 - PAGE - true - true - - - - DLQ - ExpiryQueue - 0 - - + tcp://0.0.0.0:5672?tcpSendBufferSize=1048576;tcpReceiveBufferSize=1048576;protocols=AMQP;useEpoll=true;amqpCredits=100000;amqpLowCredits=30000;amqpMinLargeMessageSize=102400;amqpDuplicateDetection=false + + + + + + + + + + + + + + + + + + + + + + + DLQ + ExpiryQueue + 0 + + -1 + 10 + PAGE + true + true + + + + DLQ + ExpiryQueue + 0 + + - - -1 + + -1 - - -1 + + -1 - - 10M - - - -1 - - - 20M - - 10 - PAGE - true - true - false - false - ANYCAST - ANYCAST - - - - -
- - - -
-
- - - -
- -
- - - + -1 + + + 20M + + 10 + PAGE + true + true + false + false + ANYCAST + ANYCAST + + + + +
+ + + +
+
+ + + +
+ +
+ + + - + From 75f0a511be6031ee4086bc0b9bbeff9fcad1557b Mon Sep 17 00:00:00 2001 From: wkirschenmann Date: Thu, 10 Aug 2023 18:00:30 +0200 Subject: [PATCH 11/21] Apply reformat patch --- Adaptors/Memory/src/SessionTable.cs | 13 +-- Adaptors/Memory/src/TaskTable.cs | 19 +++-- .../src/Table/DataModel/IndexHelper.cs | 18 ++-- Adaptors/MongoDB/tests/SessionTableTests.cs | 4 +- .../src/Auth/Authentication/Authenticator.cs | 5 +- Common/src/gRPC/ExpressionBuilders.cs | 8 +- .../Auth/AuthenticationIntegrationTest.cs | 15 ++-- Common/tests/Pollster/AgentTest.cs | 15 ++-- Common/tests/Pollster/DataPrefetcherTest.cs | 84 ++++++++++++------- Common/tests/Submitter/SubmitterTests.cs | 12 ++- .../TestBase/AuthenticationTableTestBase.cs | 54 ++++++++---- Tests/Stream/Client/StreamWrapperTests.cs | 34 +++++--- 12 files changed, 183 insertions(+), 98 deletions(-) diff --git a/Adaptors/Memory/src/SessionTable.cs b/Adaptors/Memory/src/SessionTable.cs index a2de371b5..af5661b14 100644 --- a/Adaptors/Memory/src/SessionTable.cs +++ b/Adaptors/Memory/src/SessionTable.cs @@ -107,7 +107,8 @@ public Task GetDefaultTaskOptionAsync(string sessionId, throw new SessionNotFoundException($"Key '{sessionId}' not found"); } - return Task.FromResult(storage_[sessionId].Options); + return Task.FromResult(storage_[sessionId] + .Options); } /// @@ -160,10 +161,12 @@ public IAsyncEnumerable ListSessionsAsync(SessionFilter sessionFilte return rawList.Where(sessionId => sessionFilter.StatusesCase switch { - SessionFilter.StatusesOneofCase.None => true, - SessionFilter.StatusesOneofCase.Included => sessionFilter.Included.Statuses.Contains(storage_[sessionId].Status), - SessionFilter.StatusesOneofCase.Excluded => !sessionFilter.Excluded.Statuses.Contains(storage_[sessionId].Status), - _ => throw new ArgumentException("Filter is set to an unknown StatusesCase."), + SessionFilter.StatusesOneofCase.None => true, + SessionFilter.StatusesOneofCase.Included => sessionFilter.Included.Statuses.Contains(storage_[sessionId] + .Status), + SessionFilter.StatusesOneofCase.Excluded => !sessionFilter.Excluded.Statuses.Contains(storage_[sessionId] + .Status), + _ => throw new ArgumentException("Filter is set to an unknown StatusesCase."), }); } diff --git a/Adaptors/Memory/src/TaskTable.cs b/Adaptors/Memory/src/TaskTable.cs index 986143cc0..e3f1facef 100644 --- a/Adaptors/Memory/src/TaskTable.cs +++ b/Adaptors/Memory/src/TaskTable.cs @@ -124,7 +124,8 @@ public async Task> CountTasksAsync(TaskFilter CancellationToken cancellationToken = default) => await ListTasksAsync(filter, cancellationToken) - .Select(taskId => taskId2TaskData_[taskId].Status) + .Select(taskId => taskId2TaskData_[taskId] + .Status) .GroupBy(status => status) .SelectAwait(async grouping => new TaskStatusCount(grouping.Key, await grouping.CountAsync(cancellationToken) @@ -224,10 +225,12 @@ public IAsyncEnumerable ListTasksAsync(TaskFilter filter, return rawList.Where(taskId => filter.StatusesCase switch { - TaskFilter.StatusesOneofCase.None => true, - TaskFilter.StatusesOneofCase.Included => filter.Included.Statuses.Contains(taskId2TaskData_[taskId].Status), - TaskFilter.StatusesOneofCase.Excluded => !filter.Excluded.Statuses.Contains(taskId2TaskData_[taskId].Status), - _ => throw new ArgumentException("Filter is set to an unknown StatusesCase."), + TaskFilter.StatusesOneofCase.None => true, + TaskFilter.StatusesOneofCase.Included => filter.Included.Statuses.Contains(taskId2TaskData_[taskId] + .Status), + TaskFilter.StatusesOneofCase.Excluded => !filter.Excluded.Statuses.Contains(taskId2TaskData_[taskId] + .Status), + _ => throw new ArgumentException("Filter is set to an unknown StatusesCase."), }) .ToAsyncEnumerable(); } @@ -356,7 +359,8 @@ public Task GetTaskOutput(string taskId, throw new TaskNotFoundException($"Key '{taskId}' not found"); } - return Task.FromResult(taskId2TaskData_[taskId].Output); + return Task.FromResult(taskId2TaskData_[taskId] + .Output); } /// @@ -429,7 +433,8 @@ public Task> GetParentTaskIds(string taskId, throw new TaskNotFoundException($"Key '{taskId}' not found"); } - return Task.FromResult(taskId2TaskData_[taskId].ParentTaskIds as IEnumerable); + return Task.FromResult(taskId2TaskData_[taskId] + .ParentTaskIds as IEnumerable); } /// diff --git a/Adaptors/MongoDB/src/Table/DataModel/IndexHelper.cs b/Adaptors/MongoDB/src/Table/DataModel/IndexHelper.cs index 482095a6d..80b1aa34e 100644 --- a/Adaptors/MongoDB/src/Table/DataModel/IndexHelper.cs +++ b/Adaptors/MongoDB/src/Table/DataModel/IndexHelper.cs @@ -203,20 +203,26 @@ public static CreateIndexModel CreateIndex(bool if (field.Length == 1) { - if (unique && field[0].type == IndexType.Hashed) + if (unique && field[0] + .type == IndexType.Hashed) { throw new ArgumentOutOfRangeException(nameof(unique), "A hashed index cannot be constrained to be unique"); } - return field[0].type switch + return field[0] + .type switch { - IndexType.Ascending => CreateAscendingIndex(field[0].expression, + IndexType.Ascending => CreateAscendingIndex(field[0] + .expression, unique), - IndexType.Descending => CreateAscendingIndex(field[0].expression, + IndexType.Descending => CreateAscendingIndex(field[0] + .expression, unique), - IndexType.Hashed => CreateHashedIndex(field[0].expression), - IndexType.Text => CreateTextIndex(field[0].expression, + IndexType.Hashed => CreateHashedIndex(field[0] + .expression), + IndexType.Text => CreateTextIndex(field[0] + .expression, unique), _ => throw new ArgumentOutOfRangeException(nameof(field), "Invalid IndexType"), diff --git a/Adaptors/MongoDB/tests/SessionTableTests.cs b/Adaptors/MongoDB/tests/SessionTableTests.cs index 921334b36..b94ed9159 100644 --- a/Adaptors/MongoDB/tests/SessionTableTests.cs +++ b/Adaptors/MongoDB/tests/SessionTableTests.cs @@ -24,14 +24,14 @@ namespace ArmoniK.Core.Adapters.MongoDB.Tests; public class SessionTableTests : SessionTableTestBase { - private MongoDatabaseProvider? tableProvider_; - public override void TearDown() { tableProvider_?.Dispose(); RunTests = false; } + private MongoDatabaseProvider? tableProvider_; + public override void GetSessionTableInstance() { tableProvider_ = new MongoDatabaseProvider(); diff --git a/Common/src/Auth/Authentication/Authenticator.cs b/Common/src/Auth/Authentication/Authenticator.cs index 3e4d092bb..3738c8461 100644 --- a/Common/src/Auth/Authentication/Authenticator.cs +++ b/Common/src/Auth/Authentication/Authenticator.cs @@ -362,8 +362,9 @@ public async Task GetImpersonatedIdentityAsync(ClaimsPrincipal /// Value of the header if found and not empty, null otherwise private string? TryGetHeader(string headerName) { - if (!string.IsNullOrEmpty(headerName) && Request.Headers.TryGetValue(headerName, - out var values) && !string.IsNullOrWhiteSpace(values.First())) + if (!string.IsNullOrEmpty(headerName) && Request.Headers.TryGetValue(headerName, + out var values) && + !string.IsNullOrWhiteSpace(values.First())) { return values.First(); } diff --git a/Common/src/gRPC/ExpressionBuilders.cs b/Common/src/gRPC/ExpressionBuilders.cs index 77ff09ad7..428b43cff 100644 --- a/Common/src/gRPC/ExpressionBuilders.cs +++ b/Common/src/gRPC/ExpressionBuilders.cs @@ -147,10 +147,10 @@ public static Expression> MakeCallString(Expression m.Name == method && m.GetParameters() - .Length == 1 && m.GetParameters() - .First() - .ParameterType == typeof(string)); + .First(m => m.Name == method && m.GetParameters() + .Length == 1 && m.GetParameters() + .First() + .ParameterType == typeof(string)); var call = Expression.Call(member, methodInfo, diff --git a/Common/tests/Auth/AuthenticationIntegrationTest.cs b/Common/tests/Auth/AuthenticationIntegrationTest.cs index 4a0ff829b..e60b836a4 100644 --- a/Common/tests/Auth/AuthenticationIntegrationTest.cs +++ b/Common/tests/Auth/AuthenticationIntegrationTest.cs @@ -421,14 +421,16 @@ public static Metadata GetHeaders(IdentityIndex index, headers.Add(AuthenticatorOptions.DefaultAuth.ImpersonationIdHeader, (int)impersonate < 0 ? "DoesntExist" - : Identities[(int)impersonate].UserId); + : Identities[(int)impersonate] + .UserId); } else if (impersonationType == ImpersonationType.ImpersonateUsername) { headers.Add(AuthenticatorOptions.DefaultAuth.ImpersonationUsernameHeader, (int)impersonate < 0 ? "DoesntExist" - : Identities[(int)impersonate].UserName); + : Identities[(int)impersonate] + .UserName); } return headers; @@ -842,13 +844,15 @@ public static IEnumerable GetTestReflectionCases(bool isAsync, ? "Async" : ""), // - The parameter of the method - GetParameters(m.GetParameters()[0].ParameterType, + GetParameters(m.GetParameters()[0] + .ParameterType, clientStream), // - The Request type clientStream ? m.GetParameters()[0] .ParameterType.GetGenericArguments()[0] - : m.GetParameters()[0].ParameterType, + : m.GetParameters()[0] + .ParameterType, // - The Response type serverStream ? m.GetParameters()[1] @@ -1353,7 +1357,8 @@ public async Task AuthServiceShouldGiveUserInfo(CaseParameters parameters, var castedResponse = (GetCurrentUserResponse)response!; // Check if the returned username is correct Assert.AreEqual(options_!.RequireAuthentication - ? Identities[finalUserIndex].UserName + ? Identities[finalUserIndex] + .UserName : "Anonymous", castedResponse.User.Username); // Check if the role list is empty when there is no authorization, otherwise returns the roles diff --git a/Common/tests/Pollster/AgentTest.cs b/Common/tests/Pollster/AgentTest.cs index fe57e1b0f..81363525c 100644 --- a/Common/tests/Pollster/AgentTest.cs +++ b/Common/tests/Pollster/AgentTest.cs @@ -528,7 +528,8 @@ await holder.Agent.FinalizeTaskCreation(CancellationToken.None) Assert.Contains(holder.TaskWithDependencies2, holder.QueueStorage.Messages[Partition]); Assert.AreEqual(2, - holder.QueueStorage.Messages[Partition].Count); + holder.QueueStorage.Messages[Partition] + .Count); var taskData1 = await holder.TaskTable.ReadTaskAsync(holder.TaskWithDependencies1, CancellationToken.None) @@ -719,7 +720,8 @@ await holder.Agent.FinalizeTaskCreation(CancellationToken.None) .ConfigureAwait(false); Assert.AreEqual(3, - holder.QueueStorage.Messages[Partition].Count); + holder.QueueStorage.Messages[Partition] + .Count); taskData3 = await holder.TaskTable.ReadTaskAsync(taskId3, CancellationToken.None) @@ -810,10 +812,13 @@ await holder.Agent.GetResourceData(new DataRequest Assert.AreEqual(3, resourceData.Messages.Count); Assert.AreEqual("Data1", - resourceData.Messages[0].Data.Data); + resourceData.Messages[0] + .Data.Data); Assert.AreEqual("Data2", - resourceData.Messages[1].Data.Data); - Assert.IsTrue(resourceData.Messages[2].Data.DataComplete); + resourceData.Messages[1] + .Data.Data); + Assert.IsTrue(resourceData.Messages[2] + .Data.DataComplete); } [Test] diff --git a/Common/tests/Pollster/DataPrefetcherTest.cs b/Common/tests/Pollster/DataPrefetcherTest.cs index e7eef5b94..54eaacd92 100644 --- a/Common/tests/Pollster/DataPrefetcherTest.cs +++ b/Common/tests/Pollster/DataPrefetcherTest.cs @@ -122,73 +122,101 @@ public async Task EmptyPayloadAndOneDependency() Console.WriteLine(request); } - Assert.AreEqual(computeRequests[0].TypeCase, + Assert.AreEqual(computeRequests[0] + .TypeCase, ProcessRequest.Types.ComputeRequest.TypeOneofCase.InitRequest); - Assert.AreEqual(computeRequests[0].InitRequest.SessionId, + Assert.AreEqual(computeRequests[0] + .InitRequest.SessionId, sessionId); - Assert.AreEqual(computeRequests[0].InitRequest.TaskId, + Assert.AreEqual(computeRequests[0] + .InitRequest.TaskId, taskId); Assert.AreEqual(computeRequests[0] .InitRequest.ExpectedOutputKeys.First(), output1); - Assert.AreEqual(computeRequests[1].TypeCase, + Assert.AreEqual(computeRequests[1] + .TypeCase, ProcessRequest.Types.ComputeRequest.TypeOneofCase.Payload); - Assert.AreEqual(computeRequests[1].Payload.TypeCase, + Assert.AreEqual(computeRequests[1] + .Payload.TypeCase, DataChunk.TypeOneofCase.Data); - Assert.AreEqual(computeRequests[2].TypeCase, + Assert.AreEqual(computeRequests[2] + .TypeCase, ProcessRequest.Types.ComputeRequest.TypeOneofCase.Payload); - Assert.AreEqual(computeRequests[2].Payload.TypeCase, + Assert.AreEqual(computeRequests[2] + .Payload.TypeCase, DataChunk.TypeOneofCase.Data); - Assert.AreEqual(computeRequests[3].TypeCase, + Assert.AreEqual(computeRequests[3] + .TypeCase, ProcessRequest.Types.ComputeRequest.TypeOneofCase.Payload); - Assert.AreEqual(computeRequests[3].Payload.TypeCase, + Assert.AreEqual(computeRequests[3] + .Payload.TypeCase, DataChunk.TypeOneofCase.Data); - Assert.AreEqual(computeRequests[4].TypeCase, + Assert.AreEqual(computeRequests[4] + .TypeCase, ProcessRequest.Types.ComputeRequest.TypeOneofCase.Payload); - Assert.AreEqual(computeRequests[4].Payload.TypeCase, + Assert.AreEqual(computeRequests[4] + .Payload.TypeCase, DataChunk.TypeOneofCase.DataComplete); - Assert.IsTrue(computeRequests[4].Payload.DataComplete); + Assert.IsTrue(computeRequests[4] + .Payload.DataComplete); - Assert.AreEqual(computeRequests[5].TypeCase, + Assert.AreEqual(computeRequests[5] + .TypeCase, ProcessRequest.Types.ComputeRequest.TypeOneofCase.InitData); - Assert.AreEqual(computeRequests[5].InitData.Key, + Assert.AreEqual(computeRequests[5] + .InitData.Key, dependency1); - Assert.AreEqual(computeRequests[6].TypeCase, + Assert.AreEqual(computeRequests[6] + .TypeCase, ProcessRequest.Types.ComputeRequest.TypeOneofCase.Data); - Assert.AreEqual(computeRequests[6].Data.TypeCase, + Assert.AreEqual(computeRequests[6] + .Data.TypeCase, DataChunk.TypeOneofCase.Data); - Assert.AreEqual(computeRequests[7].TypeCase, + Assert.AreEqual(computeRequests[7] + .TypeCase, ProcessRequest.Types.ComputeRequest.TypeOneofCase.Data); - Assert.AreEqual(computeRequests[7].Data.TypeCase, + Assert.AreEqual(computeRequests[7] + .Data.TypeCase, DataChunk.TypeOneofCase.Data); - Assert.AreEqual(computeRequests[8].TypeCase, + Assert.AreEqual(computeRequests[8] + .TypeCase, ProcessRequest.Types.ComputeRequest.TypeOneofCase.Data); - Assert.AreEqual(computeRequests[8].Data.TypeCase, + Assert.AreEqual(computeRequests[8] + .Data.TypeCase, DataChunk.TypeOneofCase.Data); - Assert.AreEqual(computeRequests[9].TypeCase, + Assert.AreEqual(computeRequests[9] + .TypeCase, ProcessRequest.Types.ComputeRequest.TypeOneofCase.Data); - Assert.AreEqual(computeRequests[9].Data.TypeCase, + Assert.AreEqual(computeRequests[9] + .Data.TypeCase, DataChunk.TypeOneofCase.Data); - Assert.AreEqual(computeRequests[10].TypeCase, + Assert.AreEqual(computeRequests[10] + .TypeCase, ProcessRequest.Types.ComputeRequest.TypeOneofCase.Data); - Assert.AreEqual(computeRequests[10].Data.TypeCase, + Assert.AreEqual(computeRequests[10] + .Data.TypeCase, DataChunk.TypeOneofCase.DataComplete); - Assert.IsTrue(computeRequests[10].Data.DataComplete); + Assert.IsTrue(computeRequests[10] + .Data.DataComplete); - Assert.AreEqual(computeRequests[11].TypeCase, + Assert.AreEqual(computeRequests[11] + .TypeCase, ProcessRequest.Types.ComputeRequest.TypeOneofCase.InitData); - Assert.AreEqual(computeRequests[11].InitData.TypeCase, + Assert.AreEqual(computeRequests[11] + .InitData.TypeCase, ProcessRequest.Types.ComputeRequest.Types.InitData.TypeOneofCase.LastData); - Assert.IsTrue(computeRequests[11].InitData.LastData); + Assert.IsTrue(computeRequests[11] + .InitData.LastData); } [Test] diff --git a/Common/tests/Submitter/SubmitterTests.cs b/Common/tests/Submitter/SubmitterTests.cs index 2165e20a5..69a7ae280 100644 --- a/Common/tests/Submitter/SubmitterTests.cs +++ b/Common/tests/Submitter/SubmitterTests.cs @@ -774,12 +774,16 @@ await submitter_.TryGetResult(resultRequest, .ConfigureAwait(false); Assert.AreEqual(ResultReply.TypeOneofCase.Result, - writer.Messages[0].TypeCase); + writer.Messages[0] + .TypeCase); Assert.AreEqual(ResultReply.TypeOneofCase.Result, - writer.Messages[1].TypeCase); + writer.Messages[1] + .TypeCase); Assert.AreEqual(ResultReply.TypeOneofCase.Result, - writer.Messages[2].TypeCase); - Assert.IsTrue(writer.Messages[2].Result.DataComplete); + writer.Messages[2] + .TypeCase); + Assert.IsTrue(writer.Messages[2] + .Result.DataComplete); } [Test] diff --git a/Common/tests/TestBase/AuthenticationTableTestBase.cs b/Common/tests/TestBase/AuthenticationTableTestBase.cs index 31fe0e1a4..819f84bc2 100644 --- a/Common/tests/TestBase/AuthenticationTableTestBase.cs +++ b/Common/tests/TestBase/AuthenticationTableTestBase.cs @@ -99,27 +99,33 @@ static AuthenticationTableTestBase() "User1", new[] { - Roles[0].RoleId, + Roles[0] + .RoleId, }), new("UserId2".ToOidString(), "User2", new[] { - Roles[0].RoleId, - Roles[1].RoleId, + Roles[0] + .RoleId, + Roles[1] + .RoleId, }), new("UserId3".ToOidString(), "User3", new[] { - Roles[0].RoleId, - Roles[2].RoleId, + Roles[0] + .RoleId, + Roles[2] + .RoleId, }), new("UserId4".ToOidString(), "User4", new[] { - Roles[0].RoleId, + Roles[0] + .RoleId, "RoleIdDontExist".ToOidString(), }), new("UserId5".ToOidString(), @@ -129,23 +135,28 @@ static AuthenticationTableTestBase() Auths = new List { new("AuthId1".ToOidString(), - Users[0].UserId, + Users[0] + .UserId, "CNUser1", "Fingerprint1"), new("AuthId2".ToOidString(), - Users[1].UserId, + Users[1] + .UserId, "CNUser2", "Fingerprint2"), new("AuthId3".ToOidString(), - Users[1].UserId, + Users[1] + .UserId, "CNUser3", "Fingerprint3"), new("AuthId4".ToOidString(), - Users[2].UserId, + Users[2] + .UserId, "CNUser4", "Fingerprint4"), new("AuthId5".ToOidString(), - Users[3].UserId, + Users[3] + .UserId, "CNUser5", "Fingerprint5"), new("AuthId6".ToOidString(), @@ -153,15 +164,18 @@ static AuthenticationTableTestBase() "CNUser6", "Fingerprint6"), new("AuthId7".ToOidString(), - Users[1].UserId, + Users[1] + .UserId, "CNUser2", "Fingerprint7"), new("AuthId8".ToOidString(), - Users[2].UserId, + Users[2] + .UserId, "CNUserCommon", null), new("AuthId9".ToOidString(), - Users[3].UserId, + Users[3] + .UserId, "CNUser2", null), }; @@ -256,7 +270,8 @@ public void GetIdentityFromCnAndFingerprintShouldSucceed(string cn, CancellationToken.None) .Result; Assert.NotNull(ident); - Assert.AreEqual(Users[userid].UserId, + Assert.AreEqual(Users[userid] + .UserId, ident!.Id); } @@ -290,11 +305,13 @@ public void GetIdentityFromIdShouldSucceed(int id, return; } - var ident = AuthenticationTable!.GetIdentityFromUserAsync(Users[id].UserId, + var ident = AuthenticationTable!.GetIdentityFromUserAsync(Users[id] + .UserId, null) .Result; Assert.NotNull(ident); - Assert.AreEqual(Users[id].UserId, + Assert.AreEqual(Users[id] + .UserId, ident!.Id); Assert.AreEqual(username, ident.Username); @@ -331,7 +348,8 @@ public void GetIdentityFromNameShouldSucceed(string name, Assert.NotNull(identity); Assert.AreEqual(name, identity!.Username); - Assert.AreEqual(Users[id].UserId, + Assert.AreEqual(Users[id] + .UserId, identity.Id); } diff --git a/Tests/Stream/Client/StreamWrapperTests.cs b/Tests/Stream/Client/StreamWrapperTests.cs index 51ddb3fb1..4d82035fa 100644 --- a/Tests/Stream/Client/StreamWrapperTests.cs +++ b/Tests/Stream/Client/StreamWrapperTests.cs @@ -259,7 +259,8 @@ public async Task TaskFailed() Payload = ByteString.CopyFrom(payload.Serialize()), ExpectedOutputKeys = { - results.Results[i].ResultId, + results.Results[i] + .ResultId, }, }; taskRequests.Add(req); @@ -323,7 +324,8 @@ public async Task MultipleTasks([Values(4, { Type = taskType, DataBytes = BitConverter.GetBytes(i), - ResultKey = results.Results[i].ResultId, + ResultKey = results.Results[i] + .ResultId, }; var req = new TaskRequest @@ -331,7 +333,8 @@ public async Task MultipleTasks([Values(4, Payload = ByteString.CopyFrom(payload.Serialize()), ExpectedOutputKeys = { - results.Results[i].ResultId, + results.Results[i] + .ResultId, }, }; taskRequestList.Add(req); @@ -411,10 +414,12 @@ public async Task MultipleDataDependencies([Values(1, { var payload = new TestPayload { - Type = TestPayload.TaskType.DatadepTransfer, - DataBytes = BitConverter.GetBytes(i + 5), - ResultKey = resultsMetaData.Results[2 * i].ResultId, - ResultKey2 = resultsMetaData.Results[2 * i + 1].ResultId, + Type = TestPayload.TaskType.DatadepTransfer, + DataBytes = BitConverter.GetBytes(i + 5), + ResultKey = resultsMetaData.Results[2 * i] + .ResultId, + ResultKey2 = resultsMetaData.Results[2 * i + 1] + .ResultId, }; var req = new TaskRequest @@ -422,8 +427,10 @@ public async Task MultipleDataDependencies([Values(1, Payload = ByteString.CopyFrom(payload.Serialize()), ExpectedOutputKeys = { - resultsMetaData.Results[2 * i].ResultId, - resultsMetaData.Results[2 * i + 1].ResultId, + resultsMetaData.Results[2 * i] + .ResultId, + resultsMetaData.Results[2 * i + 1] + .ResultId, }, }; taskRequestList.Add(req); @@ -538,7 +545,8 @@ public async Task LargePayloads([Values(2, Payload = byteString, ExpectedOutputKeys = { - resultsMetaData.Results[i].ResultId, + resultsMetaData.Results[i] + .ResultId, }, }; @@ -700,7 +708,8 @@ private async Task RunForPriority(string sessionId, { Type = TestPayload.TaskType.Compute, DataBytes = BitConverter.GetBytes(1), - ResultKey = resultsMetaData.Results[i].ResultId, + ResultKey = resultsMetaData.Results[i] + .ResultId, }; var req = new TaskRequest @@ -708,7 +717,8 @@ private async Task RunForPriority(string sessionId, Payload = ByteString.CopyFrom(payload.Serialize()), ExpectedOutputKeys = { - resultsMetaData.Results[i].ResultId, + resultsMetaData.Results[i] + .ResultId, }, }; From 39620e34e7a944bce9d59fa880d9b33a1429f27a Mon Sep 17 00:00:00 2001 From: wkirschenmann Date: Fri, 11 Aug 2023 09:39:02 +0200 Subject: [PATCH 12/21] Update Common/tests/Pollster/PollsterTest.cs Co-authored-by: lemaitre-aneo <91961298+lemaitre-aneo@users.noreply.github.com> --- Common/tests/Pollster/PollsterTest.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Common/tests/Pollster/PollsterTest.cs b/Common/tests/Pollster/PollsterTest.cs index 9f8367fac..be9da9a37 100644 --- a/Common/tests/Pollster/PollsterTest.cs +++ b/Common/tests/Pollster/PollsterTest.cs @@ -441,7 +441,7 @@ public WaitAsyncPipe(double delay) public async Task ReadAsync(CancellationToken cancellationToken) { await Task.Delay(TimeSpan.FromMilliseconds(delay_), - cancellationToken) + CancellationToken.None) .ConfigureAwait(false); return new ProcessReply { From 1f22b22a627fd7f2fad45d646ba29f46c2afd393 Mon Sep 17 00:00:00 2001 From: wkirschenmann Date: Fri, 11 Aug 2023 09:44:47 +0200 Subject: [PATCH 13/21] Update Common/tests/Helpers/SimplePullQueueStorage.cs Co-authored-by: lemaitre-aneo <91961298+lemaitre-aneo@users.noreply.github.com> --- Common/tests/Helpers/SimplePullQueueStorage.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Common/tests/Helpers/SimplePullQueueStorage.cs b/Common/tests/Helpers/SimplePullQueueStorage.cs index 4fdf0ff9c..e7e63ab61 100644 --- a/Common/tests/Helpers/SimplePullQueueStorage.cs +++ b/Common/tests/Helpers/SimplePullQueueStorage.cs @@ -46,7 +46,7 @@ public int MaxPriority public IAsyncEnumerable PullMessagesAsync(int nbMessages, CancellationToken cancellationToken = default) // using ToAsyncEnumerable avoids using an async function needlessly - => Enumerable.Repeat(0, + => Enumerable.Repeat(new ValueTuple(), nbMessages) .Select(_ => { From 220ff4dea1b3b869b5892f92c53f9c8bddc82b86 Mon Sep 17 00:00:00 2001 From: wkirschenmann Date: Fri, 11 Aug 2023 09:45:18 +0200 Subject: [PATCH 14/21] Update Adaptors/MongoDB/src/IMongoQueryableExt.cs Co-authored-by: lemaitre-aneo <91961298+lemaitre-aneo@users.noreply.github.com> --- Adaptors/MongoDB/src/IMongoQueryableExt.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Adaptors/MongoDB/src/IMongoQueryableExt.cs b/Adaptors/MongoDB/src/IMongoQueryableExt.cs index 852b395e2..99274af2f 100644 --- a/Adaptors/MongoDB/src/IMongoQueryableExt.cs +++ b/Adaptors/MongoDB/src/IMongoQueryableExt.cs @@ -46,7 +46,7 @@ public static async IAsyncEnumerable ToAsyncEnumerable(this } - public static async IAsyncEnumerable ToAsyncEnumerable(this IFindFluent findFluent, + public static async IAsyncEnumerable ToAsyncEnumerable(this IFindFluent findFluent, [EnumeratorCancellation] CancellationToken cancellationToken = default) { var cursor = await findFluent.ToCursorAsync(cancellationToken) From 10ad2f037d756d848d705e63e4b1c6f6f15f58d7 Mon Sep 17 00:00:00 2001 From: wkirschenmann Date: Fri, 11 Aug 2023 09:48:09 +0200 Subject: [PATCH 15/21] Update Adaptors/S3/src/ObjectStorage.cs Co-authored-by: lemaitre-aneo <91961298+lemaitre-aneo@users.noreply.github.com> --- Adaptors/S3/src/ObjectStorage.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Adaptors/S3/src/ObjectStorage.cs b/Adaptors/S3/src/ObjectStorage.cs index d2d68a149..23ace2a3b 100644 --- a/Adaptors/S3/src/ObjectStorage.cs +++ b/Adaptors/S3/src/ObjectStorage.cs @@ -281,7 +281,7 @@ internal static async Task StringByteGetAsync(this AmazonS3Client s3Clie await using var responseStream = response.ResponseStream; var retrievedData = new byte[responseStream.Length]; - _ = await responseStream.ReadAsync(new Memory(retrievedData), + _ = await responseStream.ReadAsync(retrievedData, cancellationToken); return Encoding.UTF8.GetString(retrievedData); } From 96a2632fc2d21cd74b1de62978daa74e43bf9170 Mon Sep 17 00:00:00 2001 From: wkirschenmann Date: Fri, 11 Aug 2023 10:10:16 +0200 Subject: [PATCH 16/21] Update TaskHandler.cs --- Common/src/Pollster/TaskHandler.cs | 20 +++++++------------- 1 file changed, 7 insertions(+), 13 deletions(-) diff --git a/Common/src/Pollster/TaskHandler.cs b/Common/src/Pollster/TaskHandler.cs index b90fc1aee..d6e0e3c7a 100644 --- a/Common/src/Pollster/TaskHandler.cs +++ b/Common/src/Pollster/TaskHandler.cs @@ -647,19 +647,7 @@ await taskTable_.ReleaseTask(taskData, } else { - if (resubmit) - { - logger_.LogError(e, - "Error during task execution, retrying task"); - messageHandler_.Status = QueueMessageStatus.Cancelled; - } - else - { - logger_.LogError(e, - "Error during task execution, cancelling task"); - messageHandler_.Status = QueueMessageStatus.Processed; - } - + logger_.LogError(e, "Error during task execution: {Decision}", resubmit ? "retrying task" : "cancelling task"); await submitter_.CompleteTaskAsync(taskData, resubmit, @@ -672,6 +660,12 @@ await submitter_.CompleteTaskAsync(taskData, }, CancellationToken.None) .ConfigureAwait(false); + + + messageHandler_.Status = resubmit + ? QueueMessageStatus.Cancelled + : QueueMessageStatus.Processed; + } } From 68e0f9751e17eaab242d899e93e2e7d72786872d Mon Sep 17 00:00:00 2001 From: wkirschenmann Date: Fri, 11 Aug 2023 10:14:03 +0200 Subject: [PATCH 17/21] Add message in WorkerStreamHandler.cs --- Common/src/Stream/Worker/WorkerStreamHandler.cs | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/Common/src/Stream/Worker/WorkerStreamHandler.cs b/Common/src/Stream/Worker/WorkerStreamHandler.cs index fb953f47c..a20d308cd 100644 --- a/Common/src/Stream/Worker/WorkerStreamHandler.cs +++ b/Common/src/Stream/Worker/WorkerStreamHandler.cs @@ -115,9 +115,7 @@ await Task.Delay(optionsInitWorker_.WorkerCheckDelay * retry, var e = new ArmoniKException("Could not get grpc channel"); logger_.LogError(e, -#pragma warning disable CA2254 // string.Empty is constant - string.Empty); -#pragma warning restore CA2254 + "Could not get grpc channel"); throw e; } From 687973944898877df5515ff63712303938df68c2 Mon Sep 17 00:00:00 2001 From: wkirschenmann Date: Fri, 11 Aug 2023 11:27:47 +0200 Subject: [PATCH 18/21] Correct format in IMongoQueryableExt --- Adaptors/MongoDB/src/IMongoQueryableExt.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Adaptors/MongoDB/src/IMongoQueryableExt.cs b/Adaptors/MongoDB/src/IMongoQueryableExt.cs index 99274af2f..1c28b046f 100644 --- a/Adaptors/MongoDB/src/IMongoQueryableExt.cs +++ b/Adaptors/MongoDB/src/IMongoQueryableExt.cs @@ -47,7 +47,7 @@ public static async IAsyncEnumerable ToAsyncEnumerable(this public static async IAsyncEnumerable ToAsyncEnumerable(this IFindFluent findFluent, - [EnumeratorCancellation] CancellationToken cancellationToken = default) + [EnumeratorCancellation] CancellationToken cancellationToken = default) { var cursor = await findFluent.ToCursorAsync(cancellationToken) .ConfigureAwait(false); From 489314f11bd5229ab9412481570a934989729a33 Mon Sep 17 00:00:00 2001 From: wkirschenmann Date: Fri, 11 Aug 2023 11:28:51 +0200 Subject: [PATCH 19/21] Clean code --- Base/src/QueueMessageStatus.cs | 34 +++++++++++++++++++++- Common/src/Pollster/TaskHandler.cs | 7 +++-- Common/src/gRPC/ListSessionsRequestExt.cs | 2 +- Tests/Stream/Client/TaskSubmissionTests.cs | 2 ++ 4 files changed, 41 insertions(+), 4 deletions(-) diff --git a/Base/src/QueueMessageStatus.cs b/Base/src/QueueMessageStatus.cs index 54db212e5..812a09da8 100644 --- a/Base/src/QueueMessageStatus.cs +++ b/Base/src/QueueMessageStatus.cs @@ -1,4 +1,4 @@ -// This file is part of the ArmoniK project +// This file is part of the ArmoniK project // // Copyright (C) ANEO, 2021-2023. All rights reserved. // @@ -15,15 +15,47 @@ // You should have received a copy of the GNU Affero General Public License // along with this program. If not, see . +using System; + namespace ArmoniK.Core.Base; +/// +/// Represents the status of a queue message +/// public enum QueueMessageStatus { + /// + /// Message is waiting for being processed. + /// Waiting, + + /// + /// Message processing has failed. The message should be put back at the begin of the queue. + /// Failed, + + /// + /// The message is being processed. + /// Running, + + /// + /// Task is not ready to be processed. The message should be put at the end of the queue. + /// Postponed, + + /// + /// The message has been processed. It can safely be removed from the queue. + /// Processed, + + /// + /// The message processing has been cancelled. the message can safely be removed from the queue. + /// Cancelled, + + /// + /// Message has been retried too many times and is considered as poisonous for the queue + /// Poisonous, } diff --git a/Common/src/Pollster/TaskHandler.cs b/Common/src/Pollster/TaskHandler.cs index d6e0e3c7a..7d0b1b1dd 100644 --- a/Common/src/Pollster/TaskHandler.cs +++ b/Common/src/Pollster/TaskHandler.cs @@ -647,7 +647,11 @@ await taskTable_.ReleaseTask(taskData, } else { - logger_.LogError(e, "Error during task execution: {Decision}", resubmit ? "retrying task" : "cancelling task"); + logger_.LogError(e, + "Error during task execution: {Decision}", + resubmit + ? "retrying task" + : "cancelling task"); await submitter_.CompleteTaskAsync(taskData, resubmit, @@ -665,7 +669,6 @@ await submitter_.CompleteTaskAsync(taskData, messageHandler_.Status = resubmit ? QueueMessageStatus.Cancelled : QueueMessageStatus.Processed; - } } diff --git a/Common/src/gRPC/ListSessionsRequestExt.cs b/Common/src/gRPC/ListSessionsRequestExt.cs index 3c23a8a15..96e9b9db5 100644 --- a/Common/src/gRPC/ListSessionsRequestExt.cs +++ b/Common/src/gRPC/ListSessionsRequestExt.cs @@ -64,7 +64,7 @@ public static class ListSessionsRequestExt /// the given message is not recognized [SuppressMessage("Style", "IDE0066:Convert switch statement to expression", - Justification = "Readibility for nested switch")] + Justification = "Readability for nested switch")] public static Expression> ToSessionDataFilter(this Filters filters) { Expression> expr = data => false; diff --git a/Tests/Stream/Client/TaskSubmissionTests.cs b/Tests/Stream/Client/TaskSubmissionTests.cs index 3f575d53b..02b64c22d 100644 --- a/Tests/Stream/Client/TaskSubmissionTests.cs +++ b/Tests/Stream/Client/TaskSubmissionTests.cs @@ -269,7 +269,9 @@ public async Task SubmitTasksShouldSucceed() TaskStatus.Processing, }); +#pragma warning disable CS0612 // Type or member is obsolete await submitterClient.WaitForAvailabilityAsync(new ResultRequest +#pragma warning restore CS0612 // Type or member is obsolete { ResultId = results.Results.Single() .ResultId, From f81f4886945b33701b44747b140498c1b63bf00e Mon Sep 17 00:00:00 2001 From: wkirschenmann Date: Fri, 11 Aug 2023 11:45:43 +0200 Subject: [PATCH 20/21] Add arguments for creation of all ArgumentOutOfRangeException --- Common/src/gRPC/Services/Agent.cs | 14 +++++----- Common/src/gRPC/Services/Submitter.cs | 6 ++-- Tests/Stream/Client/SubmitterExt.cs | 2 +- Tests/Stream/Server/WorkerService.cs | 40 ++++++++++++--------------- 4 files changed, 29 insertions(+), 33 deletions(-) diff --git a/Common/src/gRPC/Services/Agent.cs b/Common/src/gRPC/Services/Agent.cs index 1db7530fa..440abacf0 100644 --- a/Common/src/gRPC/Services/Agent.cs +++ b/Common/src/gRPC/Services/Agent.cs @@ -312,7 +312,7 @@ await taskRequestsChannel.Writer.WriteAsync(new TaskRequest(request.InitTask.Hea { currentTasks!.Select(_ => new CreateTaskReply.Types.CreationStatus { - Error = "An error occured during task creation", + Error = "An error occurred during task creation", }), }, }, @@ -321,7 +321,7 @@ await taskRequestsChannel.Writer.WriteAsync(new TaskRequest(request.InitTask.Hea case InitTaskRequest.TypeOneofCase.None: default: - throw new ArgumentOutOfRangeException(); + throw new ArgumentOutOfRangeException(nameof(InitTaskRequest.TypeOneofCase.LastTask)); } break; @@ -342,13 +342,13 @@ await taskRequestsChannel.Writer.WriteAsync(new TaskRequest(request.InitTask.Hea break; case DataChunk.TypeOneofCase.None: default: - throw new ArgumentOutOfRangeException(); + throw new ArgumentOutOfRangeException(nameof(request.TaskPayload.TypeCase)); } break; case CreateTaskRequest.TypeOneofCase.None: default: - throw new ArgumentOutOfRangeException(); + throw new ArgumentOutOfRangeException(nameof(CreateTaskRequest.TypeOneofCase.InitTask)); } } @@ -589,7 +589,7 @@ await completionTask.WaitAsync(cancellationToken) case InitKeyedDataStream.TypeOneofCase.None: default: - throw new ArgumentOutOfRangeException(); + throw new ArgumentOutOfRangeException(nameof(request.Init.TypeCase)); } break; @@ -609,13 +609,13 @@ await chunksChannel.Writer.WriteAsync(request.Data.Data.Memory, case DataChunk.TypeOneofCase.None: default: - throw new ArgumentOutOfRangeException(); + throw new ArgumentOutOfRangeException(nameof(request.Data.TypeCase)); } break; case Result.TypeOneofCase.None: default: - throw new ArgumentOutOfRangeException(); + throw new ArgumentOutOfRangeException(nameof(request.TypeCase)); } } diff --git a/Common/src/gRPC/Services/Submitter.cs b/Common/src/gRPC/Services/Submitter.cs index 19df2449e..8e5cc4e95 100644 --- a/Common/src/gRPC/Services/Submitter.cs +++ b/Common/src/gRPC/Services/Submitter.cs @@ -236,9 +236,10 @@ await responseStream.WriteAsync(new ResultReply .ConfigureAwait(false); return; + case TaskStatus.Retried: // TODO: If this case is not used, maybe remove it completely? case TaskStatus.Unspecified: default: - throw new ArgumentOutOfRangeException(); + throw new ArgumentOutOfRangeException(nameof(taskData.Status)); } } @@ -505,8 +506,9 @@ public async Task WaitForAvailabilityAsync(ResultRequest }, }; case ResultStatus.Unspecified: + case ResultStatus.Notfound: // TODO: define a specific error type ? default: - throw new ArgumentOutOfRangeException(); + throw new ArgumentOutOfRangeException(nameof(result.Status)); } await Task.Delay(currentPollingDelay, diff --git a/Tests/Stream/Client/SubmitterExt.cs b/Tests/Stream/Client/SubmitterExt.cs index 352ad4af0..5a6bd985a 100644 --- a/Tests/Stream/Client/SubmitterExt.cs +++ b/Tests/Stream/Client/SubmitterExt.cs @@ -72,7 +72,7 @@ public static async Task> CreateTasksAndCheckReplyAsync(this CreateTaskReply.ResponseOneofCase.None => throw new Exception("Issue with Server !"), CreateTaskReply.ResponseOneofCase.CreationStatusList => createTaskReply.CreationStatusList.CreationStatuses.Select(StatusToString), CreateTaskReply.ResponseOneofCase.Error => throw new Exception("Error : " + createTaskReply.Error), - _ => throw new ArgumentOutOfRangeException(), + _ => throw new ArgumentOutOfRangeException(nameof(createTaskReply.ResponseCase)), }; } diff --git a/Tests/Stream/Server/WorkerService.cs b/Tests/Stream/Server/WorkerService.cs index 31ec169bc..d8e1b16f1 100644 --- a/Tests/Stream/Server/WorkerService.cs +++ b/Tests/Stream/Server/WorkerService.cs @@ -126,11 +126,10 @@ await taskHandler.CreateTasksAsync(new[] break; case TestPayload.TaskType.DatadepTransfer: { - var taskId = "DataDepTransfer-" + Guid.NewGuid(); - TaskRequest req; + var taskId = "DataDepTransfer-" + Guid.NewGuid(); if (taskHandler.ExpectedResults.Count != 2) { - throw new ArgumentOutOfRangeException(); + throw new ArgumentOutOfRangeException(nameof(payload.Type)); } var resId = taskHandler.ExpectedResults.First(); @@ -139,18 +138,18 @@ await taskHandler.CreateTasksAsync(new[] payload.Type = TestPayload.TaskType.DatadepCompute; - req = new TaskRequest - { - Payload = ByteString.CopyFrom(payload.Serialize()), - ExpectedOutputKeys = - { - resId, - }, - DataDependencies = - { - depId, - }, - }; + var req = new TaskRequest + { + Payload = ByteString.CopyFrom(payload.Serialize()), + ExpectedOutputKeys = + { + resId, + }, + DataDependencies = + { + depId, + }, + }; logger_.LogDebug("DataDepTransfer Input {input}", input); @@ -179,14 +178,9 @@ await taskHandler.CreateTasksAsync(new[] break; case TestPayload.TaskType.DatadepCompute: { - if (taskHandler.ExpectedResults.Count != 1) - { - throw new ArgumentOutOfRangeException(); - } - - if (taskHandler.DataDependencies.Count != 1) + if (taskHandler.ExpectedResults.Count != 1 || taskHandler.DataDependencies.Count != 1) { - throw new ArgumentOutOfRangeException(); + throw new ArgumentOutOfRangeException(nameof(payload.Type)); } var resId = taskHandler.ExpectedResults.First(); @@ -247,7 +241,7 @@ await taskHandler.SendResult(taskHandler.ExpectedResults.Single(), }; break; default: - throw new ArgumentOutOfRangeException(); + throw new ArgumentOutOfRangeException(nameof(payload.Type)); } } } From e582dc0997c0b79671a3fec998d6cb7f75a054ae Mon Sep 17 00:00:00 2001 From: wkirschenmann Date: Fri, 11 Aug 2023 11:48:54 +0200 Subject: [PATCH 21/21] Apply format patch. --- Base/src/QueueMessageStatus.cs | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/Base/src/QueueMessageStatus.cs b/Base/src/QueueMessageStatus.cs index 812a09da8..0b8d64ebb 100644 --- a/Base/src/QueueMessageStatus.cs +++ b/Base/src/QueueMessageStatus.cs @@ -15,47 +15,45 @@ // You should have received a copy of the GNU Affero General Public License // along with this program. If not, see . -using System; - namespace ArmoniK.Core.Base; /// -/// Represents the status of a queue message +/// Represents the status of a queue message /// public enum QueueMessageStatus { /// - /// Message is waiting for being processed. + /// Message is waiting for being processed. /// Waiting, /// - /// Message processing has failed. The message should be put back at the begin of the queue. + /// Message processing has failed. The message should be put back at the begin of the queue. /// Failed, /// - /// The message is being processed. + /// The message is being processed. /// Running, /// - /// Task is not ready to be processed. The message should be put at the end of the queue. + /// Task is not ready to be processed. The message should be put at the end of the queue. /// Postponed, /// - /// The message has been processed. It can safely be removed from the queue. + /// The message has been processed. It can safely be removed from the queue. /// Processed, /// - /// The message processing has been cancelled. the message can safely be removed from the queue. + /// The message processing has been cancelled. the message can safely be removed from the queue. /// Cancelled, /// - /// Message has been retried too many times and is considered as poisonous for the queue + /// Message has been retried too many times and is considered as poisonous for the queue /// Poisonous, }