Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 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 @@ -136,7 +136,7 @@ private void StartAccept(SocketAsyncEventArgs acceptEventArg)
}

_log.WriteLine(this.GetHashCode() + " StartAccept(_numConnectedSockets={0})", _numConnectedSockets);
if (!_maxNumberAcceptedClientsSemaphore.WaitOne(TestSettings.PassingTestTimeout))
if (!_maxNumberAcceptedClientsSemaphore.WaitOne(TestSettings.PassingTestShortTimeout))
{
throw new TimeoutException("Timeout waiting for client connection.");
}
Expand Down
5 changes: 3 additions & 2 deletions src/libraries/Common/tests/System/Net/Sockets/TestSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@ namespace System.Net.Sockets.Tests
public static class TestSettings
{
// Timeout values in milliseconds.
public const int PassingTestTimeout = 10000;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you keep this untouched to be consistent with other tests? e.g. PassingTestTimeout is normal/default timeout. If we need anything different for come case we would make it with specific name - like PassingTestLongTimeout (that part looks ok to me)

Copy link
Contributor Author

@antonfirsov antonfirsov Sep 1, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reverted this renaming to reduce the diff size.

I think more verbosity in the names wouldn't hurt here. 10 sec is quite a short time in comparison to Http.Tests's default PassingTestTimeout=30sec. We use hardcoded 30 seconds at a bunch of places in socket tests, which we will eventually replace with PassingTestLongTimeout, meaning that the "default" PassingTestTimeout=10sec will become much less common.

public const int PassingTestShortTimeout = 10_000;
public const int PassingTestLongTimeout = 30_000;
public const int FailingTestTimeout = 100;

public static Task WhenAllOrAnyFailedWithTimeout(params Task[] tasks) => tasks.WhenAllOrAnyFailed(PassingTestTimeout);
public static Task WhenAllOrAnyFailedWithTimeout(params Task[] tasks) => tasks.WhenAllOrAnyFailed(PassingTestShortTimeout);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -480,7 +480,7 @@ await Task.Run(async () =>
}
}
}
}).WaitAsync(TestSettings.PassingTestTimeout);
}).WaitAsync(TestSettings.PassingTestShortTimeout);
}

[DllImport("libc")]
Expand Down Expand Up @@ -611,7 +611,7 @@ public unsafe void Ctor_SafeHandle_UnknownSocket_Success()

netlink.Send(new ReadOnlySpan<byte>(Unsafe.AsPointer(ref req), sizeof(nl_request)));

Assert.True(netlink.Poll(TestSettings.PassingTestTimeout, SelectMode.SelectRead));
Assert.True(netlink.Poll(TestSettings.PassingTestShortTimeout, SelectMode.SelectRead));

