use a more realistic network delay simulation

pull/178/head
Chet Husk 2022-11-03 15:40:24 -05:00
parent 255a77456f
commit a4b55f5f3a
2 changed files with 12 additions and 1 deletions

View File

@ -7,6 +7,17 @@ using Podcast.Infrastructure.Data.Models;
namespace Podcast.Infrastructure.Http.Feeds;
public class JitterHandler : DelegatingHandler
{
protected override async Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
{
// Who would do such a thing?!
// TODO fix this horrible perf leak!
await Task.Delay(TimeSpan.FromSeconds(Random.Shared.NextInt64()));
return await base.SendAsync(request, cancellationToken);
}
}
public class FeedClient : IFeedClient
{
private static readonly XmlSerializer XmlSerializer = new(typeof(Rss));

View File

@ -17,7 +17,7 @@ var connectionString = builder.Configuration.GetConnectionString("PodcastDb")!;
builder.Services.AddSqlServer<PodcastDbContext>(connectionString);
var queueConnectionString = builder.Configuration.GetConnectionString("FeedQueue");
builder.Services.AddSingleton(new QueueClient(queueConnectionString, "feed-queue"));
builder.Services.AddHttpClient<IFeedClient, FeedClient>();
builder.Services.AddHttpClient<IFeedClient, FeedClient>().AddHttpMessageHandler<JitterHandler>();
// Authentication and authorization-related services
builder.Services.AddAuthentication().AddJwtBearer();