From e95e59b5773b4f9745685b5c5800f2e9716ce68e Mon Sep 17 00:00:00 2001 From: Amanda Nguyen <48961492+amnguye@users.noreply.github.com> Date: Tue, 21 Feb 2023 09:18:06 -0800 Subject: [PATCH] Attempt fix GetMetrics_ReturnsExpectedResult failing in live tests (#34356) * Attempt to fix live tests for GetMetrics tests from Target Based Scaling for Queues * Remove unncessary packages * Change test queue from mock queue to fixture queue * Change metric provider constructor to only change for the success metrics test * Correcting test to use fixture queue * Removing duplicate queues for same tests * shorter queue name --- .../tests/QueueMetricsProviderTests.cs | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/sdk/storage/Microsoft.Azure.WebJobs.Extensions.Storage.Queues/tests/QueueMetricsProviderTests.cs b/sdk/storage/Microsoft.Azure.WebJobs.Extensions.Storage.Queues/tests/QueueMetricsProviderTests.cs index 8b99608e3c848..1dfbf0aa1c17a 100644 --- a/sdk/storage/Microsoft.Azure.WebJobs.Extensions.Storage.Queues/tests/QueueMetricsProviderTests.cs +++ b/sdk/storage/Microsoft.Azure.WebJobs.Extensions.Storage.Queues/tests/QueueMetricsProviderTests.cs @@ -33,6 +33,7 @@ public void SetUp() _loggerProvider = new TestLoggerProvider(); _loggerFactory.AddProvider(_loggerProvider); _mockQueue = new Mock(new Uri("https://test.queue.core.windows.net/testqueue"), new QueueClientOptions()); + _mockQueue.Setup(x => x.Name).Returns("testqueue"); _metricsProvider = new QueueMetricsProvider(_mockQueue.Object, _loggerFactory); } @@ -53,7 +54,8 @@ public void OneTimeTearDown() [Test] public async Task GetMetrics_ReturnsExpectedResult() { - var metrics = await _metricsProvider.GetMetricsAsync(); + QueueMetricsProvider _provider = new QueueMetricsProvider(Fixture.Queue, _loggerFactory); + var metrics = await _provider.GetMetricsAsync(); Assert.AreEqual(0, metrics.QueueLength); Assert.AreEqual(TimeSpan.Zero, metrics.QueueTime); @@ -67,14 +69,14 @@ public async Task GetMetrics_ReturnsExpectedResult() await Task.Delay(TimeSpan.FromSeconds(5)); - metrics = await _metricsProvider.GetMetricsAsync(); + metrics = await _provider.GetMetricsAsync(); Assert.AreEqual(5, metrics.QueueLength); Assert.True(metrics.QueueTime.Ticks > 0); Assert.AreNotEqual(default(DateTime), metrics.Timestamp); // verify non-generic interface works as expected - metrics = (QueueTriggerMetrics)(await _metricsProvider.GetMetricsAsync()); + metrics = (QueueTriggerMetrics)(await _provider.GetMetricsAsync()); Assert.AreEqual(5, metrics.QueueLength); } @@ -101,7 +103,7 @@ public async Task GetMetrics_HandlesStorageExceptions() public class TestFixture : IDisposable { - private const string TestQueuePrefix = "queuelistenertests"; + private const string TestQueuePrefix = "metrictests"; public TestFixture() {