diff --git a/build.fsx b/build.fsx index 829675e4..bbfa72f8 100644 --- a/build.fsx +++ b/build.fsx @@ -218,11 +218,9 @@ Target "RunTests" (fun _ -> | true -> !! "./test/*.Tests/*.Tests.csproj" -- "./test/*.Tests/DotNetty.Transport.Tests.csproj" -- "./test/*.Tests/DotNetty.Suite.Tests.csproj" - -- "./test/*.Tests/DotNetty.Handlers.Proxy.Tests.csproj" | _ -> !! "./test/*.Tests/*.Tests.csproj" // if you need to filter specs for Linux vs. Windows, do it here -- "./test/*.Tests/DotNetty.Transport.Tests.csproj" -- "./test/*.Tests/DotNetty.Suite.Tests.csproj" - -- "./test/*.Tests/DotNetty.Handlers.Proxy.Tests.csproj" -- "./test/*.Tests/DotNetty.End2End.Tests.csproj" rawProjects |> Seq.choose filterProjects @@ -230,7 +228,7 @@ Target "RunTests" (fun _ -> let arguments = match (hasTeamCity) with | true -> (sprintf "test -c %s --no-build --logger:trx --logger:\"console;verbosity=normal\" --framework %s -- RunConfiguration.TargetPlatform=x64 --results-directory \"%s\" -- -parallel none -teamcity" configuration testNetVersion outputTests) - | false -> (sprintf "test -c %s --no-build --logger:trx --logger:\"console;verbosity=normal\" --framework %s -- RunConfiguration.TargetPlatform=x64 --results-directory \"%s\" -- -parallel none" configuration testNetVersion outputTests) + | false -> (sprintf "test -c %s --no-build --filter \"FullyQualifiedName=DotNetty.Handlers.Proxy.Tests.ProxyHandlerTest.Test\" --logger:trx --logger:\"console;verbosity=normal\" --framework %s -- RunConfiguration.TargetPlatform=x64 --results-directory \"%s\" -- -parallel none" configuration testNetVersion outputTests) let result = ExecProcess(fun info -> info.FileName <- "dotnet" diff --git a/src/DotNetty.Handlers.Proxy/ProxyHandler.cs b/src/DotNetty.Handlers.Proxy/ProxyHandler.cs index 5ddbf8f3..6730d757 100644 --- a/src/DotNetty.Handlers.Proxy/ProxyHandler.cs +++ b/src/DotNetty.Handlers.Proxy/ProxyHandler.cs @@ -205,13 +205,19 @@ void ConnectTimeout() /// Sends the specified message to the proxy server. Use this method to send a response to the proxy server in /// {@link #handleResponse(IChannelHandlerContext, object)}. /// - protected void SendToProxyServer(object msg) + protected async Task SendToProxyServer(object msg) { - _ctx.WriteAndFlushAsync(msg).ContinueWith(OnCompleted, TaskContinuationOptions.NotOnRanToCompletion | TaskContinuationOptions.ExecuteSynchronously); - - void OnCompleted(Task future) + try + { + await _ctx.WriteAndFlushAsync(msg); + if (Logger.DebugEnabled) + { + Logger.Debug($"Connect sent to {_destinationAddress}."); + } + } + catch (Exception ex) { - SetConnectFailure(future.Exception); + SetConnectFailure(ex); } } diff --git a/test/DotNetty.Handlers.Proxy.Tests/HttpProxyHandlerTest.cs b/test/DotNetty.Handlers.Proxy.Tests/HttpProxyHandlerTest.cs index 62641fce..eb263299 100644 --- a/test/DotNetty.Handlers.Proxy.Tests/HttpProxyHandlerTest.cs +++ b/test/DotNetty.Handlers.Proxy.Tests/HttpProxyHandlerTest.cs @@ -15,7 +15,7 @@ namespace DotNetty.Handlers.Proxy.Tests { - /* + public class HttpProxyHandlerTest { [Fact(Timeout = 5000)] @@ -274,5 +274,5 @@ public InactiveEmbeddedChannel(params IChannelHandler[] handlers) public override bool IsActive => false; } - }*/ + } } \ No newline at end of file diff --git a/test/DotNetty.Handlers.Proxy.Tests/HttpProxyServer.cs b/test/DotNetty.Handlers.Proxy.Tests/HttpProxyServer.cs index 198ae0eb..c7c30b77 100644 --- a/test/DotNetty.Handlers.Proxy.Tests/HttpProxyServer.cs +++ b/test/DotNetty.Handlers.Proxy.Tests/HttpProxyServer.cs @@ -4,6 +4,7 @@ using DotNetty.Codecs; using DotNetty.Codecs.Base64; using DotNetty.Codecs.Http; +using DotNetty.Handlers.Logging; using DotNetty.Transport.Channels; using DotNetty.Transport.Channels.Sockets; using Xunit; @@ -36,6 +37,7 @@ protected override void Configure(ISocketChannel ch) case TestMode.Terminal: p.AddLast(new HttpServerCodec()); p.AddLast(new HttpObjectAggregator(1)); + p.AddLast(new LoggingHandler("proxy")); p.AddLast(new HttpTerminalHandler(this)); break; case TestMode.Unresponsive: diff --git a/test/DotNetty.Handlers.Proxy.Tests/ProxyHandlerTest.cs b/test/DotNetty.Handlers.Proxy.Tests/ProxyHandlerTest.cs index 366f0cf7..3a2fb395 100644 --- a/test/DotNetty.Handlers.Proxy.Tests/ProxyHandlerTest.cs +++ b/test/DotNetty.Handlers.Proxy.Tests/ProxyHandlerTest.cs @@ -5,17 +5,16 @@ using System.Net.Security; using System.Text; using System.Threading; -using System.Threading.Tasks; using DotNetty.Buffers; using DotNetty.Codecs; using DotNetty.Common.Internal.Logging; using DotNetty.Common.Utilities; +using DotNetty.Handlers.Logging; using DotNetty.Handlers.Tls; using DotNetty.Tests.Common; using DotNetty.Transport.Bootstrapping; using DotNetty.Transport.Channels; using DotNetty.Transport.Channels.Sockets; -using Microsoft.Extensions.Logging; using Xunit; using Xunit.Abstractions; using Xunit.Sdk; @@ -90,7 +89,7 @@ public ProxyHandlerTest(ITestOutputHelper output) : base(output) [MemberData(nameof(CreateTestItems))] public void Test(TestItem item) { - item.Test(); + item.Test(this.Output); } public void Dispose() @@ -121,13 +120,10 @@ public static List CreateTestItems() BAD_DESTINATION, "status: 403", new HttpProxyHandler(AnonHttpProxy.Address)), - /* - Note: Test keeps failing and Tom/Max agreed to skip it for now new FailureTestItem( "HTTP proxy: rejected anonymous connection", DESTINATION, "status: 401", new HttpProxyHandler(HttpProxy.Address)), - */ new SuccessTestItem( "HTTP proxy: successful connection, AUTO_READ on", @@ -171,14 +167,11 @@ public static List CreateTestItems() CreateClientTlsHandler(), new HttpProxyHandler(AnonHttpsProxy.Address)), - /* - Note: Test keeps failing and Tom/Max agreed to skip it for now new FailureTestItem( "Anonymous HTTPS proxy: rejected connection", BAD_DESTINATION, "status: 403", CreateClientTlsHandler(), new HttpProxyHandler(AnonHttpsProxy.Address)), - */ new FailureTestItem( "HTTPS proxy: rejected anonymous connection", @@ -378,6 +371,18 @@ public static List CreateTestItems() */ }; + items = Enumerable.Range(0, 100).Select(_ => + new SuccessTestItem( + "HTTPS proxy: successful connection, AUTO_READ on", + DESTINATION, + true, + new LoggingHandler("client-tcp"), + CreateClientTlsHandler(), + new LoggingHandler("client-tls"), + new HttpProxyHandler(HttpsProxy.Address, USERNAME, PASSWORD), + new LoggingHandler("client-proxy") + )).Cast().ToList(); + // Convert the test items to the list of constructor parameters. var parameters = new List(items.Count); foreach (var i in items) @@ -516,7 +521,7 @@ protected TestItem(string name, EndPoint destination, params IChannelHandler[] c ClientHandlers = clientHandlers; } - public abstract void Test(); + public abstract void Test(ITestOutputHelper output); protected void AssertProxyHandlers(bool success) { @@ -585,7 +590,7 @@ internal SuccessTestItem(string name, _autoRead = autoRead; } - public override void Test() + public override void Test(ITestOutputHelper output) { var testHandler = new SuccessTestHandler(); var b = new Bootstrap() @@ -604,7 +609,8 @@ public override void Test() var channel = b.ConnectAsync(Destination).Result; var finished = channel.CloseCompletion.Wait(TimeSpan.FromSeconds(10)); - + Assert.True(finished); + Logger.Debug("Received messages: {0}", testHandler.Received); if (testHandler.Exceptions.Count == 0) @@ -618,7 +624,6 @@ public override void Test() Assert.Equal(testHandler.Received, new object[] {"0", "1", "2", "3"}); Assert.Empty(testHandler.Exceptions); Assert.Equal(testHandler.EventCount, _expectedEventCount); - Assert.True(finished); } } @@ -633,7 +638,7 @@ internal FailureTestItem( _expectedMessage = expectedMessage; } - public override void Test() + public override void Test(ITestOutputHelper output) { var testHandler = new FailureTestHandler(); var b = new Bootstrap(); @@ -671,7 +676,7 @@ internal TimeoutTestItem(string name, params IChannelHandler[] clientHandlers) { } - public override void Test() + public override void Test(ITestOutputHelper output) { const long timeout = 2000; foreach (var h in ClientHandlers) diff --git a/test/DotNetty.Handlers.Proxy.Tests/ProxyServer.cs b/test/DotNetty.Handlers.Proxy.Tests/ProxyServer.cs index e9a9de37..5df85805 100644 --- a/test/DotNetty.Handlers.Proxy.Tests/ProxyServer.cs +++ b/test/DotNetty.Handlers.Proxy.Tests/ProxyServer.cs @@ -277,7 +277,10 @@ protected override void ChannelRead0(IChannelHandlerContext ctx, object msg) else if ("C\n".Equals(str)) { ctx.WriteAsync(Unpooled.CopiedBuffer("3\n", Encoding.ASCII)) - .ContinueWith(_ => ctx.Channel.CloseAsync(), TaskContinuationOptions.ExecuteSynchronously); + .ContinueWith(_ => + { + return ctx.Channel.CloseAsync(); + }, TaskContinuationOptions.ExecuteSynchronously); } else {