Skip to content

Commit

Permalink
[MetricsAdvisor] Add tests for Skip and MaximumPageSize input options…
Browse files Browse the repository at this point in the history
… in AnomalyAlertConfigurationLiveTests and AnomalyDetectionConfigurationLiveTests (#24540)
  • Loading branch information
Gyeonghun-Park authored Nov 18, 2021
1 parent 941cf29 commit 1153eae
Show file tree
Hide file tree
Showing 11 changed files with 5,490 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -726,6 +726,51 @@ public async Task GetAlertConfigurations(bool useTokenCredential)
Assert.That(configCount, Is.GreaterThan(0));
}

[RecordedTest]
public void GetAlertConfigurationsWithOptionalSkip()
{
MetricsAdvisorAdministrationClient adminClient = GetMetricsAdvisorAdministrationClient();

var options = new GetAlertConfigurationsOptions()
{
Skip = SkipSamples
};

AsyncPageable<AnomalyAlertConfiguration> configs = adminClient.GetAlertConfigurationsAsync(DetectionConfigurationId);
AsyncPageable<AnomalyAlertConfiguration> configsWithSkip = adminClient.GetAlertConfigurationsAsync(DetectionConfigurationId, options);
var getConfigsCount = configs.ToEnumerableAsync().Result.Count;
var getConfigsWithSkipCount = configsWithSkip.ToEnumerableAsync().Result.Count;

Assert.That(getConfigsCount, Is.EqualTo(getConfigsWithSkipCount + SkipSamples));
}

[RecordedTest]
public async Task GetAlertConfigurationsWithOptionalMaxPageSize()
{
MetricsAdvisorAdministrationClient adminClient = GetMetricsAdvisorAdministrationClient();

var options = new GetAlertConfigurationsOptions()
{
MaxPageSize = MaxPageSizeSamples
};

AsyncPageable<AnomalyAlertConfiguration> configsWithMaxPageSize = adminClient.GetAlertConfigurationsAsync(DetectionConfigurationId, options);

var configCount = 0;

await foreach (Page<AnomalyAlertConfiguration> page in configsWithMaxPageSize.AsPages())
{
Assert.That(page.Values.Count, Is.LessThanOrEqualTo(MaxPageSizeSamples));

if (++configCount >= MaximumSamplesCount)
{
break;
}
}

Assert.That(configCount, Is.GreaterThan(0));
}

[RecordedTest]
[TestCase(true)]
[TestCase(false)]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -733,6 +733,51 @@ public async Task GetDetectionConfigurations(bool useTokenCredential)
Assert.That(configCount, Is.GreaterThan(0));
}

[RecordedTest]
public void GetDetectionConfigurationsWithOptionalSkip()
{
MetricsAdvisorAdministrationClient adminClient = GetMetricsAdvisorAdministrationClient();

var options = new GetDetectionConfigurationsOptions()
{
Skip = SkipSamples
};

AsyncPageable<AnomalyDetectionConfiguration> configs = adminClient.GetDetectionConfigurationsAsync(MetricId);
AsyncPageable<AnomalyDetectionConfiguration> configsWithSkip = adminClient.GetDetectionConfigurationsAsync(MetricId, options);
var getConfigsCount = configs.ToEnumerableAsync().Result.Count;
var getConfigsWithSkipCount = configsWithSkip.ToEnumerableAsync().Result.Count;

Assert.That(getConfigsCount, Is.EqualTo(getConfigsWithSkipCount + SkipSamples));
}

[RecordedTest]
public async Task GetDetectionConfigurationsWithOptionalMaxPageSize()
{
MetricsAdvisorAdministrationClient adminClient = GetMetricsAdvisorAdministrationClient();

var options = new GetDetectionConfigurationsOptions()
{
MaxPageSize = MaxPageSizeSamples
};

AsyncPageable<AnomalyDetectionConfiguration> configsWithMaxPageSize = adminClient.GetDetectionConfigurationsAsync(MetricId, options);

var configCount = 0;

await foreach (Page<AnomalyDetectionConfiguration> page in configsWithMaxPageSize.AsPages())
{
Assert.That(page.Values.Count, Is.LessThanOrEqualTo(MaxPageSizeSamples));

if (++configCount >= MaximumSamplesCount)
{
break;
}
}

Assert.That(configCount, Is.GreaterThan(0));
}

[RecordedTest]
[TestCase(true)]
[TestCase(false)]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ public MetricsAdvisorLiveTestBase(bool isAsync) : base(isAsync)

protected int MaximumSamplesCount => 10;

protected int MaxPageSizeSamples => 1;

protected int SkipSamples => 1;

protected DateTimeOffset SamplingStartTime => DateTimeOffset.Parse("2020-10-01T00:00:00Z");

protected DateTimeOffset SamplingEndTime => DateTimeOffset.Parse("2020-10-31T00:00:00Z");
Expand Down
Loading

0 comments on commit 1153eae

Please sign in to comment.