diff --git a/src/Common/tests/Scripts/ParallelTestExecution.ps1 b/src/Common/tests/Scripts/ParallelTestExecution.ps1 new file mode 100644 index 000000000000..b1fbcd24ae36 --- /dev/null +++ b/src/Common/tests/Scripts/ParallelTestExecution.ps1 @@ -0,0 +1,249 @@ +# Licensed to the .NET Foundation under one or more agreements. +# The .NET Foundation licenses this file to you under the MIT license. +# See the LICENSE file in the project root for more information. + +# Usage: +# +# . ParallelTestExecution.ps1 +# cd (e.g. testFolder = src\System.Net.Security\tests\FunctionalTests) +# RunMultiple [-UntilFailed] +# +# The above sequence will open up windows running the test project present in the current folder. +# If -UntilFailed is used, the tests will continuously loop until a failure is detected. +# Between loops, the execution will pause for . + +function BuildAndTestBinary +{ + $output = (msbuild /t:rebuild,test) + if ($lastexitcode -ne 0) + { + throw "Build/test failed." + } + + return $output +} + +function TileWindows +{ + $shell = New-Object -ComObject Shell.Application + $shell.TileHorizontally() +} + +function CurrentPath +{ + return (Get-Item -Path ".\" -Verbose).FullName +} + +function ParseCurrentPath +{ + $p = CurrentPath + + $test_found = $false + $contract_found = $false + $root_found = $false + + while ((-not $root_found) -and ($p -ne "")) + { + $leaf = Split-Path $p -Leaf + + if (Test-Path (Join-Path $p 'build.cmd')) + { + $Global:RootPath = $p + $root_found = $true + } + + if ($test_found -and (-not $contract_found)) + { + $Global:ContractName = $leaf + $contract_found = $true + } + + if ($leaf -eq "tests") + { + $test_found = $true + } + + $p = Split-Path $p + } + + if (-not $test_found) + { + throw "This folder doesn't appear to be part of a test (looking for ...\contract\tests\...)." + } +} + +function ParseTestExecutionCommand($msBuildOutput) +{ + $foundTestExecution = $false + $cmdLine = "" + + foreach ($line in $msBuildOutput) + { + if ($foundTestExecution -eq $true) + { + $cmdLine = $line + break + } + + if ($line.Contains("RunTestsForProject:")) + { + $foundTestExecution = $true + } + } + + if (-not $foundTestExecution) + { + throw "Cannot parse MSBuild output: please ensure that the current folder contains a test." + } + + $Global:TestCommand = $cmdLine.Trim() +} + +function ParseTestFolder($testExecutionCmdLine) +{ + $coreRunPath = $testExecutionCmdLine.Split()[0] + return Split-Path $coreRunPath +} + +function Initialize +{ + ParseCurrentPath + + Write-Host -NoNewline "Initializing tests for $($Global:ContractName) . . . " + + try + { + $output = BuildAndTestBinary + ParseTestExecutionCommand($output) + + Write-Host -ForegroundColor Green "OK" + } + catch + { + Write-Host -ForegroundColor Red "Failed" + throw + } +} + +function RunOne($testCommand) +{ + if ($testCommand -ne "") + { + $Global:TestCommand = $testCommand + } + + if ($Global:TestCommand -eq $null) + { + throw "Run Initialize first or pass the test command line as a parameter." + } + + Write-Host $Global:TestCommand + $path = ParseTestFolder($Global:TestCommand) + Write-Host "$path" + + Push-Location + cd $path + Invoke-Expression $Global:TestCommand + if ($lastexitcode -ne 0) + { + throw "Test execution failed." + } + + Pop-Location +} + +function RunUntilFailed($testCommand, $delayVarianceMilliseconds = 0) +{ + + try + { + while($true) + { + RunOne $testCommand + + if ($delayVarianceMilliseconds -ne 0) + { + $sleepMilliseconds = Get-Random -Minimum 0 -Maximum $delayVarianceMilliseconds + Write-Host -ForegroundColor Cyan "Sleeping $sleepMilliseconds" + Start-Sleep -Milliseconds $sleepMilliseconds + } + } + } + catch + { + Write-Host -ForegroundColor Red "Test execution failed!" + Read-Host "Press ENTER to continue..." + } +} + +function RunMultiple( + [int]$n = 2, + [int]$RandomDelayVarianceMilliseconds = 0, + [switch]$UntilFailed = $false) +{ + if ($Global:TestCommand -eq $null) + { + Initialize + } + + $script = $PSCommandPath + $testCommand = $Global:TestCommand + + if ($untilFailed) + { + $executionMethod = "RunUntilFailed" + } + else + { + $executionMethod = "RunOne" + } + + $cmdArguments = "-Command `"&{. $script; $executionMethod '$testCommand' $RandomDelayVarianceMilliseconds}`"" + + $processes = @() + + for ($i=0; $i -lt $n; $i++) + { + $thisCmdArguments = $cmdArguments -replace ("testResults.xml", "testResults$i.xml") + $process = Start-Process -PassThru powershell -ArgumentList $thisCmdArguments + $processes += $process + } + + $processesExited = $false + while (-not ([console]::KeyAvailable -or $processesExited)) + { + Clear-Host + + Write-Host -ForegroundColor Cyan "Active test processes:" + Write-Host + Write-Host "[Press any key to close.]" + Write-Host + $processes | Format-Table -Property Id, CPU, Handles, WS, ExitCode + + $processesExited = $true + foreach($p in $processes) + { + if (-not $p.HasExited) + { + $processesExited = $false + } + } + + Start-Sleep -Milliseconds 1000 + TileWindows + } + + if (-not $processesExited) + { + Write-Host -ForegroundColor Cyan "Terminating all processes." + foreach ($p in $processes) + { + if (-not $p.HasExited) + { + $p.Kill() + } + } + } + + Write-Host "Done." +} diff --git a/src/Common/tests/System/Net/VirtualNetwork/VirtualNetwork.cs b/src/Common/tests/System/Net/VirtualNetwork/VirtualNetwork.cs index 82d492deb276..b82c3946d9d5 100644 --- a/src/Common/tests/System/Net/VirtualNetwork/VirtualNetwork.cs +++ b/src/Common/tests/System/Net/VirtualNetwork/VirtualNetwork.cs @@ -10,7 +10,7 @@ namespace System.Net.Test.Common { public class VirtualNetwork { - private readonly int WaitForReadDataTimeoutMilliseconds = 10 * 1000; + private readonly int WaitForReadDataTimeoutMilliseconds = 30 * 1000; private readonly ConcurrentQueue _clientWriteQueue = new ConcurrentQueue(); private readonly ConcurrentQueue _serverWriteQueue = new ConcurrentQueue(); @@ -34,9 +34,29 @@ public void ReadFrame(bool server, out byte[] buffer) packetQueue = _serverWriteQueue; } - semaphore.Wait(WaitForReadDataTimeoutMilliseconds); + if (!semaphore.Wait(WaitForReadDataTimeoutMilliseconds)) + { + throw new TimeoutException("VirtualNetwork: Timeout reading the next frame."); + } + + bool dequeueSucceeded = false; + int remainingTries = 3; + int backOffDelayMilliseconds = 2; + + do + { + dequeueSucceeded = packetQueue.TryDequeue(out buffer); + if (dequeueSucceeded) + { + break; + } + + remainingTries--; + backOffDelayMilliseconds *= backOffDelayMilliseconds; + Thread.Sleep(backOffDelayMilliseconds); + } + while (!dequeueSucceeded && (remainingTries > 0)); - bool dequeueSucceeded = packetQueue.TryDequeue(out buffer); Debug.Assert(dequeueSucceeded, "Packet queue: TryDequeue failed."); } diff --git a/src/Common/tests/System/Net/VirtualNetwork/VirtualNetworkStream.cs b/src/Common/tests/System/Net/VirtualNetwork/VirtualNetworkStream.cs index 73ed76184af0..c0497b0c22ce 100644 --- a/src/Common/tests/System/Net/VirtualNetwork/VirtualNetworkStream.cs +++ b/src/Common/tests/System/Net/VirtualNetwork/VirtualNetworkStream.cs @@ -114,16 +114,9 @@ public override Task ReadAsync(byte[] buffer, int offset, int count, Cancel public override Task WriteAsync(byte[] buffer, int offset, int count, CancellationToken cancellationToken) { - try - { - cancellationToken.ThrowIfCancellationRequested(); - Write(buffer, offset, count); - return Task.CompletedTask; - } - catch (Exception e) - { - return Task.FromException(e); - } + return cancellationToken.IsCancellationRequested ? + Task.FromCanceled(cancellationToken) : + Task.Run(() => Write(buffer, offset, count)); } } } diff --git a/src/Common/tests/Tests/System/Net/VirtualNetworkStreamTest.cs b/src/Common/tests/Tests/System/Net/VirtualNetworkStreamTest.cs index ee1092fda728..aeaa4f45fc71 100644 --- a/src/Common/tests/Tests/System/Net/VirtualNetworkStreamTest.cs +++ b/src/Common/tests/Tests/System/Net/VirtualNetworkStreamTest.cs @@ -24,10 +24,13 @@ public void VirtualNetworkStream_SingleThreadIntegrityTest_Ok() { for (int i = 0; i < 100000; i++) { - int bufferSize = rnd.Next(1, 2048); - - byte[] writeFrame = new byte[bufferSize]; + int bufferSize; + byte[] writeFrame; + + bufferSize = rnd.Next(1, 2048); + writeFrame = new byte[bufferSize]; rnd.NextBytes(writeFrame); + uint writeChecksum = Fletcher32.Checksum(writeFrame, 0, writeFrame.Length); client.Write(writeFrame, 0, writeFrame.Length); @@ -99,6 +102,8 @@ public void VirtualNetworkStream_MultiThreadIntegrityTest_Ok() Assert.True(maxFrameSize > sizeof(int) + 1); var rnd = new Random(); + var rndLock = new object(); + var network = new VirtualNetwork(); var checksumAndLengths = new ConcurrentDictionary>(); @@ -107,12 +112,21 @@ public void VirtualNetworkStream_MultiThreadIntegrityTest_Ok() using (var client = new VirtualNetworkStream(network, isServer: false)) using (var server = new VirtualNetworkStream(network, isServer: true)) { - Parallel.For(0, 100000, async (int i) => + Parallel.For(0, 100, (int i) => { - int bufferSize = rnd.Next(sizeof(int) + 1, maxFrameSize); + int bufferSize; + int delayMilliseconds; + byte[] writeFrame; + + lock (rndLock) + { + bufferSize = rnd.Next(sizeof(int) + 1, maxFrameSize); + delayMilliseconds = rnd.Next(0, 10); + + writeFrame = new byte[bufferSize]; + rnd.NextBytes(writeFrame); + } - byte[] writeFrame = new byte[bufferSize]; - rnd.NextBytes(writeFrame); // First 4 bytes represent the sequence number. byte[] sequenceNo = BitConverter.GetBytes(i); @@ -123,14 +137,12 @@ public void VirtualNetworkStream_MultiThreadIntegrityTest_Ok() checksumAndLengths.AddOrUpdate(i, writeFrameInfo, (seq, checkSum) => { Debug.Fail("Attempt to update checksum."); return new Tuple(0, 0); }); - await client.WriteAsync(writeFrame, 0, writeFrame.Length); - - int delayMilliseconds = rnd.Next(0, 10); - await Task.Delay(delayMilliseconds); + client.WriteAsync(writeFrame, 0, writeFrame.Length).GetAwaiter().GetResult(); + Task.Delay(delayMilliseconds).GetAwaiter().GetResult(); // First read the index to know how much data to read from this frame. var readFrame = new byte[maxFrameSize]; - int readLen = await server.ReadAsync(readFrame, 0, maxFrameSize); + int readLen = server.ReadAsync(readFrame, 0, maxFrameSize).GetAwaiter().GetResult(); int idx = BitConverter.ToInt32(readFrame, 0); Tuple expectedFrameInfo = checksumAndLengths[idx]; diff --git a/src/Common/tests/project.json b/src/Common/tests/project.json index 8dd14f11ed5c..81e545bde10f 100644 --- a/src/Common/tests/project.json +++ b/src/Common/tests/project.json @@ -18,6 +18,7 @@ "System.Runtime.Handles": "4.0.1-rc3-24022-00", "System.Runtime.InteropServices": "4.1.0-rc3-24022-00", "System.Text.RegularExpressions": "4.1.0-rc3-24022-00", + "System.Threading.Thread": "4.0.0-rc3-24022-00", "System.Threading.Tasks": "4.0.11-rc3-24022-00", "System.Threading.Tasks.Parallel": "4.0.1-rc3-24022-00", "xunit": "2.1.0", diff --git a/src/System.Net.Security/System.Net.Security.sln b/src/System.Net.Security/System.Net.Security.sln index 8399699e5451..c4865f92b1b9 100644 --- a/src/System.Net.Security/System.Net.Security.sln +++ b/src/System.Net.Security/System.Net.Security.sln @@ -1,7 +1,7 @@  Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio 14 -VisualStudioVersion = 14.0.24720.0 +VisualStudioVersion = 14.0.25123.0 MinimumVisualStudioVersion = 10.0.40219.1 Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "ref", "ref", "{1B8F56A7-863B-4E11-A882-D83EEA79C997}" EndProject @@ -24,57 +24,57 @@ EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU Unix_Debug|Any CPU = Unix_Debug|Any CPU Unix_Release|Any CPU = Unix_Release|Any CPU - Release|Any CPU = Release|Any CPU Windows_Debug|Any CPU = Windows_Debug|Any CPU Windows_Release|Any CPU = Windows_Release|Any CPU EndGlobalSection GlobalSection(ProjectConfigurationPlatforms) = postSolution {0F78E13E-74EE-40F0-8E0B-A026C7794CCB}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {0F78E13E-74EE-40F0-8E0B-A026C7794CCB}.Debug|Any CPU.Build.0 = Debug|Any CPU + {0F78E13E-74EE-40F0-8E0B-A026C7794CCB}.Release|Any CPU.ActiveCfg = Debug|Any CPU + {0F78E13E-74EE-40F0-8E0B-A026C7794CCB}.Release|Any CPU.Build.0 = Debug|Any CPU {0F78E13E-74EE-40F0-8E0B-A026C7794CCB}.Unix_Debug|Any CPU.ActiveCfg = Debug|Any CPU {0F78E13E-74EE-40F0-8E0B-A026C7794CCB}.Unix_Debug|Any CPU.Build.0 = Debug|Any CPU {0F78E13E-74EE-40F0-8E0B-A026C7794CCB}.Unix_Release|Any CPU.ActiveCfg = Debug|Any CPU {0F78E13E-74EE-40F0-8E0B-A026C7794CCB}.Unix_Release|Any CPU.Build.0 = Debug|Any CPU - {0F78E13E-74EE-40F0-8E0B-A026C7794CCB}.Release|Any CPU.ActiveCfg = Debug|Any CPU - {0F78E13E-74EE-40F0-8E0B-A026C7794CCB}.Release|Any CPU.Build.0 = Debug|Any CPU {0F78E13E-74EE-40F0-8E0B-A026C7794CCB}.Windows_Debug|Any CPU.ActiveCfg = Debug|Any CPU {0F78E13E-74EE-40F0-8E0B-A026C7794CCB}.Windows_Debug|Any CPU.Build.0 = Debug|Any CPU {0F78E13E-74EE-40F0-8E0B-A026C7794CCB}.Windows_Release|Any CPU.ActiveCfg = Debug|Any CPU {0F78E13E-74EE-40F0-8E0B-A026C7794CCB}.Windows_Release|Any CPU.Build.0 = Debug|Any CPU {89F37791-6254-4D60-AB96-ACD3CCA0E771}.Debug|Any CPU.ActiveCfg = Windows_Debug|Any CPU {89F37791-6254-4D60-AB96-ACD3CCA0E771}.Debug|Any CPU.Build.0 = Windows_Debug|Any CPU + {89F37791-6254-4D60-AB96-ACD3CCA0E771}.Release|Any CPU.ActiveCfg = Windows_Release|Any CPU + {89F37791-6254-4D60-AB96-ACD3CCA0E771}.Release|Any CPU.Build.0 = Windows_Release|Any CPU {89F37791-6254-4D60-AB96-ACD3CCA0E771}.Unix_Debug|Any CPU.ActiveCfg = Unix_Debug|Any CPU {89F37791-6254-4D60-AB96-ACD3CCA0E771}.Unix_Debug|Any CPU.Build.0 = Unix_Debug|Any CPU {89F37791-6254-4D60-AB96-ACD3CCA0E771}.Unix_Release|Any CPU.ActiveCfg = Unix_Release|Any CPU {89F37791-6254-4D60-AB96-ACD3CCA0E771}.Unix_Release|Any CPU.Build.0 = Unix_Release|Any CPU - {89F37791-6254-4D60-AB96-ACD3CCA0E771}.Release|Any CPU.ActiveCfg = Windows_Release|Any CPU - {89F37791-6254-4D60-AB96-ACD3CCA0E771}.Release|Any CPU.Build.0 = Windows_Release|Any CPU {89F37791-6254-4D60-AB96-ACD3CCA0E771}.Windows_Debug|Any CPU.ActiveCfg = Windows_Debug|Any CPU {89F37791-6254-4D60-AB96-ACD3CCA0E771}.Windows_Debug|Any CPU.Build.0 = Windows_Debug|Any CPU {89F37791-6254-4D60-AB96-ACD3CCA0E771}.Windows_Release|Any CPU.ActiveCfg = Windows_Release|Any CPU {89F37791-6254-4D60-AB96-ACD3CCA0E771}.Windows_Release|Any CPU.Build.0 = Windows_Release|Any CPU {A55A2B9A-830F-4330-A0E7-02A9FB30ABD2}.Debug|Any CPU.ActiveCfg = Windows_Debug|Any CPU {A55A2B9A-830F-4330-A0E7-02A9FB30ABD2}.Debug|Any CPU.Build.0 = Windows_Debug|Any CPU - {A55A2B9A-830F-4330-A0E7-02A9FB30ABD2}.Unix_Debug|Any CPU.ActiveCfg = Unix_Debug|Any CPU - {A55A2B9A-830F-4330-A0E7-02A9FB30ABD2}.Unix_Debug|Any CPU.Build.0 = Unix_Debug|Any CPU - {A55A2B9A-830F-4330-A0E7-02A9FB30ABD2}.Unix_Release|Any CPU.ActiveCfg = Unix_Release|Any CPU - {A55A2B9A-830F-4330-A0E7-02A9FB30ABD2}.Unix_Release|Any CPU.Build.0 = Unix_Release|Any CPU {A55A2B9A-830F-4330-A0E7-02A9FB30ABD2}.Release|Any CPU.ActiveCfg = Windows_Release|Any CPU {A55A2B9A-830F-4330-A0E7-02A9FB30ABD2}.Release|Any CPU.Build.0 = Windows_Release|Any CPU + {A55A2B9A-830F-4330-A0E7-02A9FB30ABD2}.Unix_Debug|Any CPU.ActiveCfg = OSX_Release|Any CPU + {A55A2B9A-830F-4330-A0E7-02A9FB30ABD2}.Unix_Debug|Any CPU.Build.0 = OSX_Release|Any CPU + {A55A2B9A-830F-4330-A0E7-02A9FB30ABD2}.Unix_Release|Any CPU.ActiveCfg = OSX_Release|Any CPU + {A55A2B9A-830F-4330-A0E7-02A9FB30ABD2}.Unix_Release|Any CPU.Build.0 = OSX_Release|Any CPU {A55A2B9A-830F-4330-A0E7-02A9FB30ABD2}.Windows_Debug|Any CPU.ActiveCfg = Windows_Debug|Any CPU {A55A2B9A-830F-4330-A0E7-02A9FB30ABD2}.Windows_Debug|Any CPU.Build.0 = Windows_Debug|Any CPU {A55A2B9A-830F-4330-A0E7-02A9FB30ABD2}.Windows_Release|Any CPU.ActiveCfg = Windows_Release|Any CPU {A55A2B9A-830F-4330-A0E7-02A9FB30ABD2}.Windows_Release|Any CPU.Build.0 = Windows_Release|Any CPU {0D174EA9-9E61-4519-8D31-7BD2331A1982}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {0D174EA9-9E61-4519-8D31-7BD2331A1982}.Debug|Any CPU.Build.0 = Debug|Any CPU + {0D174EA9-9E61-4519-8D31-7BD2331A1982}.Release|Any CPU.ActiveCfg = Release|Any CPU + {0D174EA9-9E61-4519-8D31-7BD2331A1982}.Release|Any CPU.Build.0 = Release|Any CPU {0D174EA9-9E61-4519-8D31-7BD2331A1982}.Unix_Debug|Any CPU.ActiveCfg = Debug|Any CPU {0D174EA9-9E61-4519-8D31-7BD2331A1982}.Unix_Debug|Any CPU.Build.0 = Debug|Any CPU {0D174EA9-9E61-4519-8D31-7BD2331A1982}.Unix_Release|Any CPU.ActiveCfg = Release|Any CPU {0D174EA9-9E61-4519-8D31-7BD2331A1982}.Unix_Release|Any CPU.Build.0 = Release|Any CPU - {0D174EA9-9E61-4519-8D31-7BD2331A1982}.Release|Any CPU.ActiveCfg = Release|Any CPU - {0D174EA9-9E61-4519-8D31-7BD2331A1982}.Release|Any CPU.Build.0 = Release|Any CPU {0D174EA9-9E61-4519-8D31-7BD2331A1982}.Windows_Debug|Any CPU.ActiveCfg = Debug|Any CPU {0D174EA9-9E61-4519-8D31-7BD2331A1982}.Windows_Debug|Any CPU.Build.0 = Debug|Any CPU {0D174EA9-9E61-4519-8D31-7BD2331A1982}.Windows_Release|Any CPU.ActiveCfg = Release|Any CPU diff --git a/src/System.Net.Security/tests/FunctionalTests/CertificateValidationClientServer.cs b/src/System.Net.Security/tests/FunctionalTests/CertificateValidationClientServer.cs index e0c57bef1088..27718c3e6e1a 100644 --- a/src/System.Net.Security/tests/FunctionalTests/CertificateValidationClientServer.cs +++ b/src/System.Net.Security/tests/FunctionalTests/CertificateValidationClientServer.cs @@ -30,7 +30,6 @@ public CertificateValidationClientServer() [Theory] [InlineData(false)] [InlineData(true)] - [ActiveIssue(4467, PlatformID.Windows)] public async Task CertificateValidationClientServer_EndToEnd_Ok(bool useClientSelectionCallback) { IPEndPoint endPoint = new IPEndPoint(IPAddress.IPv6Loopback, 0); diff --git a/src/System.Net.Security/tests/FunctionalTests/NegotiateStreamStreamToStreamTest.cs b/src/System.Net.Security/tests/FunctionalTests/NegotiateStreamStreamToStreamTest.cs index f77a552ae9e4..cb02714b4301 100644 --- a/src/System.Net.Security/tests/FunctionalTests/NegotiateStreamStreamToStreamTest.cs +++ b/src/System.Net.Security/tests/FunctionalTests/NegotiateStreamStreamToStreamTest.cs @@ -17,7 +17,6 @@ public class NegotiateStreamStreamToStreamTest { private readonly byte[] _sampleMsg = Encoding.UTF8.GetBytes("Sample Test Message"); - [ActiveIssue(5284)] [Fact] public void NegotiateStream_StreamToStream_Authentication_Success() { @@ -69,7 +68,6 @@ public void NegotiateStream_StreamToStream_Authentication_Success() } } - [ActiveIssue(5284)] [Fact] public void NegotiateStream_StreamToStream_Authentication_TargetName_Success() { @@ -124,7 +122,6 @@ public void NegotiateStream_StreamToStream_Authentication_TargetName_Success() } } - [ActiveIssue(5284)] [Fact] public void NegotiateStream_StreamToStream_Authentication_EmptyCredentials_Fails() { @@ -188,7 +185,6 @@ public void NegotiateStream_StreamToStream_Authentication_EmptyCredentials_Fails } } - [ActiveIssue(5283)] [Fact] public void NegotiateStream_StreamToStream_Successive_ClientWrite_Sync_Success() { @@ -222,7 +218,6 @@ public void NegotiateStream_StreamToStream_Successive_ClientWrite_Sync_Success() } } - [ActiveIssue(5284)] [Fact] public void NegotiateStream_StreamToStream_Successive_ClientWrite_Async_Success() { diff --git a/src/System.Net.Security/tests/FunctionalTests/ServerAsyncAuthenticateTest.cs b/src/System.Net.Security/tests/FunctionalTests/ServerAsyncAuthenticateTest.cs index 6606bd342e22..ca82e711f37b 100644 --- a/src/System.Net.Security/tests/FunctionalTests/ServerAsyncAuthenticateTest.cs +++ b/src/System.Net.Security/tests/FunctionalTests/ServerAsyncAuthenticateTest.cs @@ -18,11 +18,13 @@ namespace System.Net.Security.Tests public class ServerAsyncAuthenticateTest { private readonly ITestOutputHelper _log; + private readonly ITestOutputHelper _logVerbose; private readonly X509Certificate2 _serverCertificate; public ServerAsyncAuthenticateTest() { _log = TestLogging.GetInstance(); + _logVerbose = VerboseTestLogging.GetInstance(); _serverCertificate = TestConfiguration.GetServerCertificate(); } @@ -120,8 +122,7 @@ private async Task ServerAsyncSslHelper( Task serverAccept = server.AcceptTcpClientAsync(); // We expect that the network-level connect will always complete. - Task.WaitAll( - new Task[] { clientConnect, serverAccept }, + await Task.WhenAll(new Task[] { clientConnect, serverAccept }).TimeoutAfter( TestConfiguration.PassingTestTimeoutMilliseconds); using (TcpClient serverConnection = await serverAccept) @@ -133,12 +134,14 @@ private async Task ServerAsyncSslHelper( { string serverName = _serverCertificate.GetNameInfo(X509NameType.SimpleName, false); + _logVerbose.WriteLine("ServerAsyncAuthenticateTest.AuthenticateAsClientAsync start."); Task clientAuthentication = sslClientStream.AuthenticateAsClientAsync( serverName, null, clientSslProtocols, false); + _logVerbose.WriteLine("ServerAsyncAuthenticateTest.AuthenticateAsServerAsync start."); Task serverAuthentication = sslServerStream.AuthenticateAsServerAsync( _serverCertificate, true, @@ -147,29 +150,17 @@ private async Task ServerAsyncSslHelper( try { - clientAuthentication.Wait(timeOut); + await clientAuthentication.TimeoutAfter(timeOut); + _logVerbose.WriteLine("ServerAsyncAuthenticateTest.clientAuthentication complete."); } - catch (AggregateException ex) + catch (Exception ex) { // Ignore client-side errors: we're only interested in server-side behavior. - _log.WriteLine("Client exception: " + ex.InnerException); + _log.WriteLine("Client exception: " + ex); } - bool serverAuthenticationCompleted = false; - - try - { - serverAuthenticationCompleted = serverAuthentication.Wait(timeOut); - } - catch (AggregateException ex) - { - ExceptionDispatchInfo.Capture(ex.InnerException).Throw(); - } - - if (!serverAuthenticationCompleted) - { - throw new TimeoutException(); - } + await serverAuthentication.TimeoutAfter(timeOut); + _logVerbose.WriteLine("ServerAsyncAuthenticateTest.serverAuthentication complete."); _log.WriteLine( "Server({0}) authenticated with encryption cipher: {1} {2}-bit strength", diff --git a/src/System.Net.Security/tests/FunctionalTests/SslStreamStreamToStreamTest.cs b/src/System.Net.Security/tests/FunctionalTests/SslStreamStreamToStreamTest.cs index 8ee48bea4990..de322814d4e6 100644 --- a/src/System.Net.Security/tests/FunctionalTests/SslStreamStreamToStreamTest.cs +++ b/src/System.Net.Security/tests/FunctionalTests/SslStreamStreamToStreamTest.cs @@ -17,7 +17,6 @@ public class SslStreamStreamToStreamTest { private readonly byte[] _sampleMsg = Encoding.UTF8.GetBytes("Sample Test Message"); - [ActiveIssue(4467)] [Fact] public void SslStream_StreamToStream_Authentication_Success() { diff --git a/src/System.Net.Security/tests/FunctionalTests/TestConfiguration.cs b/src/System.Net.Security/tests/FunctionalTests/TestConfiguration.cs index 4eda7975f647..5d1495a4c04c 100644 --- a/src/System.Net.Security/tests/FunctionalTests/TestConfiguration.cs +++ b/src/System.Net.Security/tests/FunctionalTests/TestConfiguration.cs @@ -14,7 +14,7 @@ namespace System.Net.Security.Tests { internal static class TestConfiguration { - public const int PassingTestTimeoutMilliseconds = 15 * 1000; + public const int PassingTestTimeoutMilliseconds = 1 * 60 * 1000; public const int FailingTestTimeoutMiliseconds = 250; private const string CertificatePassword = "testcertificate"; diff --git a/src/System.Net.Security/tests/FunctionalTests/unix/project.json b/src/System.Net.Security/tests/FunctionalTests/unix/project.json index 282b7d13f871..502e78b4441c 100644 --- a/src/System.Net.Security/tests/FunctionalTests/unix/project.json +++ b/src/System.Net.Security/tests/FunctionalTests/unix/project.json @@ -16,6 +16,7 @@ "System.Security.Cryptography.X509Certificates": "4.1.0-rc3-24022-00", "System.Security.Principal": "4.0.1-rc3-24022-00", "System.Text.RegularExpressions": "4.1.0-rc3-24022-00", + "System.Threading.Thread": "4.0.0-rc3-24022-00", "System.Resources.ResourceManager": "4.0.1-rc3-24022-00", "xunit": "2.1.0", "xunit.netcore.extensions": "1.0.0-prerelease-00312-04", diff --git a/src/System.Net.Security/tests/FunctionalTests/win/project.json b/src/System.Net.Security/tests/FunctionalTests/win/project.json index 2ae7e6053408..bbee879e63c7 100644 --- a/src/System.Net.Security/tests/FunctionalTests/win/project.json +++ b/src/System.Net.Security/tests/FunctionalTests/win/project.json @@ -13,6 +13,7 @@ "System.Security.Principal": "4.0.1-rc3-24022-00", "System.Security.Principal.Windows": "4.0.0-rc3-24022-00", "System.Text.RegularExpressions": "4.1.0-rc3-24022-00", + "System.Threading.Thread": "4.0.0-rc3-24022-00", "System.Resources.ResourceManager": "4.0.1-rc3-24022-00", "xunit": "2.1.0", "xunit.netcore.extensions": "1.0.0-prerelease-00312-04",