Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
JamesNK committed May 9, 2024
1 parent 67b4997 commit 7c05f97
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
15 changes: 12 additions & 3 deletions src/Servers/Kestrel/Core/test/Http1/Http1OutputProducerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -117,9 +117,10 @@ public async Task FlushAsync_OnSocketWithCanceledPendingFlush_ReturnsResultWithI
[Fact]
public void AbortsTransportEvenAfterDispose()
{
var metricsTagsFeature = new TestConnectionMetricsTagsFeature();
var mockConnectionContext = new Mock<ConnectionContext>();

var outputProducer = CreateOutputProducer(connectionContext: mockConnectionContext.Object);
var outputProducer = CreateOutputProducer(connectionContext: mockConnectionContext.Object, metricsTagsFeature: metricsTagsFeature);

outputProducer.Dispose();

Expand All @@ -132,6 +133,8 @@ public void AbortsTransportEvenAfterDispose()
outputProducer.Abort(null, ConnectionEndReason.AbortedByApplication);

mockConnectionContext.Verify(f => f.Abort(null), Times.Once());

Assert.Equal(nameof(ConnectionEndReason.AbortedByApplication), metricsTagsFeature.Tags.Single(t => t.Key == KestrelMetrics.KestrelConnectionEndReason).Value);
}

[Fact]
Expand Down Expand Up @@ -219,7 +222,8 @@ public void ReusesFakeMemory()

private TestHttpOutputProducer CreateOutputProducer(
PipeOptions pipeOptions = null,
ConnectionContext connectionContext = null)
ConnectionContext connectionContext = null,
IConnectionMetricsTagsFeature metricsTagsFeature = null)
{
pipeOptions = pipeOptions ?? new PipeOptions();
connectionContext = connectionContext ?? Mock.Of<ConnectionContext>();
Expand All @@ -234,12 +238,17 @@ public void ReusesFakeMemory()
serviceContext.Log,
Mock.Of<ITimeoutControl>(),
Mock.Of<IHttpMinResponseDataRateFeature>(),
Mock.Of<IConnectionMetricsTagsFeature>(),
metricsTagsFeature ?? new TestConnectionMetricsTagsFeature(),
Mock.Of<IHttpOutputAborter>());

return socketOutput;
}

private class TestConnectionMetricsTagsFeature : IConnectionMetricsTagsFeature
{
public ICollection<KeyValuePair<string, object>> Tags { get; } = new List<KeyValuePair<string, object>>();
}

private class TestHttpOutputProducer : Http1OutputProducer
{
public TestHttpOutputProducer(Pipe pipe, string connectionId, ConnectionContext connectionContext, MemoryPool<byte> memoryPool, KestrelTrace log, ITimeoutControl timeoutControl, IHttpMinResponseDataRateFeature minResponseDataRateFeature, IConnectionMetricsTagsFeature metricsTagsFeature, IHttpOutputAborter outputAborter)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2139,7 +2139,7 @@ public async Task UnexpectedServerFrame(string frameType)
expectedLastStreamId: null,
Http3ErrorCode.UnexpectedFrame,
null);
Assert.Equal(nameof(ConnectionEndReason.UnexpectedFrame), Http3Api.ConnectionTags[KestrelMetrics.KestrelConnectionEndReason]);
Assert.Equal(nameof(ConnectionEndReason.UnsupportedFrame), Http3Api.ConnectionTags[KestrelMetrics.KestrelConnectionEndReason]);
}

[Fact]
Expand Down

0 comments on commit 7c05f97

Please sign in to comment.