mirror of
				https://github.com/nsnail/Ocelot.git
				synced 2025-11-04 15:10:50 +08:00 
			
		
		
		
	Merge branch 'jmezach-bugfix/fcp-dispose' into develop
This commit is contained in:
		@@ -1,4 +1,4 @@
 | 
				
			|||||||
#tool "nuget:?package=GitVersion.CommandLine&version=5.0.1"
 | 
					#tool "nuget:?package=GitVersion.CommandLine&version=5.0.1"
 | 
				
			||||||
#tool "nuget:?package=GitReleaseNotes"
 | 
					#tool "nuget:?package=GitReleaseNotes"
 | 
				
			||||||
#addin nuget:?package=Cake.Json
 | 
					#addin nuget:?package=Cake.Json
 | 
				
			||||||
#addin nuget:?package=Newtonsoft.Json
 | 
					#addin nuget:?package=Newtonsoft.Json
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -105,7 +105,8 @@ namespace Ocelot.Configuration.Repository
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
        public void Dispose()
 | 
					        public void Dispose()
 | 
				
			||||||
        {
 | 
					        {
 | 
				
			||||||
            _timer.Dispose();
 | 
					            _timer?.Dispose();
 | 
				
			||||||
 | 
					            _timer = null;
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -41,13 +41,13 @@ namespace Ocelot.UnitTests.Configuration
 | 
				
			|||||||
            _internalConfigCreator = new Mock<IInternalConfigurationCreator>();
 | 
					            _internalConfigCreator = new Mock<IInternalConfigurationCreator>();
 | 
				
			||||||
            _internalConfigCreator.Setup(x => x.Create(It.IsAny<FileConfiguration>())).ReturnsAsync(new OkResponse<IInternalConfiguration>(_internalConfig));
 | 
					            _internalConfigCreator.Setup(x => x.Create(It.IsAny<FileConfiguration>())).ReturnsAsync(new OkResponse<IInternalConfiguration>(_internalConfig));
 | 
				
			||||||
            _poller = new FileConfigurationPoller(_factory.Object, _repo.Object, _config.Object, _internalConfigRepo.Object, _internalConfigCreator.Object);
 | 
					            _poller = new FileConfigurationPoller(_factory.Object, _repo.Object, _config.Object, _internalConfigRepo.Object, _internalConfigCreator.Object);
 | 
				
			||||||
            _poller.StartAsync(new CancellationToken());
 | 
					 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        [Fact]
 | 
					        [Fact]
 | 
				
			||||||
        public void should_start()
 | 
					        public void should_start()
 | 
				
			||||||
        {
 | 
					        {
 | 
				
			||||||
            this.Given(x => ThenTheSetterIsCalled(_fileConfig, 1))
 | 
					            this.Given(x => GivenPollerHasStarted())
 | 
				
			||||||
 | 
					                .Given(x => ThenTheSetterIsCalled(_fileConfig, 1))
 | 
				
			||||||
                .BDDfy();
 | 
					                .BDDfy();
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -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))
 | 
					                .Then(x => ThenTheSetterIsCalledAtLeast(newConfig, 1))
 | 
				
			||||||
                .BDDfy();
 | 
					                .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))
 | 
					                .Then(x => ThenTheSetterIsCalled(newConfig, 1))
 | 
				
			||||||
                .BDDfy();
 | 
					                .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))
 | 
					                .Then(x => ThenTheSetterIsCalled(newConfig, 0))
 | 
				
			||||||
                .BDDfy();
 | 
					                .BDDfy();
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        [Fact]
 | 
				
			||||||
 | 
					        public void should_dispose_cleanly_without_starting()
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
 | 
					            this.When(x => WhenPollerIsDisposed())
 | 
				
			||||||
 | 
					                .BDDfy();
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        private void GivenPollerHasStarted()
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
 | 
					            _poller.StartAsync(CancellationToken.None);
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        private void WhenProviderErrors()
 | 
					        private void WhenProviderErrors()
 | 
				
			||||||
        {
 | 
					        {
 | 
				
			||||||
            _repo
 | 
					            _repo
 | 
				
			||||||
@@ -141,6 +156,11 @@ namespace Ocelot.UnitTests.Configuration
 | 
				
			|||||||
                .ReturnsAsync(new OkResponse<FileConfiguration>(newConfig));
 | 
					                .ReturnsAsync(new OkResponse<FileConfiguration>(newConfig));
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        private void WhenPollerIsDisposed()
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
 | 
					            _poller.Dispose();
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        private void ThenTheSetterIsCalled(FileConfiguration fileConfig, int times)
 | 
					        private void ThenTheSetterIsCalled(FileConfiguration fileConfig, int times)
 | 
				
			||||||
        {
 | 
					        {
 | 
				
			||||||
            var result = WaitFor(4000).Until(() =>
 | 
					            var result = WaitFor(4000).Until(() =>
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user