Skip to content
代码片段 群组 项目
未验证 提交 82629def 编辑于 作者: Chris Ross's avatar Chris Ross 提交者: GitHub
浏览文件

Fix multiple dictionary add in polly (#37537)

上级 a48a0be0
No related branches found
No related tags found
无相关合并请求
......@@ -169,7 +169,7 @@ namespace Microsoft.Extensions.Http
var result = await base.SendAsync(request, cancellationToken);
request.Properties.Add(PriorResponseKey, result);
request.Properties[PriorResponseKey] = result;
return result;
}
......
......@@ -147,6 +147,58 @@ namespace Microsoft.Extensions.Http
Assert.True(fakeContent.Disposed);
}
[Fact]
public async Task MultipleHandlers_CanReexecuteSendAsync_FirstResponseDisposed()
{
// Arrange
var policy1 = HttpPolicyExtensions.HandleTransientHttpError()
.RetryAsync(retryCount: 1);
var policy2 = HttpPolicyExtensions.HandleTransientHttpError()
.CircuitBreakerAsync(handledEventsAllowedBeforeBreaking: 2, durationOfBreak: TimeSpan.FromSeconds(10));
var callCount = 0;
var fakeContent = new FakeContent();
var firstResponse = new HttpResponseMessage()
{
StatusCode = System.Net.HttpStatusCode.InternalServerError,
Content = fakeContent,
};
var expected = new HttpResponseMessage();
var handler1 = new PolicyHttpMessageHandler(policy1);
var handler2 = new PolicyHttpMessageHandler(policy2);
handler1.InnerHandler = handler2;
handler2.InnerHandler = new TestHandler()
{
OnSendAsync = (req, ct) =>
{
if (callCount == 0)
{
callCount++;
return Task.FromResult(firstResponse);
}
else if (callCount == 1)
{
callCount++;
return Task.FromResult(expected);
}
else
{
throw new InvalidOperationException();
}
}
};
var invoke = new HttpMessageInvoker(handler1);
// Act
var response = await invoke.SendAsync(new HttpRequestMessage(), CancellationToken.None);
// Assert
Assert.Equal(2, callCount);
Assert.Same(expected, response);
Assert.True(fakeContent.Disposed);
}
[Fact]
public async Task SendAsync_DynamicPolicy_PolicySelectorReturnsNull_ThrowsException()
{
......
0% 加载中 .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册