From dc2ac8826eae35236d07af83cfd99c26d80f40b1 Mon Sep 17 00:00:00 2001 From: Justin Perez Date: Tue, 2 May 2023 12:53:37 -0700 Subject: [PATCH] Revert "fix: yank experiments (#533)" This reverts commit cd6405a827b256fa6d0881ad495cd7dd5a0a821d. --- .../Services/DetectorProcessingService.cs | 7 +++ .../DetectorProcessingServiceTests.cs | 43 ++++++++++++++++++- 2 files changed, 49 insertions(+), 1 deletion(-) diff --git a/src/Microsoft.ComponentDetection.Orchestrator/Services/DetectorProcessingService.cs b/src/Microsoft.ComponentDetection.Orchestrator/Services/DetectorProcessingService.cs index c433c5ae2..0b241b01b 100644 --- a/src/Microsoft.ComponentDetection.Orchestrator/Services/DetectorProcessingService.cs +++ b/src/Microsoft.ComponentDetection.Orchestrator/Services/DetectorProcessingService.cs @@ -15,6 +15,7 @@ using Microsoft.ComponentDetection.Contracts; using Microsoft.ComponentDetection.Contracts.BcdeModels; using Microsoft.ComponentDetection.Orchestrator.ArgumentSets; +using Microsoft.ComponentDetection.Orchestrator.Experiments; using Microsoft.Extensions.Logging; using Newtonsoft.Json; using static System.Environment; @@ -23,12 +24,15 @@ public class DetectorProcessingService : IDetectorProcessingService { private readonly IObservableDirectoryWalkerFactory scanner; private readonly ILogger logger; + private readonly IExperimentService experimentService; public DetectorProcessingService( IObservableDirectoryWalkerFactory scanner, + IExperimentService experimentService, ILogger logger) { this.scanner = scanner; + this.experimentService = experimentService; this.logger = logger; } @@ -105,6 +109,8 @@ public async Task ProcessDetectorsAsync(IDetectionArgu exitCode = resultCode; } + this.experimentService.RecordDetectorRun(detector, detectedComponents); + if (isExperimentalDetector) { return (new IndividualDetectorScanResult(), new ComponentRecorder(), detector); @@ -116,6 +122,7 @@ public async Task ProcessDetectorsAsync(IDetectionArgu }).ToList(); var results = await Task.WhenAll(scanTasks); + await this.experimentService.FinishAsync(); var detectorProcessingResult = this.ConvertDetectorResultsIntoResult(results, exitCode); diff --git a/test/Microsoft.ComponentDetection.Orchestrator.Tests/Services/DetectorProcessingServiceTests.cs b/test/Microsoft.ComponentDetection.Orchestrator.Tests/Services/DetectorProcessingServiceTests.cs index 00e92aad6..37eb40229 100644 --- a/test/Microsoft.ComponentDetection.Orchestrator.Tests/Services/DetectorProcessingServiceTests.cs +++ b/test/Microsoft.ComponentDetection.Orchestrator.Tests/Services/DetectorProcessingServiceTests.cs @@ -56,7 +56,7 @@ public DetectorProcessingServiceTests() this.loggerMock = new Mock>(); this.directoryWalkerFactory = new Mock(); this.serviceUnderTest = - new DetectorProcessingService(this.directoryWalkerFactory.Object, this.loggerMock.Object); + new DetectorProcessingService(this.directoryWalkerFactory.Object, this.experimentServiceMock.Object, this.loggerMock.Object); this.firstFileComponentDetectorMock = this.SetupFileDetectorMock("firstFileDetectorId"); this.secondFileComponentDetectorMock = this.SetupFileDetectorMock("secondFileDetectorId"); @@ -509,6 +509,47 @@ public async Task ProcessDetectorsAsync_HandlesDetectorArgsAsync() .And.Contain("arg3", "val3"); } + [TestMethod] + public async Task ProcessDetectorsAsync_FinishesExperimentsAsync() + { + this.detectorsToUse = new[] + { + this.firstFileComponentDetectorMock.Object, this.secondFileComponentDetectorMock.Object, + }; + + await this.serviceUnderTest.ProcessDetectorsAsync(DefaultArgs, this.detectorsToUse, new DetectorRestrictions()); + + this.experimentServiceMock.Verify(x => x.FinishAsync(), Times.Once()); + } + + [TestMethod] + public async Task ProcessDetectorsAsync_RecordsDetectorRunsAsync() + { + this.detectorsToUse = new[] + { + this.firstFileComponentDetectorMock.Object, this.secondFileComponentDetectorMock.Object, + }; + + var firstComponents = new[] { this.componentDictionary[this.firstFileComponentDetectorMock.Object.Id] }; + var secondComponents = new[] { this.componentDictionary[this.secondFileComponentDetectorMock.Object.Id] }; + + await this.serviceUnderTest.ProcessDetectorsAsync(DefaultArgs, this.detectorsToUse, new DetectorRestrictions()); + + this.experimentServiceMock.Verify( + x => + x.RecordDetectorRun( + It.Is(detector => detector == this.firstFileComponentDetectorMock.Object), + It.Is>(components => components.SequenceEqual(firstComponents))), + Times.Once()); + + this.experimentServiceMock.Verify( + x => + x.RecordDetectorRun( + It.Is(detector => detector == this.secondFileComponentDetectorMock.Object), + It.Is>(components => components.SequenceEqual(secondComponents))), + Times.Once()); + } + private Mock SetupFileDetectorMock(string id) { var mockFileDetector = new Mock();