Skip to content

Commit

Permalink
Remove invalid proxy tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jsquire committed Jan 25, 2025
1 parent 19de7ff commit f962c02
Show file tree
Hide file tree
Showing 4 changed files with 0 additions and 321 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1333,46 +1333,6 @@ public async Task ConsumerCannotReadFromInvalidConsumerGroup()
}
}

/// <summary>
/// Verifies that the <see cref="EventHubConsumerClient" /> is able to
/// connect to the Event Hubs service and perform operations.
/// </summary>
///
[Test]
public async Task ConsumerCannotReadWithInvalidProxy()
{
await using (EventHubScope scope = await EventHubScope.CreateAsync(1))
{
using var cancellationSource = new CancellationTokenSource();
cancellationSource.CancelAfter(EventHubsTestEnvironment.Instance.TestExecutionTimeLimit);

var clientOptions = new EventHubConsumerClientOptions();
clientOptions.RetryOptions.MaximumRetries = 0;
clientOptions.RetryOptions.MaximumDelay = TimeSpan.FromMilliseconds(5);
clientOptions.RetryOptions.TryTimeout = TimeSpan.FromSeconds(45);
clientOptions.ConnectionOptions.Proxy = new WebProxy("http://1.2.3.4:9999");
clientOptions.ConnectionOptions.TransportType = EventHubsTransportType.AmqpWebSockets;

await using (var producer = new EventHubProducerClient(EventHubsTestEnvironment.Instance.FullyQualifiedNamespace, scope.EventHubName, EventHubsTestEnvironment.Instance.Credential))
await using (var invalidProxyConsumer = new EventHubConsumerClient(EventHubConsumerClient.DefaultConsumerGroupName, EventHubsTestEnvironment.Instance.FullyQualifiedNamespace, scope.EventHubName, EventHubsTestEnvironment.Instance.Credential, clientOptions))
{
var partition = (await producer.GetPartitionIdsAsync(cancellationSource.Token)).First();

// The sockets implementation in .NET Core on some platforms, such as Linux, does not trigger a specific socket exception and
// will, instead, hang indefinitely. The try timeout is intentionally set to a value smaller than the cancellation token to
// invoke a timeout exception in these cases.

Assert.That(async () => await ReadNothingAsync(invalidProxyConsumer, partition, cancellationSource.Token, iterationCount: 25),
Throws
.InstanceOf<WebSocketException>()
.Or.InstanceOf<TimeoutException>()
.Or.InstanceOf<OperationCanceledException>());

Assert.That(cancellationSource.IsCancellationRequested, Is.False, "The cancellation token should not have been signaled.");
}
}
}

/// <summary>
/// Verifies that the <see cref="EventHubConsumerClient" /> is able to
/// connect to the Event Hubs service and perform operations.
Expand Down Expand Up @@ -2205,68 +2165,6 @@ public async Task ConsumerCannotRetrievePartitionPropertiesWithInvalidPartitionI
}
}

