Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mono/corefx.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorTomas Weinfurt <tweinfurt@yahoo.com>2017-10-26 07:56:36 +0300
committerGitHub <noreply@github.com>2017-10-26 07:56:36 +0300
commit0911d81e8d7371fa06236562c1ad702e818af295 (patch)
treeacdd64203c78e114c4687b0d0a78cd14abe9cda1 /src
parent56623123ed2dcf664499c297c1652c68de623769 (diff)
add some code to make sure we sent datagram before we try to receive it (#24615)
* add some code to make sure we sent datagram before we try to receive it. #17681 * use synchronous send with timeout instead of task to avoid race condition
Diffstat (limited to 'src')
-rw-r--r--src/System.Net.Sockets/tests/FunctionalTests/DualModeSocketTest.cs19
-rw-r--r--src/System.Net.Sockets/tests/FunctionalTests/System.Net.Sockets.Tests.csproj6
2 files changed, 18 insertions, 7 deletions
diff --git a/src/System.Net.Sockets/tests/FunctionalTests/DualModeSocketTest.cs b/src/System.Net.Sockets/tests/FunctionalTests/DualModeSocketTest.cs
index fba1acd298..8c0b57c04c 100644
--- a/src/System.Net.Sockets/tests/FunctionalTests/DualModeSocketTest.cs
+++ b/src/System.Net.Sockets/tests/FunctionalTests/DualModeSocketTest.cs
@@ -2707,7 +2707,7 @@ namespace System.Net.Sockets.Tests
private IPAddress _connectTo;
private Socket _serverSocket;
- public SocketUdpClient(ITestOutputHelper output, Socket serverSocket, IPAddress connectTo, int port, bool redundant = true)
+ public SocketUdpClient(ITestOutputHelper output, Socket serverSocket, IPAddress connectTo, int port, bool redundant = true, bool sendNow = true)
{
_output = output;
@@ -2715,14 +2715,18 @@ namespace System.Net.Sockets.Tests
_port = port;
_serverSocket = serverSocket;
- Task.Run(() => ClientSend(null, redundant));
+ if (sendNow)
+ {
+ Task.Run(() => ClientSend(redundant));
+ }
}
- private void ClientSend(object state, bool redundant)
+ public void ClientSend(bool redundant = true, int timeout = 3)
{
try
{
Socket socket = new Socket(_connectTo.AddressFamily, SocketType.Dgram, ProtocolType.Udp);
+ socket.SendTimeout = timeout * 1000;
for (int i = 0; i < (redundant ? TestSettings.UDPRedundancy : 1); i++)
{
@@ -2733,8 +2737,9 @@ namespace System.Net.Sockets.Tests
socket.SendToAsync(e);
}
}
- catch (SocketException)
+ catch (SocketException e)
{
+ _output.WriteLine("Send to {0} {1} failed: {2}", _connectTo, _port, e.ToString());
_serverSocket.Dispose(); // Cancels the test
}
}
@@ -2755,10 +2760,12 @@ namespace System.Net.Sockets.Tests
{
using (Socket serverSocket = new Socket(SocketType.Dgram, ProtocolType.Udp))
{
- serverSocket.ReceiveTimeout = 500;
+ serverSocket.ReceiveTimeout = 1000;
int port = serverSocket.BindToAnonymousPort(listenOn);
- SocketUdpClient client = new SocketUdpClient(_log, serverSocket, connectTo, port);
+ SocketUdpClient client = new SocketUdpClient(_log, serverSocket, connectTo, port, sendNow: false);
+
+ client.ClientSend();
EndPoint receivedFrom = new IPEndPoint(connectTo, port);
int received = serverSocket.ReceiveFrom(new byte[1], ref receivedFrom);
diff --git a/src/System.Net.Sockets/tests/FunctionalTests/System.Net.Sockets.Tests.csproj b/src/System.Net.Sockets/tests/FunctionalTests/System.Net.Sockets.Tests.csproj
index 088fd2ba4d..f3feef4441 100644
--- a/src/System.Net.Sockets/tests/FunctionalTests/System.Net.Sockets.Tests.csproj
+++ b/src/System.Net.Sockets/tests/FunctionalTests/System.Net.Sockets.Tests.csproj
@@ -3,6 +3,7 @@
<Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
<PropertyGroup>
<ProjectGuid>{8CBA022C-635F-4C8D-9D29-CD8AAC68C8E6}</ProjectGuid>
+ <AllowUnsafeBlocks>true</AllowUnsafeBlocks>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='netstandard-Debug|AnyCPU'" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='netstandard-Release|AnyCPU'" />
@@ -97,6 +98,9 @@
<Compile Include="$(CommonTestPath)\System\Diagnostics\Tracing\TestEventListener.cs">
<Link>Common\System\Diagnostics\Tracing\TestEventListener.cs</Link>
</Compile>
+ <Compile Include="$(CommonPath)\System\Net\Logging\NetEventSource.Common.cs">
+ <Link>Common\System\Net\Logging\NetEventSource.Common.cs</Link>
+ </Compile>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="$(CommonTestPath)\System\Diagnostics\RemoteExecutorConsoleApp\RemoteExecutorConsoleApp.csproj">
@@ -108,4 +112,4 @@
<EmbeddedResource Include="Resources\$(AssemblyName).rd.xml" />
</ItemGroup>
<Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
-</Project> \ No newline at end of file
+</Project>