Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix intermittent errors during build and in VS Test Explorer #430

Merged
merged 1 commit into from
Jan 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

<PropertyGroup>
<IsTestProject>false</IsTestProject>
<TestProject>false</TestProject>
</PropertyGroup>

<PropertyGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

<PropertyGroup>
<IsTestProject>false</IsTestProject>
<TestProject>false</TestProject>
</PropertyGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,12 @@

<PropertyGroup>
<IsTestProject>false</IsTestProject>
<TestProject>false</TestProject>
</PropertyGroup>
<ItemGroup>
<!-- This project takes depedency on nUnit that adds the TestContainer capability importing NUnit.props, but this is not a test project -->
<ProjectCapability Remove="TestContainer" />
</ItemGroup>

<PropertyGroup>
<PackageLicenseExpression>Apache-2.0</PackageLicenseExpression>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,12 @@

<PropertyGroup>
<IsTestProject>false</IsTestProject>
<TestProject>false</TestProject>
</PropertyGroup>
<ItemGroup>
<!-- This project takes depedency on nUnit that adds the TestContainer capability importing NUnit.props, but this is not a test project -->
<ProjectCapability Remove="TestContainer" />
</ItemGroup>

<PropertyGroup>
<PackageLicenseExpression>Apache-2.0</PackageLicenseExpression>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public FunctionPerTestFacts(ITestOutputHelper output)
.CreateLogger("Xunit Demo tests");

this.function = new FunctionsController(logger);
this.Port = new Random().Next(50000, 60000);
this.Port = this.function.FindAvailableTcpPort(50000, 60000);
}

public int Port { get; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

<PropertyGroup>
<IsTestProject>false</IsTestProject>
<TestProject>false</TestProject>
</PropertyGroup>

<PropertyGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,34 @@ await Task.WhenAny(
this.logger.LogInformation("Function {Path} now running on port {Port}", path, port);
}

/// <summary>
/// Randomly selects a port that appears to be available for use.
/// </summary>
/// <param name="lowerBoundInclusive">
/// The lowest port number acceptable. Defaults to 50000.
/// </param>
/// <param name="upperBoundExclusive">
/// The port number above which no port will be selected. Defaults to 60000.
/// </param>
/// <returns>A port number that seems to be available.</returns>
public int FindAvailableTcpPort(int? lowerBoundInclusive, int? upperBoundExclusive)
{
int lb = lowerBoundInclusive ?? 50000;
int ub = upperBoundExclusive ?? 60000;

var portsInRangeInUse = IPGlobalProperties
.GetIPGlobalProperties()
.GetActiveTcpListeners()
.Select(e => e.Port)
.Where(p => p >= lb && p < ub)
.ToHashSet();

int availablePorts = ub - lb - portsInRangeInUse.Count;
int availablePortOffset = Random.Shared.Next(availablePorts);
int port = Enumerable.Range(lb, ub - lb).Where(p => !portsInRangeInUse.Contains(p)).ElementAt(availablePortOffset);
return port;
}

/// <summary>
/// Provides access to the output.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,12 @@

<PropertyGroup>
<IsTestProject>false</IsTestProject>
<TestProject>false</TestProject>
</PropertyGroup>
<ItemGroup>
<!-- This project takes depedency on nUnit that adds the TestContainer capability importing NUnit.props, but this is not a test project -->
<ProjectCapability Remove="TestContainer" />
</ItemGroup>

<PropertyGroup>
<PackageLicenseExpression>Apache-2.0</PackageLicenseExpression>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,12 @@

<PropertyGroup>
<IsTestProject>false</IsTestProject>
<TestProject>false</TestProject>
</PropertyGroup>
<ItemGroup>
<!-- This project takes depedency on nUnit that adds the TestContainer capability importing NUnit.props, but this is not a test project -->
<ProjectCapability Remove="TestContainer" />
</ItemGroup>

<PropertyGroup>
<PackageLicenseExpression>Apache-2.0</PackageLicenseExpression>
Expand Down
Loading