/// <summary>
/// Verifies that the <see cref="EventHubConsumerClient" /> is able to
/// connect to the Event Hubs service.
/// </summary>
///
[Test]
public async Task ConsumerCannotRetrieveMetadataWithInvalidProxy()
{
await using (EventHubScope scope = await EventHubScope.CreateAsync(1))
{
using var cancellationSource = new CancellationTokenSource();
cancellationSource.CancelAfter(EventHubsTestEnvironment.Instance.TestExecutionTimeLimit);

var invalidProxyOptions = new EventHubConsumerClientOptions();
invalidProxyOptions.RetryOptions.MaximumRetries = 0;
invalidProxyOptions.RetryOptions.MaximumDelay = TimeSpan.FromMilliseconds(5);
invalidProxyOptions.RetryOptions.TryTimeout = TimeSpan.FromSeconds(45);
invalidProxyOptions.ConnectionOptions.Proxy = new WebProxy("http://1.2.3.4:9999");
invalidProxyOptions.ConnectionOptions.TransportType = EventHubsTransportType.AmqpWebSockets;

await using (var consumer = new EventHubConsumerClient(
EventHubConsumerClient.DefaultConsumerGroupName,
EventHubsTestEnvironment.Instance.FullyQualifiedNamespace,
scope.EventHubName,
EventHubsTestEnvironment.Instance.Credential))

await using (var invalidProxyConsumer = new EventHubConsumerClient(
EventHubConsumerClient.DefaultConsumerGroupName,
EventHubsTestEnvironment.Instance.FullyQualifiedNamespace,
scope.EventHubName,
EventHubsTestEnvironment.Instance.Credential,
invalidProxyOptions))
{
var partition = (await consumer.GetPartitionIdsAsync(cancellationSource.Token)).First();

// The sockets implementation in .NET Core on some platforms, such as Linux, does not trigger a specific socket exception and
// will, instead, hang indefinitely. The try timeout is intentionally set to a value smaller than the cancellation token to
// invoke a timeout exception in these cases.

Assert.That(async () => await invalidProxyConsumer.GetPartitionIdsAsync(cancellationSource.Token),
Throws
.InstanceOf<WebSocketException>()
.Or.InstanceOf<TimeoutException>()
.Or.InstanceOf<OperationCanceledException>());

Assert.That(async () => await invalidProxyConsumer.GetEventHubPropertiesAsync(cancellationSource.Token),
Throws
.InstanceOf<WebSocketException>()
.Or.InstanceOf<TimeoutException>()
.Or.InstanceOf<OperationCanceledException>());

Assert.That(async () => await invalidProxyConsumer.GetPartitionPropertiesAsync(partition, cancellationSource.Token),
Throws
.InstanceOf<WebSocketException>()
.Or.InstanceOf<TimeoutException>()
.Or.InstanceOf<OperationCanceledException>());

Assert.That(cancellationSource.IsCancellationRequested, Is.False, "The cancellation token should not have been signaled.");
}
}
}

/// <summary>
/// Verifies that the <see cref="EventHubConsumerClient" /> is able to
/// connect to the Event Hubs service and perform operations.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -952,52 +952,6 @@ public async Task ReceiverCannotReadFromInvalidConsumerGroup()
}
}

/// <summary>
/// Verifies that the <see cref="PartitionReceiver" /> is able to
/// connect to the Event Hubs service and perform operations.
/// </summary>
///
[Test]
public async Task ReceiverCannotReadWithInvalidProxy()
{
await using (EventHubScope scope = await EventHubScope.CreateAsync(1))
{
using var cancellationSource = new CancellationTokenSource();
cancellationSource.CancelAfter(EventHubsTestEnvironment.Instance.TestExecutionTimeLimit);

var clientOptions = new PartitionReceiverOptions();
clientOptions.RetryOptions.MaximumRetries = 0;
clientOptions.RetryOptions.MaximumDelay = TimeSpan.FromMilliseconds(5);
clientOptions.RetryOptions.TryTimeout = TimeSpan.FromSeconds(45);
clientOptions.ConnectionOptions.Proxy = new WebProxy("http://1.2.3.4:9999");
clientOptions.ConnectionOptions.TransportType = EventHubsTransportType.AmqpWebSockets;

var partition = (await QueryPartitionsAsync(scope.EventHubName, cancellationSource.Token)).First();

await using (var invalidProxyReceiver = new PartitionReceiver(
EventHubConsumerClient.DefaultConsumerGroupName,
partition,
EventPosition.Earliest,
EventHubsTestEnvironment.Instance.FullyQualifiedNamespace,
scope.EventHubName,
EventHubsTestEnvironment.Instance.Credential,
clientOptions))
{
// The sockets implementation in .NET Core on some platforms, such as Linux, does not trigger a specific socket exception and
// will, instead, hang indefinitely. The try timeout is intentionally set to a value smaller than the cancellation token to
// invoke a timeout exception in these cases.

Assert.That(async () => await ReadNothingAsync(invalidProxyReceiver, cancellationSource.Token, iterationCount: 25),
Throws
.InstanceOf<WebSocketException>()
.Or.InstanceOf<TimeoutException>()
.Or.InstanceOf<OperationCanceledException>());

Assert.That(cancellationSource.IsCancellationRequested, Is.False, "The cancellation token should not have been signaled.");
}
}
}

/// <summary>
/// Verifies that the <see cref="PartitionReceiver" /> is able to
/// connect to the Event Hubs service and perform operations.
Expand Down Expand Up @@ -2481,52 +2435,6 @@ public async Task ReceiverCannotRetrievePartitionPropertiesWhenConnectionIsClose
}
}

