From cae1a10f2fac20223271d245df3f4c4c3a7b812a Mon Sep 17 00:00:00 2001 From: Bill Wert Date: Fri, 14 Jul 2023 11:41:36 -0700 Subject: [PATCH 1/5] Return record file location when playback starts Some tests have a need to parse data out of their recordings. When playback is started for a disk based recording, include a new header x-recording-file-location on the response which points to the recording. --- .../test-proxy/Azure.Sdk.Tools.TestProxy.Tests/PlaybackTests.cs | 2 ++ tools/test-proxy/Azure.Sdk.Tools.TestProxy/RecordingHandler.cs | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/tools/test-proxy/Azure.Sdk.Tools.TestProxy.Tests/PlaybackTests.cs b/tools/test-proxy/Azure.Sdk.Tools.TestProxy.Tests/PlaybackTests.cs index 5022d3f6f4b..3e5cfecf9a8 100644 --- a/tools/test-proxy/Azure.Sdk.Tools.TestProxy.Tests/PlaybackTests.cs +++ b/tools/test-proxy/Azure.Sdk.Tools.TestProxy.Tests/PlaybackTests.cs @@ -37,7 +37,9 @@ public async void TestStartPlaybackSimple() await controller.Start(); var value = httpContext.Response.Headers["x-recording-id"].ToString(); + var path = httpContext.Response.Headers["x-recording-file-location"].ToString(); Assert.NotNull(value); + Assert.NotNull(path); Assert.True(testRecordingHandler.PlaybackSessions.ContainsKey(value)); } diff --git a/tools/test-proxy/Azure.Sdk.Tools.TestProxy/RecordingHandler.cs b/tools/test-proxy/Azure.Sdk.Tools.TestProxy/RecordingHandler.cs index af8a23ca1c2..6c9f71d2ef5 100644 --- a/tools/test-proxy/Azure.Sdk.Tools.TestProxy/RecordingHandler.cs +++ b/tools/test-proxy/Azure.Sdk.Tools.TestProxy/RecordingHandler.cs @@ -372,7 +372,7 @@ public async Task StartPlaybackAsync(string sessionId, HttpResponse outgoingResp { await RestoreAssetsJson(assetsPath, true); var path = await GetRecordingPath(sessionId, assetsPath); - + outgoingResponse.Headers.Add("x-recording-file-location", path); if (!File.Exists(path)) { throw new TestRecordingMismatchException($"Recording file path {path} does not exist."); From 0ebe18e3bf7dba184986d7c24e009b879f2bb774 Mon Sep 17 00:00:00 2001 From: Bill Wert Date: Fri, 14 Jul 2023 11:45:24 -0700 Subject: [PATCH 2/5] update readme --- tools/test-proxy/Azure.Sdk.Tools.TestProxy/README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tools/test-proxy/Azure.Sdk.Tools.TestProxy/README.md b/tools/test-proxy/Azure.Sdk.Tools.TestProxy/README.md index 307e0bd97fb..f77a1124a90 100644 --- a/tools/test-proxy/Azure.Sdk.Tools.TestProxy/README.md +++ b/tools/test-proxy/Azure.Sdk.Tools.TestProxy/README.md @@ -351,6 +351,8 @@ To start an individual test recording or playback, users will POST to a route on You will receive a recordingId in the reponse under header `x-recording-id`. This value should be included under header `x-recording-id` in all further requests. +For playback, you will receive the location of the recording file (if it is on disk) in the header `x-recording-file-location`. + ### Run your tests The implicit assumption about this proxy is that you as a dev have _some way_ to reroute your existing requests (with some header additions) to the test-proxy. From f15122462796f05e8fec358c2c0ce4c11e187305 Mon Sep 17 00:00:00 2001 From: Bill Wert Date: Fri, 14 Jul 2023 11:58:46 -0700 Subject: [PATCH 3/5] Add test to make sure in-memory recordings aren't returning the location header --- .../test-proxy/Azure.Sdk.Tools.TestProxy.Tests/PlaybackTests.cs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tools/test-proxy/Azure.Sdk.Tools.TestProxy.Tests/PlaybackTests.cs b/tools/test-proxy/Azure.Sdk.Tools.TestProxy.Tests/PlaybackTests.cs index 3e5cfecf9a8..e562e83473a 100644 --- a/tools/test-proxy/Azure.Sdk.Tools.TestProxy.Tests/PlaybackTests.cs +++ b/tools/test-proxy/Azure.Sdk.Tools.TestProxy.Tests/PlaybackTests.cs @@ -77,6 +77,8 @@ public async void TestStartPlaybackInMemory() var value = playbackContext.Response.Headers["x-recording-id"].ToString(); Assert.NotNull(value); + // Ensure in-memory recordings don't return this header. + Assert.True(String.IsNullOrEmpty(recordLocation)); Assert.True(testRecordingHandler.PlaybackSessions.ContainsKey(value)); Assert.True(testRecordingHandler.InMemorySessions.Count() == 1); } From 07738e2f940528276d2f26cf50a280c559bdb4ac Mon Sep 17 00:00:00 2001 From: Bill Wert Date: Fri, 14 Jul 2023 11:59:33 -0700 Subject: [PATCH 4/5] `IHeaderDictionary` returns an empty string when the header is missing, so `Assert.NotNull` will not catch bugs. --- .../PlaybackTests.cs | 14 +++++++------- .../Azure.Sdk.Tools.TestProxy.Tests/RecordTests.cs | 6 +++--- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/tools/test-proxy/Azure.Sdk.Tools.TestProxy.Tests/PlaybackTests.cs b/tools/test-proxy/Azure.Sdk.Tools.TestProxy.Tests/PlaybackTests.cs index e562e83473a..95f15a459e8 100644 --- a/tools/test-proxy/Azure.Sdk.Tools.TestProxy.Tests/PlaybackTests.cs +++ b/tools/test-proxy/Azure.Sdk.Tools.TestProxy.Tests/PlaybackTests.cs @@ -37,9 +37,9 @@ public async void TestStartPlaybackSimple() await controller.Start(); var value = httpContext.Response.Headers["x-recording-id"].ToString(); - var path = httpContext.Response.Headers["x-recording-file-location"].ToString(); - Assert.NotNull(value); - Assert.NotNull(path); + var recordLocation = httpContext.Response.Headers["x-recording-f3le-location"].ToString(); + Assert.False(String.IsNullOrEmpty(value)); + Assert.False(String.IsNullOrEmpty(recordLocation)); Assert.True(testRecordingHandler.PlaybackSessions.ContainsKey(value)); } @@ -76,8 +76,8 @@ public async void TestStartPlaybackInMemory() await playbackController.Start(); var value = playbackContext.Response.Headers["x-recording-id"].ToString(); - Assert.NotNull(value); - // Ensure in-memory recordings don't return this header. + var recordLocation = playbackContext.Response.Headers["x-recording-file-location"].ToString(); + Assert.False(String.IsNullOrEmpty(value)); Assert.True(String.IsNullOrEmpty(recordLocation)); Assert.True(testRecordingHandler.PlaybackSessions.ContainsKey(value)); Assert.True(testRecordingHandler.InMemorySessions.Count() == 1); @@ -210,7 +210,7 @@ public async Task TestPlaybackSetsRetryAfterToZero() await controller.Start(); var recordingId = httpContext.Response.Headers["x-recording-id"].ToString(); - Assert.NotNull(recordingId); + Assert.False(String.IsNullOrEmpty(recordingId)); Assert.True(testRecordingHandler.PlaybackSessions.ContainsKey(recordingId)); var entry = testRecordingHandler.PlaybackSessions[recordingId].Session.Entries[0]; HttpRequest request = TestHelpers.CreateRequestFromEntry(entry); @@ -245,7 +245,7 @@ public async Task TestPlaybackWithGZippedContentPlayback() await controller.Start(); var recordingId = httpContext.Response.Headers["x-recording-id"].ToString(); - Assert.NotNull(recordingId); + Assert.False(String.IsNullOrEmpty(recordingId)); Assert.True(testRecordingHandler.PlaybackSessions.ContainsKey(recordingId)); var entry = testRecordingHandler.PlaybackSessions[recordingId].Session.Entries[0]; HttpRequest request = TestHelpers.CreateRequestFromEntry(entry); diff --git a/tools/test-proxy/Azure.Sdk.Tools.TestProxy.Tests/RecordTests.cs b/tools/test-proxy/Azure.Sdk.Tools.TestProxy.Tests/RecordTests.cs index 5e08673fa99..82fdb96b679 100644 --- a/tools/test-proxy/Azure.Sdk.Tools.TestProxy.Tests/RecordTests.cs +++ b/tools/test-proxy/Azure.Sdk.Tools.TestProxy.Tests/RecordTests.cs @@ -35,7 +35,7 @@ public async Task TestStartRecordSimple() }; await controller.Start(); var recordingId = httpContext.Response.Headers["x-recording-id"].ToString(); - Assert.NotNull(recordingId); + Assert.False(string.IsNullOrEmpty(recordingId)); Assert.True(testRecordingHandler.RecordingSessions.ContainsKey(recordingId)); } @@ -62,9 +62,9 @@ public async Task TestStartRecordInMemory() [Theory] [InlineData("recordings/TestStartRecordSimple_nosave.json", "request-response")] - [InlineData("recordings/TestStartRecordSimpl�_nosave.json", "request-response")] + [InlineData("recordings/TestStartRecordSimplé_nosave.json", "request-response")] [InlineData("recordings/TestStartRecordSimple.json", "")] - [InlineData("recordings/TestStartRecordSimpl�.json", "")] + [InlineData("recordings/TestStartRecordSimplé.json", "")] public async Task TestStopRecordingSimple(string targetFile, string additionalEntryModeHeader) { RecordingHandler testRecordingHandler = new RecordingHandler(Directory.GetCurrentDirectory()); From a561b7bf5e70ceb9e301bedca3d4fbd2d1ee9335 Mon Sep 17 00:00:00 2001 From: Bill Wert Date: Fri, 14 Jul 2023 12:44:28 -0700 Subject: [PATCH 5/5] Update tools/test-proxy/Azure.Sdk.Tools.TestProxy.Tests/PlaybackTests.cs Co-authored-by: Scott Beddall <45376673+scbedd@users.noreply.github.com> --- .../test-proxy/Azure.Sdk.Tools.TestProxy.Tests/PlaybackTests.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/test-proxy/Azure.Sdk.Tools.TestProxy.Tests/PlaybackTests.cs b/tools/test-proxy/Azure.Sdk.Tools.TestProxy.Tests/PlaybackTests.cs index 95f15a459e8..1b8fdd66406 100644 --- a/tools/test-proxy/Azure.Sdk.Tools.TestProxy.Tests/PlaybackTests.cs +++ b/tools/test-proxy/Azure.Sdk.Tools.TestProxy.Tests/PlaybackTests.cs @@ -37,7 +37,7 @@ public async void TestStartPlaybackSimple() await controller.Start(); var value = httpContext.Response.Headers["x-recording-id"].ToString(); - var recordLocation = httpContext.Response.Headers["x-recording-f3le-location"].ToString(); + var recordLocation = httpContext.Response.Headers["x-recording-file-location"].ToString(); Assert.False(String.IsNullOrEmpty(value)); Assert.False(String.IsNullOrEmpty(recordLocation)); Assert.True(testRecordingHandler.PlaybackSessions.ContainsKey(value));