Skip to content

Commit 39f643c

Browse files
committed
Remove PollyQosSteps as ugly composition pattern, thus, it's not required anymore
1 parent 2a8c7f6 commit 39f643c

4 files changed

Lines changed: 9 additions & 47 deletions

File tree

‎acceptance/DynamicRoutingTests.cs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ public async Task ShouldApplyGlobalQosOptions_ForAllDynamicRoutes_WithGroupedOpt
7878
};
7979
GivenDiscoveryMetadata(route3, ports3);
8080

81-
var configuration = GivenDynamicRouting(new(), route1, route2, route3);
81+
var configuration = GivenDynamicRouting([], route1, route2, route3);
8282
var globalOptions = configuration.GlobalConfiguration.QoSOptions
8383
= new(new QoSOptions(GlobalExceptions, GlobalBreakMs))
8484
{

‎acceptance/PollyQosTests.cs‎

Lines changed: 3 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
using Ocelot.Configuration;
44
using Ocelot.Configuration.File;
55
using Ocelot.DependencyInjection;
6-
using Ocelot.Testing.Steps;
76
using Polly.CircuitBreaker;
87
using Polly.Timeout;
98
using Shouldly;
@@ -14,8 +13,10 @@ namespace Ocelot.QualityOfService.Polly.Acceptance;
1413

1514
[Trait("Feat", "23")] // https://github.com/ThreeMammals/Ocelot/issues/23
1615
[Trait("Feat", "39")] // https://github.com/ThreeMammals/Ocelot/pull/39
17-
public sealed class PollyQosTests : PollyQosSteps
16+
public sealed class PollyQosTests : QosSteps
1817
{
18+
public PollyQosTests() : base(null!) => self = this;
19+
1920
[Fact]
2021
[Trait("Feat", "318")] // https://github.com/ThreeMammals/Ocelot/issues/318
2122
[Trait("PR", "319")] // https://github.com/ThreeMammals/Ocelot/pull/319
@@ -505,32 +506,3 @@ private void GivenThereIsAPossiblyBrokenServiceRunningOn(int port, string respon
505506
public override void GivenThereIsAServiceRunningOn(int port, HttpStatusCode statusCode, int timeout, [CallerMemberName] string response = nameof(PollyQosTests))
506507
=> base.GivenThereIsAServiceRunningOn(port, statusCode, timeout, response);
507508
}
508-
509-
public class PollyQosSteps : TimeoutSteps, IQosSteps, IDisposable
510-
{
511-
private readonly QosSteps steps;
512-
public PollyQosSteps() => steps = new(this);
513-
514-
public override void Dispose()
515-
{
516-
steps.Dispose();
517-
base.Dispose();
518-
GC.SuppressFinalize(this);
519-
}
520-
521-
public void GivenThereIsABrokenServiceOnline(HttpStatusCode onlineStatusCode, int index = 0, int length = 1, bool isDiscovery = false)
522-
=> steps.GivenThereIsABrokenServiceOnline(onlineStatusCode, index, length, isDiscovery);
523-
524-
public void GivenThereIsABrokenServiceRunningOn(int port, HttpStatusCode brokenStatusCode, int index = 0)
525-
=> steps.GivenThereIsABrokenServiceRunningOn(port, brokenStatusCode, index);
526-
527-
public void GivenThereIsAServiceRunningOn(int port, HttpStatusCode statusCode,
528-
Func<int> timeoutStrategy, Func<bool> failingStrategy, [CallerMemberName] string? response = null)
529-
=> steps.GivenThereIsAServiceRunningOn(port, statusCode, timeoutStrategy, failingStrategy, response);
530-
531-
public Task TestRouteCircuitBreaker(int[] ports, string upstreamPath, FileQoSOptions qos, int index = 0, bool isDiscovery = false)
532-
=> steps.TestRouteCircuitBreaker(ports, upstreamPath, qos, index, isDiscovery);
533-
534-
public Task TestRouteTimeout(int[] ports, string upstreamPath, FileQoSOptions qos)
535-
=> steps.TestRouteTimeout(ports, upstreamPath, qos);
536-
}

‎acceptance/QosSteps.cs‎

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
using Microsoft.AspNetCore.Http;
22
using Ocelot.Configuration.File;
3-
using Ocelot.Testing;
3+
using Ocelot.Testing.Steps;
44
using System.Collections.Concurrent;
55
using System.Net;
66
using System.Runtime.CompilerServices;
77

88
namespace Ocelot.QualityOfService.Polly.Acceptance;
99

10-
public class QosSteps : AcceptanceSteps, IQosSteps
10+
public class QosSteps : TimeoutSteps
1111
{
12-
private readonly AcceptanceSteps self;
12+
protected AcceptanceSteps self;
1313
public QosSteps(AcceptanceSteps self) => this.self = self;
1414

1515
public async Task TestRouteCircuitBreaker(int[] ports, string upstreamPath, FileQoSOptions qos, int index = 0, bool isDiscovery = false)
@@ -97,7 +97,7 @@ public void GivenThereIsABrokenServiceRunningOn(int port, HttpStatusCode brokenS
9797
return context.Response.WriteAsync(code.ToString());
9898
});
9999
}
100-
public void GivenThereIsABrokenServiceOnline(HttpStatusCode onlineStatusCode, int index = 0, int length = 1, bool isDiscovery = false)
100+
public void GivenThereIsABrokenServiceOnline(HttpStatusCode onlineStatusCode, int index = 0, bool isDiscovery = false)
101101
{
102102
if (!isDiscovery)
103103
{
@@ -110,13 +110,3 @@ public void GivenThereIsABrokenServiceOnline(HttpStatusCode onlineStatusCode, in
110110
}
111111
}
112112
}
113-
114-
public interface IQosSteps
115-
{
116-
Task TestRouteCircuitBreaker(int[] ports, string upstreamPath, FileQoSOptions qos, int index = 0, bool isDiscovery = false);
117-
Task TestRouteTimeout(int[] ports, string upstreamPath, FileQoSOptions qos);
118-
void GivenThereIsAServiceRunningOn(int port, HttpStatusCode statusCode,
119-
Func<int> timeoutStrategy, Func<bool> failingStrategy, [CallerMemberName] string? response = null);
120-
void GivenThereIsABrokenServiceRunningOn(int port, HttpStatusCode brokenStatusCode, int index = 0);
121-
void GivenThereIsABrokenServiceOnline(HttpStatusCode onlineStatusCode, int index = 0, int length = 1, bool isDiscovery = false);
122-
}

‎unit/PollyResiliencePipelineDelegatingHandlerTests.cs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ public async Task SendAsync_WhenResiliencePipelineProviderIsNull_ShouldNotCallGe
9090
_contextAccessor.Setup(x => x.HttpContext)
9191
.Returns(new DefaultHttpContext());
9292
IServiceProvider requestServices = new ServiceCollection().BuildServiceProvider();
93-
_contextAccessor.Setup(x => x.HttpContext.RequestServices)
93+
_contextAccessor.Setup(x => x.HttpContext!.RequestServices)
9494
.Returns(requestServices); // empty service provider → GetService returns null
9595

9696
_sut = new PollyResiliencePipelineDelegatingHandler(DownstreamRouteFactory(), _contextAccessor.Object, _loggerFactory.Object);

0 commit comments

Comments
 (0)