-
Notifications
You must be signed in to change notification settings - Fork 4.9k
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
Enable to playback track 1 session record for track 2 mgmt sdk test cases #11535
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -103,4 +103,4 @@ public void Intercept(IInvocation invocation) | |
} | ||
} | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -74,7 +74,19 @@ public virtual RecordEntry FindMatch(Request request, IList<RecordEntry> entries | |
{ | ||
int score = 0; | ||
|
||
if (!AreUrisSame(entry.RequestUri, uri)) | ||
var recordRequestUri = entry.RequestUri; | ||
if (entry.IsTrack1Recording) | ||
{ | ||
//there's no domain name for request uri in track 1 record, so add it from reqeust uri | ||
int len = 8; //length of "https://" | ||
int domainEndingIndex = uri.IndexOf('/', len); | ||
if (domainEndingIndex > 0) | ||
{ | ||
recordRequestUri = uri.Substring(0, domainEndingIndex) + recordRequestUri; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let's move this logic into RecordEntry.Deserialize this would allow us to drop the additional RequestUri property. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There's no domain name for request uri in track 1 record, so I get domain name from real request uri and add domain name to RequestUri of track 1 for comparison, the problem is we don't know real request uri during de-serializing. Please let me know if I have some misunderstanding. The real request uri: https://xxx.com/subscriptions/xxxx |
||
} | ||
} | ||
|
||
if (!AreUrisSame(recordRequestUri, uri)) | ||
{ | ||
score++; | ||
} | ||
|
@@ -84,7 +96,11 @@ public virtual RecordEntry FindMatch(Request request, IList<RecordEntry> entries | |
score++; | ||
} | ||
|
||
score += CompareHeaderDictionaries(headers, entry.Request.Headers, ExcludeHeaders); | ||
//we only check Uri + RequestMethod for track1 record | ||
if (entry.IsTrack1Recording) | ||
{ | ||
score += CompareHeaderDictionaries(headers, entry.Request.Headers, ExcludeHeaders); | ||
} | ||
|
||
if (score == 0) | ||
{ | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,8 @@ | |
|
||
using System; | ||
using System.IO; | ||
using System.Linq; | ||
using System.Runtime.CompilerServices; | ||
using System.Security.Cryptography; | ||
using System.Text.Json; | ||
using System.Threading; | ||
|
@@ -90,7 +92,15 @@ public TestRandom Random | |
_random = new TestRandom(Mode, seed); | ||
break; | ||
case RecordedTestMode.Playback: | ||
_random = new TestRandom(Mode, int.Parse(_session.Variables[RandomSeedVariableKey])); | ||
if (IsTrack1SessionRecord()) | ||
{ | ||
//random is not really used for track 1 playback, so randomly pick one as seed | ||
_random = new TestRandom(Mode, (int)DateTime.UtcNow.Ticks); | ||
} | ||
else | ||
{ | ||
_random = new TestRandom(Mode, int.Parse(_session.Variables[RandomSeedVariableKey])); | ||
} | ||
break; | ||
default: | ||
throw new ArgumentOutOfRangeException(); | ||
|
@@ -201,6 +211,23 @@ public string GenerateId() | |
return Random.Next().ToString(); | ||
} | ||
|
||
public string GenerateAssetName(string prefix, [CallerMemberName]string callerMethodName = "testframework_failed") | ||
{ | ||
if (Mode == RecordedTestMode.Playback && IsTrack1SessionRecord()) | ||
{ | ||
return _session.Names[callerMethodName].Dequeue(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Who adds items to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. for re-record, the record file will be in track 2 format and Names is obsolete. |
||
} | ||
else | ||
{ | ||
return prefix + Random.Next(9999); | ||
} | ||
} | ||
|
||
public bool IsTrack1SessionRecord() | ||
{ | ||
return _session.Entries.FirstOrDefault()?.IsTrack1Recording ?? false; | ||
} | ||
|
||
public string GetVariable(string variableName, string defaultValue) | ||
{ | ||
switch (Mode) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
are we positive that schema is always https?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the len we used as start index for searching "/" to get end index of domain name, so 8 is good here even for http://