From 5c53d27feb7297d2958ba813c0b6cc2f90ba5ce1 Mon Sep 17 00:00:00 2001 From: Jesse Squire Date: Wed, 13 Jan 2021 12:50:59 -0500 Subject: [PATCH] [Event Hubs Client] Test Reliability Tweaks (#17941) The focus of these changes is to tweak the approach and/or timing on tests that were observed to be intermittently failing during pipeline runs. --- .../Consumer/EventHubConsumerClientLiveTests.cs | 8 ++++---- .../tests/Primitives/PartitionReceiverLiveTests.cs | 12 ++++++------ 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/sdk/eventhub/Azure.Messaging.EventHubs/tests/Consumer/EventHubConsumerClientLiveTests.cs b/sdk/eventhub/Azure.Messaging.EventHubs/tests/Consumer/EventHubConsumerClientLiveTests.cs index c93011ee16ac..a7316d86ff8d 100644 --- a/sdk/eventhub/Azure.Messaging.EventHubs/tests/Consumer/EventHubConsumerClientLiveTests.cs +++ b/sdk/eventhub/Azure.Messaging.EventHubs/tests/Consumer/EventHubConsumerClientLiveTests.cs @@ -852,7 +852,7 @@ public async Task ConsumerCannotReadAcrossPartitions() cancellationSource.CancelAfter(EventHubsTestEnvironment.Instance.TestExecutionTimeLimit); var credential = EventHubsTestEnvironment.Instance.Credential; - var sourceEvents = EventGenerator.CreateEvents(100).ToList(); + var sourceEvents = EventGenerator.CreateEvents(50).ToList(); await using (var consumer = new EventHubConsumerClient(EventHubConsumerClient.DefaultConsumerGroupName, EventHubsTestEnvironment.Instance.FullyQualifiedNamespace, scope.EventHubName, credential)) { @@ -1585,13 +1585,13 @@ public async Task ConsumerRespectsTheWaitTimeWhenReading() await using (var consumer = new EventHubConsumerClient(EventHubConsumerClient.DefaultConsumerGroupName, EventHubsTestEnvironment.Instance.EventHubsConnectionString, scope.EventHubName)) { var partition = (await consumer.GetPartitionIdsAsync(cancellationSource.Token)).First(); - var options = new ReadEventOptions { MaximumWaitTime = TimeSpan.FromMilliseconds(250) }; + var options = new ReadEventOptions { MaximumWaitTime = TimeSpan.FromMilliseconds(100) }; var desiredEmptyEvents = 10; var minimumEmptyEvents = 5; var readTime = TimeSpan - .FromSeconds(options.MaximumWaitTime.Value.TotalSeconds * desiredEmptyEvents) - .Add(TimeSpan.FromSeconds(3)); + .FromMilliseconds(options.MaximumWaitTime.Value.TotalMilliseconds * desiredEmptyEvents) + .Add(TimeSpan.FromSeconds(10)); // Attempt to read from the empty partition and verify that no events are observed. Because no events are expected, the // read operation will not naturally complete; limit the read to only a couple of seconds and trigger cancellation. diff --git a/sdk/eventhub/Azure.Messaging.EventHubs/tests/Primitives/PartitionReceiverLiveTests.cs b/sdk/eventhub/Azure.Messaging.EventHubs/tests/Primitives/PartitionReceiverLiveTests.cs index e573186c6716..766ac8f9dcce 100644 --- a/sdk/eventhub/Azure.Messaging.EventHubs/tests/Primitives/PartitionReceiverLiveTests.cs +++ b/sdk/eventhub/Azure.Messaging.EventHubs/tests/Primitives/PartitionReceiverLiveTests.cs @@ -832,7 +832,7 @@ public async Task ReceiverCannotReadAcrossPartitions() var connectionString = EventHubsTestEnvironment.Instance.BuildConnectionStringForEventHub(scope.EventHubName); var credential = EventHubsTestEnvironment.Instance.Credential; - var sourceEvents = EventGenerator.CreateEvents(100).ToList(); + var sourceEvents = EventGenerator.CreateEvents(50).ToList(); // Send events to the second partition, which should not be visible to the receiver. @@ -845,9 +845,9 @@ public async Task ReceiverCannotReadAcrossPartitions() // read operation will not naturally complete; limit the read to only a couple of seconds and trigger cancellation. using var readCancellation = CancellationTokenSource.CreateLinkedTokenSource(cancellationSource.Token); - readCancellation.CancelAfter(TimeSpan.FromSeconds(5)); + readCancellation.CancelAfter(TimeSpan.FromSeconds(15)); - var readState = await ReadEventsAsync(receiver, sourceEvents.Count, readCancellation.Token, waitTime: TimeSpan.FromSeconds(1)); + var readState = await ReadEventsAsync(receiver, sourceEvents.Count, readCancellation.Token, waitTime: TimeSpan.FromMilliseconds(250)); Assert.That(cancellationSource.IsCancellationRequested, Is.False, "The main cancellation token should not have been signaled."); Assert.That(readState.Events.Count, Is.Zero, "No events should have been read from the empty partition."); @@ -1411,13 +1411,13 @@ public async Task ReceiverRespectsTheWaitTimeWhenReading() await using (var receiver = new PartitionReceiver(EventHubConsumerClient.DefaultConsumerGroupName, partition, EventPosition.Earliest, EventHubsTestEnvironment.Instance.EventHubsConnectionString, scope.EventHubName)) { - var waitTime = TimeSpan.FromMilliseconds(250); + var waitTime = TimeSpan.FromMilliseconds(100); var desiredEmptyBatches = 10; var minimumEmptyBatches = 5; var readTime = TimeSpan - .FromSeconds(waitTime.TotalSeconds * desiredEmptyBatches) - .Add(TimeSpan.FromSeconds(3)); + .FromMilliseconds(waitTime.TotalMilliseconds * desiredEmptyBatches) + .Add(TimeSpan.FromSeconds(10)); // Attempt to read from the empty partition and verify that no events are observed. Because no events are expected, the // read operation will not naturally complete; limit the read to only a couple of seconds and trigger cancellation.