From 7f9f55674582c8a3f0d5bd70ac06295827e5cd2d Mon Sep 17 00:00:00 2001 From: tr00d Date: Mon, 8 Apr 2024 09:50:46 +0200 Subject: [PATCH] fix: disable parallelization for connection lifetime tests using NonThreadSafeCollection --- Vonage.Test/ConfigurationTest.cs | 17 ++--------------- Vonage.Test/NonThreadSafeCollection.cs | 8 ++++++++ 2 files changed, 10 insertions(+), 15 deletions(-) create mode 100644 Vonage.Test/NonThreadSafeCollection.cs diff --git a/Vonage.Test/ConfigurationTest.cs b/Vonage.Test/ConfigurationTest.cs index 3934016a..c401a394 100644 --- a/Vonage.Test/ConfigurationTest.cs +++ b/Vonage.Test/ConfigurationTest.cs @@ -11,7 +11,6 @@ using Vonage.Test.TestHelpers; using WireMock.ResponseBuilders; using Xunit; -using Xunit.Abstractions; namespace Vonage.Test; @@ -210,13 +209,9 @@ public void VonageUrl_ShouldReturnNexmoUrl() => } [Trait("Category", "HttpConnectionPool")] -[CollectionDefinition("HttpConnectionPool", DisableParallelization = true)] +[Collection(nameof(NonThreadSafeCollection))] public class ConnectionLifetimeTest { - private readonly ITestOutputHelper output; - - public ConnectionLifetimeTest(ITestOutputHelper output) => this.output = output; - [Theory] [InlineData(5, 2, 1)] [InlineData(5, 5, 2)] @@ -248,7 +243,7 @@ public async Task ShouldRenewConnection_GivenIdleTimeoutHasExpired() private async Task RefreshConnectionPool(Dictionary settings, int timerBuffer, int loops) { - using var spy = new EventSpy(this.output); + using var spy = new EventSpy(); var helper = TestingContext.WithBasicCredentials("Url.Rest", settings); helper.Server.Given(WireMock.RequestBuilders.Request.Create().UsingGet()) .RespondWith(Response.Create().WithStatusCode(HttpStatusCode.OK)); @@ -266,10 +261,6 @@ private async Task RefreshConnectionPool(Dictionary setting internal class EventSpy : EventListener { - private readonly ITestOutputHelper output; - - public EventSpy(ITestOutputHelper output) => this.output = output; - public int RefreshedConnections { get; private set; } public int ReceivedRequests { get; private set; } @@ -288,13 +279,9 @@ protected override void OnEventWritten(EventWrittenEventArgs eventData) { case "ResolutionStart": this.RefreshedConnections++; - this.output.WriteLine($"[{this.RefreshedConnections}] - " + eventData.EventName + " - " + - DateTime.Now.TimeOfDay); break; case "RequestStart": this.ReceivedRequests++; - this.output.WriteLine($"[{this.ReceivedRequests}] - " + eventData.EventName + " - " + - DateTime.Now.TimeOfDay); break; } } diff --git a/Vonage.Test/NonThreadSafeCollection.cs b/Vonage.Test/NonThreadSafeCollection.cs new file mode 100644 index 00000000..efa594c0 --- /dev/null +++ b/Vonage.Test/NonThreadSafeCollection.cs @@ -0,0 +1,8 @@ +using Xunit; + +namespace Vonage.Test; + +[CollectionDefinition(nameof(NonThreadSafeCollection), DisableParallelization = true)] +public class NonThreadSafeCollection +{ +} \ No newline at end of file