Skip to content

Commit

Permalink
fix: disable parallelization for connection lifetime tests using NonT…
Browse files Browse the repository at this point in the history
…hreadSafeCollection
  • Loading branch information
Tr00d committed Apr 8, 2024
1 parent 38e7bec commit 7f9f556
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 15 deletions.
17 changes: 2 additions & 15 deletions Vonage.Test/ConfigurationTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
using Vonage.Test.TestHelpers;
using WireMock.ResponseBuilders;
using Xunit;
using Xunit.Abstractions;

namespace Vonage.Test;

Expand Down Expand Up @@ -210,13 +209,9 @@ public void FromConfiguration_ShouldCreateEmptyConfiguration_GivenConfigurationC
}

[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)]
Expand Down Expand Up @@ -248,7 +243,7 @@ public async Task ShouldRenewConnection_GivenIdleTimeoutHasExpired()

private async Task<int> RefreshConnectionPool(Dictionary<string, string> 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));
Expand All @@ -266,10 +261,6 @@ private async Task<int> RefreshConnectionPool(Dictionary<string, string> 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; }
Expand All @@ -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;
}
}
Expand Down
8 changes: 8 additions & 0 deletions Vonage.Test/NonThreadSafeCollection.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
using Xunit;

namespace Vonage.Test;

[CollectionDefinition(nameof(NonThreadSafeCollection), DisableParallelization = true)]
public class NonThreadSafeCollection
{
}

0 comments on commit 7f9f556

Please sign in to comment.