Skip to content

Commit

Permalink
http test fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
maksimkim committed Oct 10, 2018
1 parent 6b941c9 commit 1236174
Show file tree
Hide file tree
Showing 7 changed files with 33 additions and 38 deletions.
2 changes: 1 addition & 1 deletion src/DotNetty.Buffers/DotNetty.Buffers.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,6 @@
<Reference Include="Microsoft.CSharp" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="System.Runtime.CompilerServices.Unsafe" Version="4.5.2" />
<PackageReference Include="System.Runtime.CompilerServices.Unsafe" Version="4.5.1" />
</ItemGroup>
</Project>
2 changes: 1 addition & 1 deletion src/DotNetty.Codecs.Http/DotNetty.Codecs.Http.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
<Compile Include="..\shared\SharedAssemblyInfo.cs" Link="Properties\SharedAssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="System.Runtime.CompilerServices.Unsafe" Version="4.5.2" />
<PackageReference Include="System.Runtime.CompilerServices.Unsafe" Version="4.5.1" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\DotNetty.Common\DotNetty.Common.csproj" />
Expand Down
50 changes: 22 additions & 28 deletions src/DotNetty.Codecs.Http/HttpServerUpgradeHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -254,34 +254,28 @@ bool Upgrade(IChannelHandlerContext ctx, IFullHttpRequest request)
var upgradeEvent = new UpgradeEvent(upgradeProtocol, request);

IUpgradeCodec finalUpgradeCodec = upgradeCodec;
ctx.WriteAndFlushAsync(upgradeResponse).ContinueWith(t =>
{
try
{
if (t.Status == TaskStatus.RanToCompletion)
{
// Perform the upgrade to the new protocol.
this.sourceCodec.UpgradeFrom(ctx);
finalUpgradeCodec.UpgradeTo(ctx, request);
// Notify that the upgrade has occurred. Retain the event to offset
// the release() in the finally block.
ctx.FireUserEventTriggered(upgradeEvent.Retain());
// Remove this handler from the pipeline.
ctx.Channel.Pipeline.Remove(this);
}
else
{
ctx.Channel.CloseAsync();
}
}
finally
{
// Release the event if the upgrade event wasn't fired.
upgradeEvent.Release();
}
}, TaskContinuationOptions.ExecuteSynchronously);
try
{
Task writeTask = ctx.WriteAndFlushAsync(upgradeResponse);

// Perform the upgrade to the new protocol.
this.sourceCodec.UpgradeFrom(ctx);
finalUpgradeCodec.UpgradeTo(ctx, request);

// Remove this handler from the pipeline.
ctx.Channel.Pipeline.Remove(this);

// Notify that the upgrade has occurred. Retain the event to offset
// the release() in the finally block.
ctx.FireUserEventTriggered(upgradeEvent.Retain());

writeTask.CloseOnFailure(ctx.Channel);
}
finally
{
// Release the event if the upgrade event wasn't fired.
upgradeEvent.Release();
}
return true;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ public override ValueTask WriteAsync(IChannelHandlerContext ctx, object msg)
}

Task task = base.WriteAsync(ctx, msg).AsTask();
task.ContinueWith(this.upgradeCompletedContinuation, ctx);
task.ContinueWith(this.upgradeCompletedContinuation, ctx, TaskContinuationOptions.ExecuteSynchronously);
return new ValueTask(task);
}

Expand Down
3 changes: 3 additions & 0 deletions src/DotNetty.Codecs/TaskExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ public static Task CloseOnComplete(this Task task, IChannel channel)

public static Task CloseOnFailure(this Task task, IChannelHandlerContext ctx)
=> task.ContinueWith(CloseOnFailureContinuation, ctx, TaskContinuationOptions.ExecuteSynchronously);

public static Task CloseOnFailure(this Task task, IChannel channel)
=> task.ContinueWith(CloseOnFailureContinuation, channel, TaskContinuationOptions.ExecuteSynchronously);

static Task Close(Task task, object state)
{
Expand Down
2 changes: 1 addition & 1 deletion src/DotNetty.Common/DotNetty.Common.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Logging" Version="1.1.1" />
<PackageReference Include="System.Runtime.CompilerServices.Unsafe" Version="4.5.2" />
<PackageReference Include="System.Runtime.CompilerServices.Unsafe" Version="4.5.1" />
<PackageReference Include="System.Threading.Tasks.Extensions" Version="4.5.1" />
</ItemGroup>
<ItemGroup Condition=" '$(TargetFramework)' == 'netstandard1.3' ">
Expand Down
10 changes: 4 additions & 6 deletions test/DotNetty.Codecs.Http.Tests/HttpServerUpgradeHandlerTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@ public override void ChannelRead(IChannelHandlerContext ctx, object msg)
// written the upgrade response, and upgraded the pipeline.
Assert.True(this.writeUpgradeMessage);
Assert.False(this.writeFlushed);
//Assert.Null(ctx.Channel.Pipeline.Get<HttpServerCodec>());
//Assert.NotNull(ctx.Channel.Pipeline.Get("marker"));
Assert.Null(ctx.Channel.Pipeline.Get<HttpServerCodec>());
Assert.NotNull(ctx.Channel.Pipeline.Get("marker"));
}
finally
{
Expand Down Expand Up @@ -111,13 +111,11 @@ public void UpgradesPipelineInSameMethodInvocation()
IByteBuffer upgrade = Unpooled.CopiedBuffer(Encoding.ASCII.GetBytes(UpgradeString));

Assert.False(channel.WriteInbound(upgrade));
//Assert.Null(channel.Pipeline.Get<HttpServerCodec>());
//Assert.NotNull(channel.Pipeline.Get("marker"));

channel.Flush();
Assert.Null(channel.Pipeline.Get<HttpServerCodec>());
Assert.NotNull(channel.Pipeline.Get("marker"));

channel.Flush();

var upgradeMessage = channel.ReadOutbound<IByteBuffer>();
const string ExpectedHttpResponse = "HTTP/1.1 101 Switching Protocols\r\n" +
"connection: upgrade\r\n" +
Expand Down

0 comments on commit 1236174

Please sign in to comment.