Skip to content

Commit d180c5c

Browse files
committed
Make running kiota tests faster by turning off default handlers (such as retries)
1 parent 23be010 commit d180c5c

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

test/OpenApiKiotaEndToEndTests/TestableHttpClientRequestAdapterFactory.cs

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,17 @@
22
using Microsoft.AspNetCore.Mvc.Testing;
33
using Microsoft.Kiota.Abstractions.Authentication;
44
using Microsoft.Kiota.Http.HttpClientLibrary;
5+
using Microsoft.Kiota.Http.HttpClientLibrary.Middleware;
56
using TestBuildingBlocks;
67
using Xunit.Abstractions;
78

89
namespace OpenApiKiotaEndToEndTests;
910

1011
internal sealed class TestableHttpClientRequestAdapterFactory : IDisposable
1112
{
12-
private readonly XUnitLogHttpMessageHandler _logHttpMessageHandler;
13+
private readonly HeadersInspectionHandler _headersInspectionHandler = new();
1314
private readonly SetQueryStringHttpMessageHandler _queryStringMessageHandler = new();
15+
private readonly XUnitLogHttpMessageHandler _logHttpMessageHandler;
1416

1517
public TestableHttpClientRequestAdapterFactory(ITestOutputHelper testOutputHelper)
1618
{
@@ -24,11 +26,14 @@ public HttpClientRequestAdapter CreateAdapter<TStartup>(WebApplicationFactory<TS
2426
{
2527
ArgumentNullException.ThrowIfNull(webApplicationFactory);
2628

27-
IList<DelegatingHandler> delegatingHandlers = KiotaClientFactory.CreateDefaultHandlers();
28-
delegatingHandlers.Add(_queryStringMessageHandler);
29-
delegatingHandlers.Add(_logHttpMessageHandler);
30-
HttpClient httpClient = webApplicationFactory.CreateDefaultClient(delegatingHandlers.ToArray());
29+
DelegatingHandler[] handlers =
30+
[
31+
_headersInspectionHandler,
32+
_queryStringMessageHandler,
33+
_logHttpMessageHandler
34+
];
3135

36+
HttpClient httpClient = webApplicationFactory.CreateDefaultClient(handlers);
3237
return new HttpClientRequestAdapter(new AnonymousAuthenticationProvider(), httpClient: httpClient);
3338
}
3439

0 commit comments

Comments
 (0)