File tree Expand file tree Collapse file tree 2 files changed +6
-4
lines changed
src/samples/WorkflowCore.TestSample01 Expand file tree Collapse file tree 2 files changed +6
-4
lines changed Original file line number Diff line number Diff line change 1
1
<Project Sdk =" Microsoft.NET.Sdk" >
2
2
3
3
<PropertyGroup >
4
- <TargetFramework >netcoreapp2.2 </TargetFramework >
4
+ <TargetFramework >netcoreapp3.1 </TargetFramework >
5
5
</PropertyGroup >
6
6
7
7
<ItemGroup >
Original file line number Diff line number Diff line change @@ -30,7 +30,7 @@ public abstract class DockerSetup : IDisposable
30
30
protected readonly DockerClient docker ;
31
31
protected string containerId ;
32
32
33
- private static object Lock = new object ( ) ;
33
+ private static HashSet < int > UsedPorts = new HashSet < int > ( ) ;
34
34
35
35
protected DockerSetup ( )
36
36
{
@@ -124,7 +124,7 @@ public void Dispose()
124
124
125
125
private int GetFreePort ( )
126
126
{
127
- lock ( Lock )
127
+ lock ( UsedPorts )
128
128
{
129
129
const int startRange = 1000 ;
130
130
const int endRange = 10000 ;
@@ -134,11 +134,13 @@ private int GetFreePort()
134
134
135
135
var result = startRange ;
136
136
137
- while ( ( ( tcpPorts . Any ( x => x . Port == result ) ) || ( udpPorts . Any ( x => x . Port == result ) ) ) && result <= endRange )
137
+ while ( ( ( tcpPorts . Any ( x => x . Port == result ) ) || ( udpPorts . Any ( x => x . Port == result ) ) ) && result <= endRange && ! UsedPorts . Contains ( result ) )
138
138
result ++ ;
139
139
140
140
if ( result > endRange )
141
141
throw new PortsInUseException ( ) ;
142
+
143
+ UsedPorts . Add ( result ) ;
142
144
143
145
return result ;
144
146
}
You can’t perform that action at this time.
0 commit comments