/// <summary>
/// Verifies that the <see cref="PartitionReceiver" /> is able to
/// connect to the Event Hubs service and perform operations.
/// </summary>
///
[Test]
public async Task ReceiverCannotRetrieveMetadataWithInvalidProxy()
{
await using (EventHubScope scope = await EventHubScope.CreateAsync(1))
{
using var cancellationSource = new CancellationTokenSource();
cancellationSource.CancelAfter(EventHubsTestEnvironment.Instance.TestExecutionTimeLimit);

var partition = (await QueryPartitionsAsync(scope.EventHubName, cancellationSource.Token)).First();

var invalidProxyOptions = new PartitionReceiverOptions();
invalidProxyOptions.RetryOptions.MaximumRetries = 0;
invalidProxyOptions.RetryOptions.MaximumDelay = TimeSpan.FromMilliseconds(5);
invalidProxyOptions.RetryOptions.TryTimeout = TimeSpan.FromSeconds(45);
invalidProxyOptions.ConnectionOptions.Proxy = new WebProxy("http://1.2.3.4:9999");
invalidProxyOptions.ConnectionOptions.TransportType = EventHubsTransportType.AmqpWebSockets;

await using (var receiver = new PartitionReceiver(
EventHubConsumerClient.DefaultConsumerGroupName,
partition,
EventPosition.Earliest,
EventHubsTestEnvironment.Instance.FullyQualifiedNamespace,
scope.EventHubName,
EventHubsTestEnvironment.Instance.Credential,
invalidProxyOptions))
{
// The sockets implementation in .NET Core on some platforms, such as Linux, does not trigger a specific socket exception and
// will, instead, hang indefinitely. The try timeout is intentionally set to a value smaller than the cancellation token to
// invoke a timeout exception in these cases.

Assert.That(async () => await receiver.GetPartitionPropertiesAsync(cancellationSource.Token),
Throws
.InstanceOf<WebSocketException>()
.Or.InstanceOf<TimeoutException>()
.Or.InstanceOf<OperationCanceledException>());

Assert.That(cancellationSource.IsCancellationRequested, Is.False, "The cancellation token should not have been signaled.");
}
}
}

/// <summary>
/// Reads the list of partition identifiers for an Event Hub instance.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1666,50 +1666,6 @@ public async Task ProducerCannotRetrievePartitionPropertiesWhenPartitionIdIsInva
Assert.That(async () => await producer.GetPartitionPropertiesAsync(invalidPartition), Throws.TypeOf<ArgumentOutOfRangeException>());
}

/// <summary>
/// Verifies that the <see cref="EventHubBufferedProducerClient" /> is able to
/// connect to the Event Hubs service.
/// </summary>
///
[Test]
public async Task ProducerCannotRetrieveMetadataWhenProxyIsInvalid()
{
var invalidProxyOptions = new EventHubBufferedProducerClientOptions
{
RetryOptions = new EventHubsRetryOptions { TryTimeout = TimeSpan.FromMinutes(2) },

ConnectionOptions = new EventHubConnectionOptions
{
Proxy = new WebProxy("http://1.2.3.4:9999"),
TransportType = EventHubsTransportType.AmqpWebSockets
}
};

await using var scope = await EventHubScope.CreateAsync(1);
await using var producer = new EventHubBufferedProducerClient(EventHubsTestEnvironment.Instance.FullyQualifiedNamespace, scope.EventHubName, EventHubsTestEnvironment.Instance.Credential);
await using var invalidProxyProducer = new EventHubBufferedProducerClient(EventHubsTestEnvironment.Instance.FullyQualifiedNamespace, scope.EventHubName, EventHubsTestEnvironment.Instance.Credential, invalidProxyOptions);

var partition = (await producer.GetPartitionIdsAsync()).First();

Assert.That(async () => await invalidProxyProducer.GetPartitionIdsAsync(),
Throws
.InstanceOf<WebSocketException>().Or
.InstanceOf<TimeoutException>()
.Or.InstanceOf<OperationCanceledException>());

Assert.That(async () => await invalidProxyProducer.GetEventHubPropertiesAsync(),
Throws
.InstanceOf<WebSocketException>()
.Or.InstanceOf<TimeoutException>()
.Or.InstanceOf<OperationCanceledException>());

Assert.That(async () => await invalidProxyProducer.GetPartitionPropertiesAsync(partition),
Throws
.InstanceOf<WebSocketException>()
.Or.InstanceOf<TimeoutException>()
.Or.InstanceOf<OperationCanceledException>());
}

