Skip to content

Commit

Permalink
[Event Hubs Client] Test Reliability Tweaks (#17941)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
jsquire authored Jan 13, 2021
1 parent 44425da commit 5c53d27
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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))
{
Expand Down Expand Up @@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand All @@ -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.");
Expand Down Expand Up @@ -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.
Expand Down

0 comments on commit 5c53d27

Please sign in to comment.