byte[] response = new byte[4000];
int readBytes = netlink.Receive(response);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -772,7 +772,7 @@ public class DisposedSocketTestsNonParallel
[InlineData(true)]
public async Task NonDisposedSocket_SafeHandlesCollected(bool clientAsync)
{
TimeSpan timeout = TimeSpan.FromMilliseconds(TestSettings.PassingTestTimeout);
TimeSpan timeout = TimeSpan.FromMilliseconds(TestSettings.PassingTestShortTimeout);
List<WeakReference> handles = await CreateHandlesAsync(clientAsync).WaitAsync(timeout);
await RetryHelper.ExecuteAsync(() => Task.Run(() =>
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ public void Socket_ConnectAsyncDnsEndPoint_Success(SocketImplementationType type
bool willRaiseEvent = sock.ConnectAsync(args);
if (willRaiseEvent)
{
Assert.True(complete.WaitOne(TestSettings.PassingTestTimeout), "Timed out while waiting for connection");
Assert.True(complete.WaitOne(TestSettings.PassingTestShortTimeout), "Timed out while waiting for connection");
complete.Dispose(); // only dispose on success as we know we're done with the instance
}

Expand Down Expand Up @@ -244,7 +244,7 @@ public void Socket_ConnectAsyncDnsEndPoint_SetSocketProperties_Success(SocketImp
bool willRaiseEvent = sock.ConnectAsync(args);
if (willRaiseEvent)
{
Assert.True(complete.WaitOne(TestSettings.PassingTestTimeout), "Timed out while waiting for connection");
Assert.True(complete.WaitOne(TestSettings.PassingTestShortTimeout), "Timed out while waiting for connection");
complete.Dispose(); // only dispose on success as we know we're done with the instance
}

Expand Down Expand Up @@ -272,7 +272,7 @@ public void Socket_ConnectAsyncDnsEndPoint_HostNotFound()
bool willRaiseEvent = sock.ConnectAsync(args);
if (willRaiseEvent)
{
Assert.True(complete.WaitOne(TestSettings.PassingTestTimeout), "Timed out while waiting for connection");
Assert.True(complete.WaitOne(TestSettings.PassingTestLongTimeout), "Timed out while waiting for connection");
complete.Dispose(); // only dispose on success as we know we're done with the instance
}

Expand All @@ -299,7 +299,7 @@ public void Socket_ConnectAsyncDnsEndPoint_ConnectionRefused()
bool willRaiseEvent = sock.ConnectAsync(args);
if (willRaiseEvent)
{
Assert.True(complete.WaitOne(TestSettings.PassingTestTimeout), "Timed out while waiting for connection");
Assert.True(complete.WaitOne(TestSettings.PassingTestShortTimeout), "Timed out while waiting for connection");
complete.Dispose(); // only dispose on success as we know we're done with the instance
}

Expand Down Expand Up @@ -332,7 +332,7 @@ public void Socket_StaticConnectAsync_Success(SocketImplementationType type)

if (Socket.ConnectAsync(SocketType.Stream, ProtocolType.Tcp, args))
{
Assert.True(complete.WaitOne(TestSettings.PassingTestTimeout), "Timed out while waiting for connection");
Assert.True(complete.WaitOne(TestSettings.PassingTestLongTimeout), "Timed out while waiting for connection");
}

Assert.Equal(SocketError.Success, args.SocketError);
Expand All @@ -348,7 +348,7 @@ public void Socket_StaticConnectAsync_Success(SocketImplementationType type)

if (Socket.ConnectAsync(SocketType.Stream, ProtocolType.Tcp, args))
{
Assert.True(complete.WaitOne(TestSettings.PassingTestTimeout), "Timed out while waiting for connection");
Assert.True(complete.WaitOne(TestSettings.PassingTestShortTimeout), "Timed out while waiting for connection");
}

complete.Dispose(); // only dispose on success as we know we're done with the instance
Expand Down Expand Up @@ -377,7 +377,7 @@ public void Socket_StaticConnectAsync_IPv6MappedIPv4_Success()

if (Socket.ConnectAsync(SocketType.Stream, ProtocolType.Tcp, args))
{
Assert.True(complete.WaitOne(TestSettings.PassingTestTimeout), "Timed out while waiting for connection");
Assert.True(complete.WaitOne(TestSettings.PassingTestShortTimeout), "Timed out while waiting for connection");
}

Assert.Equal(SocketError.Success, args.SocketError);
Expand All @@ -404,7 +404,7 @@ public void Socket_StaticConnectAsync_HostNotFound()
OnConnectAsyncCompleted(null, args);
}

Assert.True(complete.WaitOne(TestSettings.PassingTestTimeout), "Timed out while waiting for connection");
Assert.True(complete.WaitOne(TestSettings.PassingTestLongTimeout), "Timed out while waiting for connection");
complete.Dispose(); // only dispose on success as we know we're done with the instance

AssertHostNotFoundOrNoData(args);
Expand All @@ -431,7 +431,7 @@ public void Socket_StaticConnectAsync_ConnectionRefused()
OnConnectAsyncCompleted(null, args);
}

Assert.True(complete.WaitOne(TestSettings.PassingTestTimeout), "Timed out while waiting for connection");
Assert.True(complete.WaitOne(TestSettings.PassingTestShortTimeout), "Timed out while waiting for connection");
complete.Dispose(); // only dispose on success as we know we're done with the instance

Assert.Equal(SocketError.ConnectionRefused, args.SocketError);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -545,7 +545,7 @@ private void DualModeConnectAsync_IPEndPointToHost_Helper(IPAddress connectTo, I
if (!pending)
waitHandle.Set();

Assert.True(waitHandle.WaitOne(TestSettings.PassingTestTimeout), "Timed out while waiting for connection");
Assert.True(waitHandle.WaitOne(TestSettings.PassingTestShortTimeout), "Timed out while waiting for connection");
if (args.SocketError != SocketError.Success)
{
throw new SocketException((int)args.SocketError);
Expand Down Expand Up @@ -585,7 +585,7 @@ public void DualModeConnectAsync_DnsEndPointToHost_Helper(IPAddress listenOn, bo
if (!pending)
waitHandle.Set();

Assert.True(waitHandle.WaitOne(TestSettings.PassingTestTimeout), "Timed out while waiting for connection");
Assert.True(waitHandle.WaitOne(TestSettings.PassingTestShortTimeout), "Timed out while waiting for connection");
if (args.SocketError != SocketError.Success)
{
throw new SocketException((int)args.SocketError);
Expand All @@ -611,7 +611,7 @@ public void DualModeConnectAsync_Static_DnsEndPointToHost_Helper(IPAddress liste
if (!pending)
waitHandle.Set();

Assert.True(waitHandle.WaitOne(TestSettings.PassingTestTimeout), "Timed out while waiting for connection");
Assert.True(waitHandle.WaitOne(TestSettings.PassingTestShortTimeout), "Timed out while waiting for connection");
if (args.SocketError != SocketError.Success)
{
throw new SocketException((int)args.SocketError);
Expand Down Expand Up @@ -845,10 +845,10 @@ private void DualModeConnect_BeginAccept_Helper(IPAddress listenOn, IPAddress co
SocketClient client = new SocketClient(_log, serverSocket, connectTo, port);

Assert.True(
client.WaitHandle.WaitOne(TestSettings.PassingTestTimeout),
client.WaitHandle.WaitOne(TestSettings.PassingTestShortTimeout),
"Timed out while waiting for connection");
Assert.True(
async.AsyncWaitHandle.WaitOne(TestSettings.PassingTestTimeout),
async.AsyncWaitHandle.WaitOne(TestSettings.PassingTestShortTimeout),
"Timed out while waiting to accept the client");

// Due to the nondeterministic nature of calling dispose on a Socket that is doing
Expand Down Expand Up @@ -969,7 +969,7 @@ private void DualModeConnect_AcceptAsync_Helper(IPAddress listenOn, IPAddress co
waitHandles[0] = waitHandle;
waitHandles[1] = client.WaitHandle;

int completedHandle = WaitHandle.WaitAny(waitHandles, TestSettings.PassingTestTimeout);
int completedHandle = WaitHandle.WaitAny(waitHandles, TestSettings.PassingTestShortTimeout);

if (completedHandle == WaitHandle.WaitTimeout)
{
Expand Down Expand Up @@ -1101,7 +1101,7 @@ private void DualModeSendTo_IPEndPointToHost_Helper(IPAddress connectTo, IPAddre
int sent = client.SendTo(new byte[1], new IPEndPoint(connectTo, port));
Assert.Equal(1, sent);

bool success = server.WaitHandle.WaitOne(expectedToTimeout ? TestSettings.FailingTestTimeout : TestSettings.PassingTestTimeout); // Make sure the bytes were received
bool success = server.WaitHandle.WaitOne(expectedToTimeout ? TestSettings.FailingTestTimeout : TestSettings.PassingTestShortTimeout); // Make sure the bytes were received
if (!success)
{
throw new TimeoutException();
Expand Down Expand Up @@ -1202,7 +1202,7 @@ private void DualModeBeginSendTo_EndPointToHost_Helper(IPAddress connectTo, IPAd
int sent = client.EndSendTo(async);
Assert.Equal(1, sent);

bool success = server.WaitHandle.WaitOne(expectedToTimeout ? TestSettings.FailingTestTimeout : TestSettings.PassingTestTimeout); // Make sure the bytes were received
bool success = server.WaitHandle.WaitOne(expectedToTimeout ? TestSettings.FailingTestTimeout : TestSettings.PassingTestShortTimeout); // Make sure the bytes were received
if (!success)
{
throw new TimeoutException();
Expand Down Expand Up @@ -1326,7 +1326,7 @@ private void DualModeSendToAsync_IPEndPointToHost_Helper(IPAddress connectTo, IP
bool async = client.SendToAsync(args);
if (async)
{
Assert.True(waitHandle.WaitOne(TestSettings.PassingTestTimeout), "Timeout while waiting for connection");
Assert.True(waitHandle.WaitOne(TestSettings.PassingTestShortTimeout), "Timeout while waiting for connection");
}

Assert.Equal(1, args.BytesTransferred);
Expand All @@ -1336,7 +1336,7 @@ private void DualModeSendToAsync_IPEndPointToHost_Helper(IPAddress connectTo, IP
}
}

bool success = server.WaitHandle.WaitOne(expectedToTimeout ? TestSettings.FailingTestTimeout : TestSettings.PassingTestTimeout); // Make sure the bytes were received
bool success = server.WaitHandle.WaitOne(expectedToTimeout ? TestSettings.FailingTestTimeout : TestSettings.PassingTestShortTimeout); // Make sure the bytes were received
if (!success)
{
throw new TimeoutException();
Expand Down Expand Up @@ -1606,7 +1606,7 @@ private void BeginReceiveFrom_Helper(IPAddress listenOn, IPAddress connectTo, bo
// Assert.Equal(connectTo.MapToIPv6(), remoteEndPoint.Address);

SocketUdpClient client = new SocketUdpClient(_log, serverSocket, connectTo, port);
bool success = async.AsyncWaitHandle.WaitOne(expectedToTimeout ? TestSettings.FailingTestTimeout : TestSettings.PassingTestTimeout);
bool success = async.AsyncWaitHandle.WaitOne(expectedToTimeout ? TestSettings.FailingTestTimeout : TestSettings.PassingTestShortTimeout);
if (!success)
{
throw new TimeoutException();
Expand Down Expand Up @@ -1751,7 +1751,7 @@ private void ReceiveFromAsync_Helper(IPAddress listenOn, IPAddress connectTo, bo

bool async = serverSocket.ReceiveFromAsync(args);
SocketUdpClient client = new SocketUdpClient(_log, serverSocket, connectTo, port);
if (async && !waitHandle.WaitOne(expectedToTimeout ? TestSettings.FailingTestTimeout : TestSettings.PassingTestTimeout))
if (async && !waitHandle.WaitOne(expectedToTimeout ? TestSettings.FailingTestTimeout : TestSettings.PassingTestShortTimeout))
{
throw new TimeoutException();
}
Expand Down Expand Up @@ -1984,7 +1984,7 @@ public void ReceiveMessageFromAsync_SocketAsyncEventArgs_Success(bool ipv4)
{
completed.Set();
}
Assert.True(completed.Wait(TestSettings.PassingTestTimeout), "Timeout while waiting for connection");
Assert.True(completed.Wait(TestSettings.PassingTestShortTimeout), "Timeout while waiting for connection");
completed.Reset();

Assert.Equal(DataLength, args.BytesTransferred);
Expand Down Expand Up @@ -2031,7 +2031,7 @@ private void ReceiveMessageFrom_Helper(IPAddress listenOn, IPAddress connectTo,
});
}

serverSocket.ReceiveTimeout = expectedToTimeout ? TestSettings.FailingTestTimeout : TestSettings.PassingTestTimeout;
serverSocket.ReceiveTimeout = expectedToTimeout ? TestSettings.FailingTestTimeout : TestSettings.PassingTestShortTimeout;

SocketUdpClient client = new SocketUdpClient(_log, serverSocket, connectTo, port);

Expand Down Expand Up @@ -2201,7 +2201,7 @@ private void BeginReceiveMessageFrom_Helper(IPAddress listenOn, IPAddress connec
// Assert.Equal(connectTo.MapToIPv6(), remoteEndPoint.Address);

SocketUdpClient client = new SocketUdpClient(_log, serverSocket, connectTo, port);
bool success = async.AsyncWaitHandle.WaitOne(expectedToTimeout ? TestSettings.FailingTestTimeout : TestSettings.PassingTestTimeout);
bool success = async.AsyncWaitHandle.WaitOne(expectedToTimeout ? TestSettings.FailingTestTimeout : TestSettings.PassingTestShortTimeout);
if (!success)
{
throw new TimeoutException();
Expand Down Expand Up @@ -2361,7 +2361,7 @@ private void ReceiveMessageFromAsync_Helper(IPAddress listenOn, IPAddress connec
{
using (Socket serverSocket = new Socket(SocketType.Dgram, ProtocolType.Udp))
{
serverSocket.ReceiveTimeout = expectedToTimeout ? TestSettings.FailingTestTimeout : TestSettings.PassingTestTimeout;
serverSocket.ReceiveTimeout = expectedToTimeout ? TestSettings.FailingTestTimeout : TestSettings.PassingTestShortTimeout;
int port = serverSocket.BindToAnonymousPort(listenOn);

ManualResetEvent waitHandle = new ManualResetEvent(false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -524,15 +524,15 @@ public void ExecutionContext_NotCachedInSocketAsyncEventArgs()
al.Value = null;

server.Send(new byte[1]);
Assert.True(receiveCompleted.Wait(TestSettings.PassingTestTimeout));
Assert.True(receiveCompleted.Wait(TestSettings.PassingTestShortTimeout));

for (int i = 0; i < 3; i++)
{
GC.Collect();
GC.WaitForPendingFinalizers();
}

Assert.True(ecDropped.Wait(TestSettings.PassingTestTimeout));
Assert.True(ecDropped.Wait(TestSettings.PassingTestShortTimeout));
}
}
}
Expand Down
Loading