Skip to content

Commit

Permalink
Find available port in integration tests (#1173)
Browse files Browse the repository at this point in the history
* use random ports in integration tests

* Remove and Sort Usings

* Code modern look

* code review

* code review: fix messages

* code review: fix some messages

* code review: Use simple `using` statement

* Add Ocelot.Testing project

---------

Co-authored-by: raman-m <[email protected]>
  • Loading branch information
jlukawska and raman-m authored Oct 27, 2023
1 parent e92b103 commit ab3d8e6
Show file tree
Hide file tree
Showing 51 changed files with 310 additions and 276 deletions.
7 changes: 7 additions & 0 deletions Ocelot.sln
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Ocelot.Samples.ServiceDisco
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Ocelot.Samples.ServiceDiscovery.DownstreamService", "samples\OcelotServiceDiscovery\DownstreamService\Ocelot.Samples.ServiceDiscovery.DownstreamService.csproj", "{E2AC741A-4120-4D59-B5E4-16382ED45E8D}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Ocelot.Testing", "test\Ocelot.Testing\Ocelot.Testing.csproj", "{AE6BCCBD-0687-4C58-B30F-4ABBC6422087}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -202,6 +204,10 @@ Global
{E2AC741A-4120-4D59-B5E4-16382ED45E8D}.Debug|Any CPU.Build.0 = Debug|Any CPU
{E2AC741A-4120-4D59-B5E4-16382ED45E8D}.Release|Any CPU.ActiveCfg = Release|Any CPU
{E2AC741A-4120-4D59-B5E4-16382ED45E8D}.Release|Any CPU.Build.0 = Release|Any CPU
{AE6BCCBD-0687-4C58-B30F-4ABBC6422087}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{AE6BCCBD-0687-4C58-B30F-4ABBC6422087}.Debug|Any CPU.Build.0 = Debug|Any CPU
{AE6BCCBD-0687-4C58-B30F-4ABBC6422087}.Release|Any CPU.ActiveCfg = Release|Any CPU
{AE6BCCBD-0687-4C58-B30F-4ABBC6422087}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down Expand Up @@ -241,6 +247,7 @@ Global
{25C30AAA-12DD-4BA5-A53F-9271E54EBAB7} = {8FA0CBA0-0338-48EB-B37F-83CA5022237C}
{D37209EA-C13E-42AE-B851-A8604F1FCD0E} = {25C30AAA-12DD-4BA5-A53F-9271E54EBAB7}
{E2AC741A-4120-4D59-B5E4-16382ED45E8D} = {25C30AAA-12DD-4BA5-A53F-9271E54EBAB7}
{AE6BCCBD-0687-4C58-B30F-4ABBC6422087} = {5B401523-36DA-4491-B73A-7590A26E420B}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {21476EFF-778A-4F97-8A56-D1AF1CEC0C48}
Expand Down
28 changes: 14 additions & 14 deletions test/Ocelot.AcceptanceTests/AggregateTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public AggregateTests()
[Fact]
public void should_fix_issue_597()
{
var port = RandomPortFinder.GetRandomPort();
var port = PortFinder.GetRandomPort();
var configuration = new FileConfiguration
{
Routes = new List<FileRoute>
Expand Down Expand Up @@ -132,9 +132,9 @@ public void should_fix_issue_597()
[Fact]
public void should_return_response_200_with_advanced_aggregate_configs()
{
var port1 = RandomPortFinder.GetRandomPort();
var port2 = RandomPortFinder.GetRandomPort();
var port3 = RandomPortFinder.GetRandomPort();
var port1 = PortFinder.GetRandomPort();
var port2 = PortFinder.GetRandomPort();
var port3 = PortFinder.GetRandomPort();
var configuration = new FileConfiguration
{
Routes = new List<FileRoute>
Expand Down Expand Up @@ -229,8 +229,8 @@ public void should_return_response_200_with_advanced_aggregate_configs()
[Fact]
public void should_return_response_200_with_simple_url_user_defined_aggregate()
{
var port1 = RandomPortFinder.GetRandomPort();
var port2 = RandomPortFinder.GetRandomPort();
var port1 = PortFinder.GetRandomPort();
var port2 = PortFinder.GetRandomPort();
var configuration = new FileConfiguration
{
Routes = new List<FileRoute>
Expand Down Expand Up @@ -300,8 +300,8 @@ public void should_return_response_200_with_simple_url_user_defined_aggregate()
[Fact]
public void should_return_response_200_with_simple_url()
{
var port1 = RandomPortFinder.GetRandomPort();
var port2 = RandomPortFinder.GetRandomPort();
var port1 = PortFinder.GetRandomPort();
var port2 = PortFinder.GetRandomPort();
var configuration = new FileConfiguration
{
Routes = new List<FileRoute>
Expand Down Expand Up @@ -370,8 +370,8 @@ public void should_return_response_200_with_simple_url()
[Fact]
public void should_return_response_200_with_simple_url_one_service_404()
{
var port1 = RandomPortFinder.GetRandomPort();
var port2 = RandomPortFinder.GetRandomPort();
var port1 = PortFinder.GetRandomPort();
var port2 = PortFinder.GetRandomPort();
var configuration = new FileConfiguration
{
Routes = new List<FileRoute>
Expand Down Expand Up @@ -440,8 +440,8 @@ public void should_return_response_200_with_simple_url_one_service_404()
[Fact]
public void should_return_response_200_with_simple_url_both_service_404()
{
var port1 = RandomPortFinder.GetRandomPort();
var port2 = RandomPortFinder.GetRandomPort();
var port1 = PortFinder.GetRandomPort();
var port2 = PortFinder.GetRandomPort();
var configuration = new FileConfiguration
{
Routes = new List<FileRoute>
Expand Down Expand Up @@ -510,8 +510,8 @@ public void should_return_response_200_with_simple_url_both_service_404()
[Fact]
public void should_be_thread_safe()
{
var port1 = RandomPortFinder.GetRandomPort();
var port2 = RandomPortFinder.GetRandomPort();
var port1 = PortFinder.GetRandomPort();
var port2 = PortFinder.GetRandomPort();
var configuration = new FileConfiguration
{
Routes = new List<FileRoute>
Expand Down
12 changes: 6 additions & 6 deletions test/Ocelot.AcceptanceTests/AuthenticationTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public AuthenticationTests()
{
_serviceHandler = new ServiceHandler();
_steps = new Steps();
var identityServerPort = RandomPortFinder.GetRandomPort();
var identityServerPort = PortFinder.GetRandomPort();
_identityServerRootUrl = $"http://localhost:{identityServerPort}";
_options = o =>
{
Expand All @@ -41,7 +41,7 @@ public AuthenticationTests()
[Fact]
public void should_return_401_using_identity_server_access_token()
{
var port = RandomPortFinder.GetRandomPort();
var port = PortFinder.GetRandomPort();

var configuration = new FileConfiguration
{
Expand Down Expand Up @@ -82,7 +82,7 @@ public void should_return_401_using_identity_server_access_token()
[Fact]
public void should_return_response_200_using_identity_server()
{
var port = RandomPortFinder.GetRandomPort();
var port = PortFinder.GetRandomPort();

var configuration = new FileConfiguration
{
Expand Down Expand Up @@ -125,7 +125,7 @@ public void should_return_response_200_using_identity_server()
[Fact]
public void should_return_response_401_using_identity_server_with_token_requested_for_other_api()
{
var port = RandomPortFinder.GetRandomPort();
var port = PortFinder.GetRandomPort();

var configuration = new FileConfiguration
{
Expand Down Expand Up @@ -167,7 +167,7 @@ public void should_return_response_401_using_identity_server_with_token_requeste
[Fact]
public void should_return_201_using_identity_server_access_token()
{
var port = RandomPortFinder.GetRandomPort();
var port = PortFinder.GetRandomPort();

var configuration = new FileConfiguration
{
Expand Down Expand Up @@ -210,7 +210,7 @@ public void should_return_201_using_identity_server_access_token()
[Fact]
public void should_return_201_using_identity_server_reference_token()
{
var port = RandomPortFinder.GetRandomPort();
var port = PortFinder.GetRandomPort();

var configuration = new FileConfiguration
{
Expand Down
12 changes: 6 additions & 6 deletions test/Ocelot.AcceptanceTests/AuthorizationTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public AuthorizationTests()
{
_serviceHandler = new ServiceHandler();
_steps = new Steps();
var identityServerPort = RandomPortFinder.GetRandomPort();
var identityServerPort = PortFinder.GetRandomPort();
_identityServerRootUrl = $"http://localhost:{identityServerPort}";
_options = o =>
{
Expand All @@ -37,7 +37,7 @@ public AuthorizationTests()
[Fact]
public void should_return_response_200_authorizing_route()
{
var port = RandomPortFinder.GetRandomPort();
var port = PortFinder.GetRandomPort();

var configuration = new FileConfiguration
{
Expand Down Expand Up @@ -97,7 +97,7 @@ public void should_return_response_200_authorizing_route()
[Fact]
public void should_return_response_403_authorizing_route()
{
var port = RandomPortFinder.GetRandomPort();
var port = PortFinder.GetRandomPort();

var configuration = new FileConfiguration
{
Expand Down Expand Up @@ -155,7 +155,7 @@ public void should_return_response_403_authorizing_route()
[Fact]
public void should_return_response_200_using_identity_server_with_allowed_scope()
{
var port = RandomPortFinder.GetRandomPort();
var port = PortFinder.GetRandomPort();

var configuration = new FileConfiguration
{
Expand Down Expand Up @@ -198,7 +198,7 @@ public void should_return_response_200_using_identity_server_with_allowed_scope(
[Fact]
public void should_return_response_403_using_identity_server_with_scope_not_allowed()
{
var port = RandomPortFinder.GetRandomPort();
var port = PortFinder.GetRandomPort();

var configuration = new FileConfiguration
{
Expand Down Expand Up @@ -241,7 +241,7 @@ public void should_return_response_403_using_identity_server_with_scope_not_allo
[Fact]
public void should_fix_issue_240()
{
var port = RandomPortFinder.GetRandomPort();
var port = PortFinder.GetRandomPort();

var configuration = new FileConfiguration
{
Expand Down
10 changes: 5 additions & 5 deletions test/Ocelot.AcceptanceTests/ButterflyTracingTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ public ButterflyTracingTests(ITestOutputHelper output)
[Fact]
public void should_forward_tracing_information_from_ocelot_and_downstream_services()
{
var port1 = RandomPortFinder.GetRandomPort();
var port2 = RandomPortFinder.GetRandomPort();
var port1 = PortFinder.GetRandomPort();
var port2 = PortFinder.GetRandomPort();
var configuration = new FileConfiguration
{
Routes = new List<FileRoute>
Expand Down Expand Up @@ -74,7 +74,7 @@ public void should_forward_tracing_information_from_ocelot_and_downstream_servic
},
};

var butterflyPort = RandomPortFinder.GetRandomPort();
var butterflyPort = PortFinder.GetRandomPort();
var butterflyUrl = $"http://localhost:{butterflyPort}";

this.Given(x => GivenFakeButterfly(butterflyUrl))
Expand All @@ -100,7 +100,7 @@ public void should_forward_tracing_information_from_ocelot_and_downstream_servic
[Fact]
public void should_return_tracing_header()
{
var port = RandomPortFinder.GetRandomPort();
var port = PortFinder.GetRandomPort();
var configuration = new FileConfiguration
{
Routes = new List<FileRoute>
Expand Down Expand Up @@ -132,7 +132,7 @@ public void should_return_tracing_header()
},
};

var butterflyPort = RandomPortFinder.GetRandomPort();
var butterflyPort = PortFinder.GetRandomPort();
var butterflyUrl = $"http://localhost:{butterflyPort}";

this.Given(x => GivenFakeButterfly(butterflyUrl))
Expand Down
8 changes: 4 additions & 4 deletions test/Ocelot.AcceptanceTests/CachingTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public CachingTests()
[Fact]
public void should_return_cached_response()
{
var port = RandomPortFinder.GetRandomPort();
var port = PortFinder.GetRandomPort();

var configuration = new FileConfiguration
{
Expand Down Expand Up @@ -62,7 +62,7 @@ public void should_return_cached_response()
[Fact]
public void should_return_cached_response_with_expires_header()
{
var port = RandomPortFinder.GetRandomPort();
var port = PortFinder.GetRandomPort();

var configuration = new FileConfiguration
{
Expand Down Expand Up @@ -108,7 +108,7 @@ public void should_return_cached_response_with_expires_header()
[Fact]
public void should_return_cached_response_when_using_jsonserialized_cache()
{
var port = RandomPortFinder.GetRandomPort();
var port = PortFinder.GetRandomPort();

var configuration = new FileConfiguration
{
Expand Down Expand Up @@ -152,7 +152,7 @@ public void should_return_cached_response_when_using_jsonserialized_cache()
[Fact]
public void should_not_return_cached_response_as_ttl_expires()
{
var port = RandomPortFinder.GetRandomPort();
var port = PortFinder.GetRandomPort();

var configuration = new FileConfiguration
{
Expand Down
2 changes: 1 addition & 1 deletion test/Ocelot.AcceptanceTests/CancelRequestTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public CancelRequestTests()
[Fact]
public void Should_abort_service_work_when_cancelling_the_request()
{
var port = RandomPortFinder.GetRandomPort();
var port = PortFinder.GetRandomPort();

var configuration = new FileConfiguration
{
Expand Down
12 changes: 6 additions & 6 deletions test/Ocelot.AcceptanceTests/CaseSensitiveRoutingTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public CaseSensitiveRoutingTests()
[Fact]
public void should_return_response_200_when_global_ignore_case_sensitivity_set()
{
var port = RandomPortFinder.GetRandomPort();
var port = PortFinder.GetRandomPort();

var configuration = new FileConfiguration
{
Expand Down Expand Up @@ -52,7 +52,7 @@ public void should_return_response_200_when_global_ignore_case_sensitivity_set()
[Fact]
public void should_return_response_200_when_route_ignore_case_sensitivity_set()
{
var port = RandomPortFinder.GetRandomPort();
var port = PortFinder.GetRandomPort();

var configuration = new FileConfiguration
{
Expand Down Expand Up @@ -88,7 +88,7 @@ public void should_return_response_200_when_route_ignore_case_sensitivity_set()
[Fact]
public void should_return_response_404_when_route_respect_case_sensitivity_set()
{
var port = RandomPortFinder.GetRandomPort();
var port = PortFinder.GetRandomPort();

var configuration = new FileConfiguration
{
Expand Down Expand Up @@ -124,7 +124,7 @@ public void should_return_response_404_when_route_respect_case_sensitivity_set()
[Fact]
public void should_return_response_200_when_route_respect_case_sensitivity_set()
{
var port = RandomPortFinder.GetRandomPort();
var port = PortFinder.GetRandomPort();

var configuration = new FileConfiguration
{
Expand Down Expand Up @@ -160,7 +160,7 @@ public void should_return_response_200_when_route_respect_case_sensitivity_set()
[Fact]
public void should_return_response_404_when_global_respect_case_sensitivity_set()
{
var port = RandomPortFinder.GetRandomPort();
var port = PortFinder.GetRandomPort();

var configuration = new FileConfiguration
{
Expand Down Expand Up @@ -196,7 +196,7 @@ public void should_return_response_404_when_global_respect_case_sensitivity_set(
[Fact]
public void should_return_response_200_when_global_respect_case_sensitivity_set()
{
var port = RandomPortFinder.GetRandomPort();
var port = PortFinder.GetRandomPort();

var configuration = new FileConfiguration
{
Expand Down
4 changes: 2 additions & 2 deletions test/Ocelot.AcceptanceTests/ClaimsToDownstreamPathTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public class ClaimsToDownstreamPathTests : IDisposable

public ClaimsToDownstreamPathTests()
{
var identityServerPort = RandomPortFinder.GetRandomPort();
var identityServerPort = PortFinder.GetRandomPort();
_identityServerRootUrl = $"http://localhost:{identityServerPort}";
_steps = new Steps();
_options = o =>
Expand All @@ -43,7 +43,7 @@ public void should_return_200_and_change_downstream_path()
SubjectId = "registered|1231231",
};

var port = RandomPortFinder.GetRandomPort();
var port = PortFinder.GetRandomPort();

var configuration = new FileConfiguration
{
Expand Down
4 changes: 2 additions & 2 deletions test/Ocelot.AcceptanceTests/ClaimsToHeadersForwardingTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public ClaimsToHeadersForwardingTests()
{
_serviceHandler = new ServiceHandler();
_steps = new Steps();
var identityServerPort = RandomPortFinder.GetRandomPort();
var identityServerPort = PortFinder.GetRandomPort();
_identityServerRootUrl = $"http://localhost:{identityServerPort}";
_options = o =>
{
Expand All @@ -51,7 +51,7 @@ public void should_return_response_200_and_foward_claim_as_header()
},
};

var port = RandomPortFinder.GetRandomPort();
var port = PortFinder.GetRandomPort();

var configuration = new FileConfiguration
{
Expand Down
Loading

0 comments on commit ab3d8e6

Please sign in to comment.