/// <summary>
/// Polls the count of buffered events for a producer until it has been updated to
/// 0 or the maximum number of iterations has been reached.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1180,42 +1180,6 @@ public async Task ProducerSendsEventsWithTheSamePartitionHashKeyToTheSamePartiti
}
}

/// <summary>
/// Verifies that the <see cref="EventHubProducerClient" /> is able to
/// connect to the Event Hubs service and perform operations.
/// </summary>
///
[Test]
public async Task ProducerCannotSendWhenProxyIsInvalid()
{
await using (EventHubScope scope = await EventHubScope.CreateAsync(1))
{
var producerOptions = new EventHubProducerClientOptions
{
RetryOptions = new EventHubsRetryOptions { TryTimeout = TimeSpan.FromMinutes(2) },

ConnectionOptions = new EventHubConnectionOptions
{
Proxy = new WebProxy("http://1.2.3.4:9999"),
TransportType = EventHubsTransportType.AmqpWebSockets
}
};

await using (var invalidProxyProducer = new EventHubProducerClient(
EventHubsTestEnvironment.Instance.FullyQualifiedNamespace,
scope.EventHubName,
EventHubsTestEnvironment.Instance.Credential,
producerOptions))
{
Assert.That(async () => await invalidProxyProducer.SendAsync(new[] { new EventData(new byte[1]) }),
Throws
.InstanceOf<WebSocketException>()
.Or.InstanceOf<TimeoutException>()
.Or.InstanceOf<OperationCanceledException>());
}
}
}

/// <summary>
/// Verifies that the <see cref="EventHubProducerClient" /> is able to
/// connect to the Event Hubs service and perform operations.
Expand Down Expand Up @@ -1455,52 +1419,5 @@ public async Task ProducerCannotRetrievePartitionPropertiesWhenPartitionIdIsInva
}
}
}

/// <summary>
/// Verifies that the <see cref="EventHubProducerClient" /> is able to
/// connect to the Event Hubs service.
/// </summary>
///
[Test]
public async Task ProducerCannotRetrieveMetadataWhenProxyIsInvalid()
{
await using (EventHubScope scope = await EventHubScope.CreateAsync(1))
{
var invalidProxyOptions = new EventHubProducerClientOptions
{
RetryOptions = new EventHubsRetryOptions { TryTimeout = TimeSpan.FromMinutes(2) },

ConnectionOptions = new EventHubConnectionOptions
{
Proxy = new WebProxy("http://1.2.3.4:9999"),
TransportType = EventHubsTransportType.AmqpWebSockets
}
};

await using (var producer = new EventHubProducerClient(EventHubsTestEnvironment.Instance.FullyQualifiedNamespace, scope.EventHubName, EventHubsTestEnvironment.Instance.Credential))
await using (var invalidProxyProducer = new EventHubProducerClient(EventHubsTestEnvironment.Instance.FullyQualifiedNamespace, scope.EventHubName, EventHubsTestEnvironment.Instance.Credential, invalidProxyOptions))
{
var partition = (await producer.GetPartitionIdsAsync()).First();

Assert.That(async () => await invalidProxyProducer.GetPartitionIdsAsync(),
Throws
.InstanceOf<WebSocketException>()
.Or.InstanceOf<TimeoutException>()
.Or.InstanceOf<OperationCanceledException>());

Assert.That(async () => await invalidProxyProducer.GetEventHubPropertiesAsync(),
Throws
.InstanceOf<WebSocketException>()
.Or.InstanceOf<TimeoutException>()
.Or.InstanceOf<OperationCanceledException>());

Assert.That(async () => await invalidProxyProducer.GetPartitionPropertiesAsync(partition),
Throws
.InstanceOf<WebSocketException>()
.Or.InstanceOf<TimeoutException>()
.Or.InstanceOf<OperationCanceledException>());
}
}
}
}
}

0 comments on commit f962c02

Please sign in to comment.