-
Notifications
You must be signed in to change notification settings - Fork 44
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make HalibutRuntime implement IDisposable (#572)
- Loading branch information
1 parent
4c88549
commit 97df1d6
Showing
3 changed files
with
62 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
using System; | ||
using System.Threading.Tasks; | ||
using FluentAssertions; | ||
using Halibut.Tests.Support; | ||
using Halibut.Tests.Support.TestAttributes; | ||
using Halibut.Tests.Support.TestCases; | ||
using Halibut.Tests.TestServices.Async; | ||
using Halibut.TestUtils.Contracts; | ||
using NUnit.Framework; | ||
|
||
namespace Halibut.Tests | ||
{ | ||
public class HalibutRuntimeDisposal : BaseTest | ||
{ | ||
[Test] | ||
[LatestClientAndLatestServiceTestCases(testNetworkConditions: false)] | ||
public async Task CanDisposeOfHalibutClientAndService(ClientAndServiceTestCase clientAndServiceTestCase) | ||
{ | ||
var timeoutsAndLimits = new HalibutTimeoutsAndLimitsForTestsBuilder().Build(); | ||
timeoutsAndLimits.PollingRequestQueueTimeout = TimeSpan.FromSeconds(15); | ||
|
||
var clientAndService = await clientAndServiceTestCase.CreateTestCaseBuilder() | ||
.WithStandardServices() | ||
.AsLatestClientAndLatestServiceBuilder() | ||
.WithHalibutTimeoutsAndLimits(timeoutsAndLimits) | ||
.Build(CancellationToken); | ||
|
||
var echoServiceClient = clientAndService.CreateAsyncClient<IEchoService, IAsyncClientEchoService>(); | ||
|
||
await echoServiceClient.SayHelloAsync("Hi"); | ||
|
||
#pragma warning disable VSTHRD103 | ||
#pragma warning disable CS0618 // Type or member is obsolete | ||
clientAndService.Service.Dispose(); | ||
#pragma warning restore CS0618 // Type or member is obsolete | ||
#pragma warning restore VSTHRD103 | ||
|
||
// The Service and Client are both HalibutRuntimes so ensuring that the Service is Dispose works should also ensure that the Client Dispose works. | ||
// This test does not test specifics of the Dispose to ensure that all resources are cleaned up, but rather that the HalibutRuntime stops working. | ||
// Future improvements could ensure that all the specifics of Dispose work as expected e.g. active connections are disconnected, listening ports freed up etc. | ||
await AssertionExtensions.Should(() => echoServiceClient.SayHelloAsync("Hey")).ThrowAsync<HalibutClientException>("The Service should have been shutdown on Dispose"); | ||
|
||
#pragma warning disable VSTHRD103 | ||
#pragma warning disable CS0618 // Type or member is obsolete | ||
clientAndService.Client.Dispose(); | ||
#pragma warning restore CS0618 // Type or member is obsolete | ||
#pragma warning restore VSTHRD103 | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters