Skip to content

Commit 74fae32

Browse files
amitla1Amitla Vannikumar
andauthored
Move Location of Experiments Call to CD Internal (#720)
* moved location of call to experiments to CD internal * updated tests * updated to call finishasync in CD * updated * update documentation * updated * Update DetectorProcessingServiceTests.cs * syntax * updated tests * updated * updated * updated * updated * updated * updated * updated * updated * added test * added tests * updated tests * updated tests * Update DetectorProcessingService.cs --------- Co-authored-by: Amitla Vannikumar <[email protected]>
1 parent 0bfe4ba commit 74fae32

File tree

3 files changed

+57
-1
lines changed

3 files changed

+57
-1
lines changed

src/Microsoft.ComponentDetection.Orchestrator/Experiments/DetectorExperiments.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,11 @@ namespace Microsoft.ComponentDetection.Orchestrator.Experiments;
77
/// </summary>
88
public static class DetectorExperiments
99
{
10+
/// <summary>
11+
/// Check to automatically proccess experiments.
12+
/// </summary>
13+
public static bool AutomaticallyProcessExperiments { get; set; } = true;
14+
1015
/// <summary>
1116
/// Manually enables detector experiments.
1217
/// </summary>

src/Microsoft.ComponentDetection.Orchestrator/Experiments/ExperimentService.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,11 @@ public async Task FinishAsync()
116116
return;
117117
}
118118

119+
if (!DetectorExperiments.AutomaticallyProcessExperiments)
120+
{
121+
return;
122+
}
123+
119124
foreach (var (config, experiment) in this.experiments)
120125
{
121126
var controlComponents = experiment.ControlGroupComponents;

test/Microsoft.ComponentDetection.Orchestrator.Tests/Experiments/ExperimentServiceTests.cs

Lines changed: 47 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,11 @@ private void SetupGraphMock(IEnumerable<ScannedComponent> components)
5555
}
5656

5757
[TestInitialize]
58-
public void EnableDetectorExperiments() => DetectorExperiments.Enable = true;
58+
public void TestInitialize()
59+
{
60+
DetectorExperiments.Enable = true;
61+
DetectorExperiments.AutomaticallyProcessExperiments = true;
62+
}
5963

6064
[TestMethod]
6165
public void RecordDetectorRun_AddsComponentsToControlAndExperimentGroup()
@@ -195,6 +199,48 @@ public async Task FinishAsync_SkipsEmptyExperimentsAsync()
195199
Times.Never());
196200
}
197201

202+
[TestMethod]
203+
public async Task FinishAsync_AutomaticallyProcessesExperimentsAsync()
204+
{
205+
var components = ExperimentTestUtils.CreateRandomComponents();
206+
this.SetupGraphMock(components);
207+
208+
var service = new ExperimentService(
209+
new[] { this.experimentConfigMock.Object },
210+
new[] { this.experimentProcessorMock.Object },
211+
this.graphTranslationServiceMock.Object,
212+
this.loggerMock.Object);
213+
service.RecordDetectorRun(this.detectorMock.Object, this.componentRecorder, this.detectionArgsMock.Object);
214+
215+
await service.FinishAsync();
216+
217+
this.experimentProcessorMock.Verify(
218+
x => x.ProcessExperimentAsync(this.experimentConfigMock.Object, It.IsAny<ExperimentDiff>()),
219+
Times.Once());
220+
}
221+
222+
[TestMethod]
223+
public async Task FinishAsync_DoesNotAutomaticallyProcessExperimentsAsync()
224+
{
225+
DetectorExperiments.AutomaticallyProcessExperiments = false;
226+
227+
var components = ExperimentTestUtils.CreateRandomComponents();
228+
this.SetupGraphMock(components);
229+
230+
var service = new ExperimentService(
231+
new[] { this.experimentConfigMock.Object },
232+
new[] { this.experimentProcessorMock.Object },
233+
this.graphTranslationServiceMock.Object,
234+
this.loggerMock.Object);
235+
service.RecordDetectorRun(this.detectorMock.Object, this.componentRecorder, this.detectionArgsMock.Object);
236+
237+
await service.FinishAsync();
238+
239+
this.experimentProcessorMock.Verify(
240+
x => x.ProcessExperimentAsync(this.experimentConfigMock.Object, It.IsAny<ExperimentDiff>()),
241+
Times.Never());
242+
}
243+
198244
[TestMethod]
199245
public async Task FinishAsync_Respects_DetectorExperiments_EnableAsync()
200246
{

0 commit comments

Comments
 (0)