diff --git a/tools/test-proxy/Azure.Sdk.Tools.TestProxy.Tests/InfoTests.cs b/tools/test-proxy/Azure.Sdk.Tools.TestProxy.Tests/InfoTests.cs index dacb6934adf..1550898dd04 100644 --- a/tools/test-proxy/Azure.Sdk.Tools.TestProxy.Tests/InfoTests.cs +++ b/tools/test-proxy/Azure.Sdk.Tools.TestProxy.Tests/InfoTests.cs @@ -79,7 +79,7 @@ public async Task TestReflectionModelWithTargetRecordSession() await testRecordingHandler.RegisterSanitizer(new UriRegexSanitizer(regex: "ABC123"), recordingId); await testRecordingHandler.RegisterSanitizer(new BodyRegexSanitizer(regex: ".+?"), recordingId); - testRecordingHandler.SetMatcherForRecording(recordingId, new CustomDefaultMatcher(compareBodies: false, excludedHeaders: "an-excluded-header")); + await testRecordingHandler.SetMatcherForRecording(recordingId, new CustomDefaultMatcher(compareBodies: false, excludedHeaders: "an-excluded-header")); var model = new ActiveMetadataModel(testRecordingHandler, recordingId); var descriptions = model.Descriptions.ToList(); diff --git a/tools/test-proxy/Azure.Sdk.Tools.TestProxy/Admin.cs b/tools/test-proxy/Azure.Sdk.Tools.TestProxy/Admin.cs index f9e41f76701..716e5389f4d 100644 --- a/tools/test-proxy/Azure.Sdk.Tools.TestProxy/Admin.cs +++ b/tools/test-proxy/Azure.Sdk.Tools.TestProxy/Admin.cs @@ -197,11 +197,20 @@ public async Task SetMatcher() if (recordingId != null) { - _recordingHandler.SetMatcherForRecording(recordingId, m); + await _recordingHandler.SetMatcherForRecording(recordingId, m); } else { - _recordingHandler.Matcher = m; + await _recordingHandler.SanitizerRegistry.SessionSanitizerLock.WaitAsync(); + + try + { + _recordingHandler.Matcher = m; + } + finally + { + _recordingHandler.SanitizerRegistry.SessionSanitizerLock.Release(); + } } } diff --git a/tools/test-proxy/Azure.Sdk.Tools.TestProxy/RecordingHandler.cs b/tools/test-proxy/Azure.Sdk.Tools.TestProxy/RecordingHandler.cs index 4c2c792b3a8..5f680db2869 100644 --- a/tools/test-proxy/Azure.Sdk.Tools.TestProxy/RecordingHandler.cs +++ b/tools/test-proxy/Azure.Sdk.Tools.TestProxy/RecordingHandler.cs @@ -1093,14 +1093,21 @@ public void AddTransformToRecording(string recordingId, ResponseTransform transf } - public void SetMatcherForRecording(string recordingId, RecordMatcher matcher) + public async Task SetMatcherForRecording(string recordingId, RecordMatcher matcher) { if (!PlaybackSessions.TryGetValue(recordingId, out var session)) { throw new HttpException(HttpStatusCode.BadRequest, $"{recordingId} is not an active playback session. Check the value being passed and try again."); } - session.CustomMatcher = matcher; + await session.Session.EntryLock.WaitAsync(); + try { + session.CustomMatcher = matcher; + } + finally + { + session.Session.EntryLock.Release(); + } } public async Task SetDefaultExtensions(string recordingId = null)