Skip to content

Commit 6bed92f

Browse files
committed
add adjustments for PlaybackResponseTime
1 parent 5ba9d1d commit 6bed92f

3 files changed

Lines changed: 38 additions & 5 deletions

File tree

tools/test-proxy/Azure.Sdk.Tools.TestProxy/Common/ModifiableRecordSession.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using System;
1+
using System;
22
using System.Collections.Generic;
33
using System.Linq;
44
using System.Net.Http;
@@ -27,6 +27,8 @@ public ModifiableRecordSession(RecordSession session)
2727

2828
public string SourceRecordingId { get; set; }
2929

30+
public int PlaybackResponseTime { get; set; }
31+
3032
public void ResetExtensions()
3133
{
3234
AdditionalTransforms.Clear();

tools/test-proxy/Azure.Sdk.Tools.TestProxy/Common/TransportCustomizations.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,5 +31,11 @@ public class TransportCustomizations
3131
/// Each certificate pair contained within this list should be added to the clientHandler for the server or an individual recording.
3232
/// </summary>
3333
public List<PemPair> Certificates { get; set; }
34+
35+
/// <summary>
36+
/// During playack, a response is normally returned all at once. By offering this response time, we can
37+
/// "stretch" the writing of the response bytes over a time range of milliseconds.
38+
/// </summary>
39+
public int PlaybackResponseTime { get; set; } = 0;
3440
}
3541
}

tools/test-proxy/Azure.Sdk.Tools.TestProxy/RecordingHandler.cs

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
using Azure.Sdk.Tools.TestProxy.Vendored;
88
using Microsoft.AspNetCore.Http;
99
using Microsoft.AspNetCore.Http.Features;
10+
using Microsoft.AspNetCore.Server.Kestrel.Core.Features;
1011
using Microsoft.Extensions.Primitives;
1112
using System;
1213
using System.Collections.Concurrent;
@@ -466,10 +467,15 @@ public async Task HandlePlaybackRequest(string recordingId, HttpRequest incoming
466467

467468
outgoingResponse.ContentLength = bodyData.Length;
468469

469-
await outgoingResponse.Body.WriteAsync(bodyData).ConfigureAwait(false);
470+
await WriteBodyBytes(bodyData, session.PlaybackResponseTime, outgoingResponse);
470471
}
471472
}
472473

474+
public async Task WriteBodyBytes(byte[] bodyData, int playbackResponseTime, HttpResponse outgoingResponse)
475+
{
476+
await outgoingResponse.Body.WriteAsync(bodyData).ConfigureAwait(false);
477+
}
478+
473479
public static async Task<(RecordEntry, byte[])> CreateEntryAsync(HttpRequest request)
474480
{
475481
var entry = new RecordEntry();
@@ -710,10 +716,29 @@ public void SetTransportOptions(TransportCustomizations customizations, string s
710716
{
711717
var customizedClientHandler = GetTransport(customizations.AllowAutoRedirect, customizations);
712718

713-
RecordingSessions[sessionId].Client = new HttpClient(customizedClientHandler)
719+
if (RecordingSessions.TryGetValue(sessionId, out var recordingSession))
714720
{
715-
Timeout = timeoutSpan
716-
};
721+
recordingSession.Client = new HttpClient(customizedClientHandler)
722+
{
723+
Timeout = timeoutSpan
724+
};
725+
}
726+
else
727+
{
728+
throw new HttpException(HttpStatusCode.BadRequest, $"Unable to set a transport customization on a recording session that is not active. Id: \"{sessionId}\"");
729+
}
730+
731+
if (customizations.PlaybackResponseTime > 0)
732+
{
733+
if (PlaybackSessions.TryGetValue(sessionId, out var playbackSession))
734+
{
735+
playbackSession.PlaybackResponseTime = customizations.PlaybackResponseTime;
736+
}
737+
else
738+
{
739+
throw new HttpException(HttpStatusCode.BadRequest, $"Unable to set a transport customization on a recording session that is not active. Id: \"{sessionId}\"");
740+
}
741+
}
717742
}
718743
else
719744
{

0 commit comments

Comments
 (0)