Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding Support to override the ClientRequestID guid format for test recording sessions. #39133

Merged
merged 13 commits into from
Oct 9, 2023
11 changes: 9 additions & 2 deletions sdk/core/Azure.Core.TestFramework/src/ProxyTransport.cs
Original file line number Diff line number Diff line change
Expand Up @@ -135,8 +135,15 @@ public override Request CreateRequest()
_recording.HasRequests = true;
lock (_recording.Random)
{
// Make sure ClientRequestId are the same across request and response
request.ClientRequestId = _recording.Random.NewGuid().ToString("N");
if (_recording.UseDefaultClientRequestIdFormat)
{
// User want the client format to use the default format
request.ClientRequestId = _recording.Random.NewGuid().ToString();
}else
wiboris marked this conversation as resolved.
Show resolved Hide resolved
{
// Make sure ClientRequestId are the same across request and response
request.ClientRequestId = _recording.Random.NewGuid().ToString("N");
}
}
return request;
}
Expand Down
6 changes: 6 additions & 0 deletions sdk/core/Azure.Core.TestFramework/src/RecordedTestBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,12 @@ public string ReplacementHost
/// </summary>
public bool CompareBodies { get; set; } = true;

/// <summary>
/// Determines if during test recording if we should use the default guid format for clientID.
wiboris marked this conversation as resolved.
Show resolved Hide resolved
/// The default value is <value>false</value>.
/// </summary>
public bool UseDefaultClientRequestIdFormat { get; set; } = false;
wiboris marked this conversation as resolved.
Show resolved Hide resolved

/// <summary>
/// Request headers whose values can change between recording and playback without causing request matching
/// to fail. The presence or absence of the header itself is still respected in matching.
Expand Down
37 changes: 37 additions & 0 deletions sdk/core/Azure.Core.TestFramework/src/TestRecording.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ namespace Azure.Core.TestFramework
public class TestRecording : IAsyncDisposable
{
private const string RandomSeedVariableKey = "RandomSeed";
private const string DefaultClientGuidFormatInRecordingKey = "DefaultClientGuidFormatInRecording";
private const string chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
// cspell: disable-next-line
private const string charsLower = "abcdefghijklmnopqrstuvwxyz0123456789";
Expand Down Expand Up @@ -199,6 +200,42 @@ public TestRandom Random

public string RecordingId { get; private set; }

private bool _useDefaultClientRequestIdFormat;

/// <summary>
/// Retrieves the value for the enviroment variable RECORDING_DEFAULT_ClIENT_GUID
/// </summary>
public bool UseDefaultClientRequestIdFormat
wiboris marked this conversation as resolved.
Show resolved Hide resolved
{
get
{
switch (Mode)
{
case RecordedTestMode.Live:
_useDefaultClientRequestIdFormat = false;
break;
case RecordedTestMode.Record:
_useDefaultClientRequestIdFormat = _recordedTestBase.UseDefaultClientRequestIdFormat;
Variables[DefaultClientGuidFormatInRecordingKey] = _useDefaultClientRequestIdFormat.ToString();
break;
case RecordedTestMode.Playback:
ValidateVariables();
try
{
_useDefaultClientRequestIdFormat = bool.Parse(Variables[DefaultClientGuidFormatInRecordingKey]);
}
catch (System.Collections.Generic.KeyNotFoundException)
{
_useDefaultClientRequestIdFormat = false;
}
break;
default:
throw new ArgumentOutOfRangeException();
}
return _useDefaultClientRequestIdFormat;
}
}

/// <summary>
/// Gets the moment in time that this test is being run. This is useful
/// for any test recordings that capture the current time.
Expand Down
Loading