Skip to content

Commit

Permalink
Externally managed SNS/SQS clients were disposed when experimental co…
Browse files Browse the repository at this point in the history
…nstructor added in 7.1.0 - 7.1 (#2640)

Co-authored-by: WilliamBZA <WilliamBZA@users.noreply.github.com>
  • Loading branch information
ramonsmits and WilliamBZA authored Nov 28, 2024
1 parent 2296b49 commit b5f6176
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 7 deletions.
38 changes: 37 additions & 1 deletion src/NServiceBus.Transport.SQS.Tests/SdkClientsDisposeTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public async Task ShouldDisposeSqsAndSnsClients(bool disposeSqs, bool disposeSns
}

[Test]
public async Task Should_not_dispose_clients_passed_into_transport()
public async Task Should_not_dispose_clients_passed_into_transport_constructor()
{
var mockSqsClient = new MockSqsClient();
var mockSnsClient = new MockSnsClient();
Expand Down Expand Up @@ -106,6 +106,42 @@ public async Task Should_not_dispose_clients_passed_into_transport()
});
}

[Test]
public async Task Should_not_dispose_clients_passed_into_transport_constructor_with_delayed_delivery()
{
var mockSqsClient = new MockSqsClient();
var mockSnsClient = new MockSnsClient();
var mockS3Client = new MockS3Client();

#pragma warning disable NSBSQSEXP0001
var transport = new SqsTransport(mockSqsClient, mockSnsClient, enableDelayedDelivery: false)
#pragma warning restore NSBSQSEXP0001
{
S3 = new S3Settings("123", "k", mockS3Client)
};

var hostSettings = new HostSettings(
"Test",
"Test",
new StartupDiagnosticEntries(),
(s, ex, cancel) => { },
false
);
var receivers = Array.Empty<ReceiveSettings>();
var sendingAddresses = Array.Empty<string>();

var infra = await transport.Initialize(hostSettings, receivers, sendingAddresses);

await infra.Shutdown();

Assert.Multiple(() =>
{
Assert.That(mockSqsClient.DisposeInvoked, Is.False);
Assert.That(mockSnsClient.DisposeInvoked, Is.False);
Assert.That(mockS3Client.DisposeInvoked, Is.False);
});
}

[Test]
public async Task Should_dispose_default_clients()
{
Expand Down
14 changes: 8 additions & 6 deletions src/NServiceBus.Transport.SQS/Configure/SqsTransport.cs
Original file line number Diff line number Diff line change
Expand Up @@ -241,17 +241,19 @@ public SqsTransport(
IAmazonSimpleNotificationService snsClient,
bool enableDelayedDelivery
)
: this(
sqsClient,
snsClient,
: base(
TransportTransactionMode.ReceiveOnly,
supportsDelayedDelivery: enableDelayedDelivery,
supportsPublishSubscribe: true,
enableDelayedDelivery: enableDelayedDelivery
supportsTTBR: true
)
{
this.sqsClient = sqsClient;
this.snsClient = snsClient;
// Use properties to ensure `externallyManagedSqsClient` is set
SqsClient = sqsClient;
SnsClient = snsClient;
}

// Only invoke when not using external SQS and SNS clients
internal SqsTransport(
IAmazonSQS sqsClient,
IAmazonSimpleNotificationService snsClient,
Expand Down

0 comments on commit b5f6176

Please sign in to comment.