From fd74ea280b0c8973234383131d0350cfe6097df9 Mon Sep 17 00:00:00 2001 From: Jonathan Mezach Date: Thu, 12 Dec 2019 08:12:10 +0100 Subject: [PATCH 1/3] Do not crash host on Dispose --- src/Ocelot/Configuration/Repository/FileConfigurationPoller.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Ocelot/Configuration/Repository/FileConfigurationPoller.cs b/src/Ocelot/Configuration/Repository/FileConfigurationPoller.cs index cca50d0b..9a2b67e6 100644 --- a/src/Ocelot/Configuration/Repository/FileConfigurationPoller.cs +++ b/src/Ocelot/Configuration/Repository/FileConfigurationPoller.cs @@ -105,7 +105,8 @@ namespace Ocelot.Configuration.Repository public void Dispose() { - _timer.Dispose(); + _timer?.Dispose(); + _timer = null; } } } From ac7d0d0af3e9f16c6f76237ca7750e7fdf466915 Mon Sep 17 00:00:00 2001 From: Jonathan Mezach Date: Thu, 12 Dec 2019 08:35:22 +0100 Subject: [PATCH 2/3] Add test --- .../FileConfigurationPollerTests.cs | 32 +++++++++++++++---- 1 file changed, 26 insertions(+), 6 deletions(-) diff --git a/test/Ocelot.UnitTests/Configuration/FileConfigurationPollerTests.cs b/test/Ocelot.UnitTests/Configuration/FileConfigurationPollerTests.cs index 3008fc6b..bfc0c98c 100644 --- a/test/Ocelot.UnitTests/Configuration/FileConfigurationPollerTests.cs +++ b/test/Ocelot.UnitTests/Configuration/FileConfigurationPollerTests.cs @@ -41,14 +41,14 @@ namespace Ocelot.UnitTests.Configuration _internalConfigCreator = new Mock(); _internalConfigCreator.Setup(x => x.Create(It.IsAny())).ReturnsAsync(new OkResponse(_internalConfig)); _poller = new FileConfigurationPoller(_factory.Object, _repo.Object, _config.Object, _internalConfigRepo.Object, _internalConfigCreator.Object); - _poller.StartAsync(new CancellationToken()); } [Fact] public void should_start() { - this.Given(x => ThenTheSetterIsCalled(_fileConfig, 1)) - .BDDfy(); + this.Given(x => GivenPollerHasStarted()) + .Given(x => ThenTheSetterIsCalled(_fileConfig, 1)) + .BDDfy(); } [Fact] @@ -71,7 +71,8 @@ namespace Ocelot.UnitTests.Configuration } }; - this.Given(x => WhenTheConfigIsChanged(newConfig, 0)) + this.Given(x => GivenPollerHasStarted()) + .Given(x => WhenTheConfigIsChanged(newConfig, 0)) .Then(x => ThenTheSetterIsCalledAtLeast(newConfig, 1)) .BDDfy(); } @@ -96,7 +97,8 @@ namespace Ocelot.UnitTests.Configuration } }; - this.Given(x => WhenTheConfigIsChanged(newConfig, 10)) + this.Given(x => GivenPollerHasStarted()) + .Given(x => WhenTheConfigIsChanged(newConfig, 10)) .Then(x => ThenTheSetterIsCalled(newConfig, 1)) .BDDfy(); } @@ -121,11 +123,24 @@ namespace Ocelot.UnitTests.Configuration } }; - this.Given(x => WhenProviderErrors()) + this.Given(x => GivenPollerHasStarted()) + .Given(x => WhenProviderErrors()) .Then(x => ThenTheSetterIsCalled(newConfig, 0)) .BDDfy(); } + [Fact] + public void should_dispose_cleanly_without_starting() + { + this.When(x => WhenPollerIsDisposed()) + .BDDfy(); + } + + private void GivenPollerHasStarted() + { + _poller.StartAsync(CancellationToken.None); + } + private void WhenProviderErrors() { _repo @@ -141,6 +156,11 @@ namespace Ocelot.UnitTests.Configuration .ReturnsAsync(new OkResponse(newConfig)); } + private void WhenPollerIsDisposed() + { + _poller.Dispose(); + } + private void ThenTheSetterIsCalled(FileConfiguration fileConfig, int times) { var result = WaitFor(4000).Until(() => From ef52ea3fc48705e19519c67e03a611cb6bdd3236 Mon Sep 17 00:00:00 2001 From: Jonathan Mezach Date: Thu, 12 Dec 2019 08:48:13 +0100 Subject: [PATCH 3/3] Pin GitVersion.CommandLine package version --- build.cake | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.cake b/build.cake index 5eb3d77c..8726183e 100644 --- a/build.cake +++ b/build.cake @@ -1,4 +1,4 @@ -#tool "nuget:?package=GitVersion.CommandLine" +#tool "nuget:?package=GitVersion.CommandLine&version=5.0.1" #tool "nuget:?package=GitReleaseNotes" #addin nuget:?package=Cake.Json #addin nuget:?package=Newtonsoft.Json