Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
4 changes: 1 addition & 3 deletions build.fsx
Original file line number Diff line number Diff line change
Expand Up @@ -218,19 +218,17 @@ 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

let runSingleProject project =
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"
Expand Down
16 changes: 11 additions & 5 deletions src/DotNetty.Handlers.Proxy/ProxyHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)}.
/// </summary>
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);
}
}

Expand Down
4 changes: 2 additions & 2 deletions test/DotNetty.Handlers.Proxy.Tests/HttpProxyHandlerTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

namespace DotNetty.Handlers.Proxy.Tests
{
/*

public class HttpProxyHandlerTest
{
[Fact(Timeout = 5000)]
Expand Down Expand Up @@ -274,5 +274,5 @@ public InactiveEmbeddedChannel(params IChannelHandler[] handlers)

public override bool IsActive => false;
}
}*/
}
}
2 changes: 2 additions & 0 deletions test/DotNetty.Handlers.Proxy.Tests/HttpProxyServer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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:
Expand Down
35 changes: 20 additions & 15 deletions test/DotNetty.Handlers.Proxy.Tests/ProxyHandlerTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -121,13 +120,10 @@ public static List<object[]> 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",
Expand Down Expand Up @@ -171,14 +167,11 @@ public static List<object[]> 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",
Expand Down Expand Up @@ -378,6 +371,18 @@ public static List<object[]> 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<TestItem>().ToList();

// Convert the test items to the list of constructor parameters.
var parameters = new List<object[]>(items.Count);
foreach (var i in items)
Expand Down Expand Up @@ -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)
{
Expand Down Expand Up @@ -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()
Expand All @@ -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)
Expand All @@ -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);
}
}

Expand All @@ -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();
Expand Down Expand Up @@ -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)
Expand Down
5 changes: 4 additions & 1 deletion test/DotNetty.Handlers.Proxy.Tests/ProxyServer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down