From 85affe5ff9597ef5946c64de537d5eafd8f6b450 Mon Sep 17 00:00:00 2001 From: SebastienDegodez Date: Sun, 22 Dec 2024 00:28:51 +0100 Subject: [PATCH] fix: failed goodmessage Signed-off-by: SebastienDegodez --- src/Microcks.Testcontainers/MicrocksBuilder.cs | 10 ++++++++-- .../MicrocksContainerExtensions.cs | 10 +++++++++- .../Async/Kafka/KafkaCollection.cs | 18 ++++++++++++++++++ .../MicrocksAsyncKafkaFunctionalityTest.cs | 6 ++++++ .../Microcks.Testcontainers.Tests.csproj | 2 +- 5 files changed, 42 insertions(+), 4 deletions(-) create mode 100644 tests/Microcks.Testcontainers.Tests/Async/Kafka/KafkaCollection.cs diff --git a/src/Microcks.Testcontainers/MicrocksBuilder.cs b/src/Microcks.Testcontainers/MicrocksBuilder.cs index e996690..c852210 100644 --- a/src/Microcks.Testcontainers/MicrocksBuilder.cs +++ b/src/Microcks.Testcontainers/MicrocksBuilder.cs @@ -5,7 +5,7 @@ // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // -// http://www.apache.org/licenses/LICENSE-2.0 +// http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, @@ -85,7 +85,8 @@ private void ContainerStarted(MicrocksContainer container) if (_mainRemoteArtifacts != null && _mainRemoteArtifacts.Any()) { - _mainRemoteArtifacts.ForEach(remoteArtifactUrl => container.DownloadArtifactAsync(remoteArtifactUrl, main: true).GetAwaiter().GetResult()); + _mainRemoteArtifacts.ForEach(remoteArtifactUrl => + container.DownloadArtifactAsync(remoteArtifactUrl, main: true).GetAwaiter().GetResult()); } if (_mainArtifacts != null && _mainArtifacts.Any()) @@ -148,6 +149,7 @@ public MicrocksBuilder WithSnapshots(params string[] snapshots) { _snapshots.AddRange(snapshots); } + return this; } @@ -166,6 +168,7 @@ public MicrocksBuilder WithMainRemoteArtifacts(params string[] urls) { _mainRemoteArtifacts.AddRange(urls); } + return this; } @@ -184,6 +187,7 @@ public MicrocksBuilder WithMainArtifacts(params string[] mainArtifacts) { _mainArtifacts.AddRange(mainArtifacts); } + return this; } @@ -202,6 +206,7 @@ public MicrocksBuilder WithSecondaryArtifacts(params string[] secondaryArtifacts { _secondaryArtifacts.AddRange(secondaryArtifacts); } + return this; } @@ -220,6 +225,7 @@ public MicrocksBuilder WithSecret(params Model.Secret[] secrets) { _secrets.AddRange(secrets); } + return this; } } diff --git a/src/Microcks.Testcontainers/MicrocksContainerExtensions.cs b/src/Microcks.Testcontainers/MicrocksContainerExtensions.cs index 106ea31..aac6914 100644 --- a/src/Microcks.Testcontainers/MicrocksContainerExtensions.cs +++ b/src/Microcks.Testcontainers/MicrocksContainerExtensions.cs @@ -71,7 +71,15 @@ public static async Task TestEndpointAsync( try { - await WaitForConditionAsync(async () => !(await RefreshTestResultAsync(httpEndpoint, testResultId)).InProgress, + await WaitForConditionAsync( + async () => + { + container.Logger.LogInformation("Polling test result {TestResultId} for completion", testResultId); + var testResult = await RefreshTestResultAsync(httpEndpoint, testResultId); + var notInProgress = !testResult.InProgress; + container.Logger.LogInformation("Test result {TestResultId} is not in progress: {NotInProgress}", testResultId, notInProgress); + return notInProgress; + }, atMost: TimeSpan.FromMilliseconds(1000).Add(testRequest.Timeout), delay: TimeSpan.FromMilliseconds(100), interval: TimeSpan.FromMilliseconds(200)); diff --git a/tests/Microcks.Testcontainers.Tests/Async/Kafka/KafkaCollection.cs b/tests/Microcks.Testcontainers.Tests/Async/Kafka/KafkaCollection.cs new file mode 100644 index 0000000..91b5591 --- /dev/null +++ b/tests/Microcks.Testcontainers.Tests/Async/Kafka/KafkaCollection.cs @@ -0,0 +1,18 @@ +// Copyright The Microcks Authors. +// +// Licensed under the Apache License, Version 2.0 (the "License") +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +namespace Microcks.Testcontainers.Tests.Async.Kafka; + +[CollectionDefinition(nameof(KafkaCollection), DisableParallelization = true)] +public class KafkaCollection { } diff --git a/tests/Microcks.Testcontainers.Tests/Async/Kafka/MicrocksAsyncKafkaFunctionalityTest.cs b/tests/Microcks.Testcontainers.Tests/Async/Kafka/MicrocksAsyncKafkaFunctionalityTest.cs index 68badc0..b59398c 100644 --- a/tests/Microcks.Testcontainers.Tests/Async/Kafka/MicrocksAsyncKafkaFunctionalityTest.cs +++ b/tests/Microcks.Testcontainers.Tests/Async/Kafka/MicrocksAsyncKafkaFunctionalityTest.cs @@ -24,10 +24,12 @@ using FluentAssertions; using Microcks.Testcontainers.Connection; using Microcks.Testcontainers.Model; +using Microsoft.Extensions.Logging; using Testcontainers.Kafka; namespace Microcks.Testcontainers.Tests.Async.Kafka; +[Collection(nameof(KafkaCollection))] public sealed class MicrocksAsyncKafkaFunctionalityTest : IAsyncLifetime { /// @@ -132,10 +134,12 @@ public async Task ShouldReturnsCorrectStatusContractWhenGoodMessageIsEmitted() .SetValueSerializer(Serializers.Utf8) .SetErrorHandler((_, e) => { + this._kafkaContainer.Logger.LogError("Error: {Reason}", e.Reason); Debug.WriteLine($"Error: {e.Reason}"); }) .SetLogHandler((_, logMessage) => { + this._kafkaContainer.Logger.LogInformation("{Name} sending {Message}", logMessage.Name, logMessage.Message); Debug.WriteLine($"{logMessage.Name} sending {logMessage.Message}"); }) .Build(); @@ -202,10 +206,12 @@ public async Task ShouldReturnsCorrectStatusContractWhenBadMessageIsEmitted() .SetValueSerializer(Serializers.Utf8) .SetErrorHandler((_, e) => { + this._kafkaContainer.Logger.LogError("Error: {Reason}", e.Reason); Debug.WriteLine($"Error: {e.Reason}"); }) .SetLogHandler((_, logMessage) => { + this._kafkaContainer.Logger.LogInformation("{Name} sending {Message}", logMessage.Name, logMessage.Message); Debug.WriteLine($"{logMessage.Name} sending {logMessage.Message}"); }) .Build(); diff --git a/tests/Microcks.Testcontainers.Tests/Microcks.Testcontainers.Tests.csproj b/tests/Microcks.Testcontainers.Tests/Microcks.Testcontainers.Tests.csproj index ecaaf9d..82a644e 100644 --- a/tests/Microcks.Testcontainers.Tests/Microcks.Testcontainers.Tests.csproj +++ b/tests/Microcks.Testcontainers.Tests/Microcks.Testcontainers.Tests.csproj @@ -35,4 +35,4 @@ PreserveNewest - \ No newline at end of file +