From 193c698562ce956f5c41135a524d9a16f46f9eed Mon Sep 17 00:00:00 2001 From: Sergey Odinokov Date: Tue, 27 Jan 2015 12:41:44 +0300 Subject: [PATCH] Wrap ServerBootstrapper with automatic retry Fixes #291 --- src/Hangfire.Core/BackgroundJobServer.cs | 9 +++++++-- src/Hangfire.Core/Server/ServerBootstrapper.cs | 2 +- tests/Hangfire.Core.Tests/BackgroundJobServerFacts.cs | 11 +++++++++-- 3 files changed, 17 insertions(+), 5 deletions(-) diff --git a/src/Hangfire.Core/BackgroundJobServer.cs b/src/Hangfire.Core/BackgroundJobServer.cs index 20ff41b61..ab338635e 100644 --- a/src/Hangfire.Core/BackgroundJobServer.cs +++ b/src/Hangfire.Core/BackgroundJobServer.cs @@ -119,7 +119,7 @@ internal virtual IServerSupervisor GetBootstrapSupervisor() _storage, new Lazy(GetSupervisors)); - return new ServerSupervisor( + return CreateSupervisor( bootstrapper, new ServerSupervisorOptions { @@ -162,7 +162,12 @@ private IEnumerable GetCommonComponents() private static ServerSupervisor CreateSupervisor(IServerComponent component) { - return new ServerSupervisor(new AutomaticRetryServerComponentWrapper(component)); + return CreateSupervisor(component, new ServerSupervisorOptions()); + } + + private static ServerSupervisor CreateSupervisor(IServerComponent component, ServerSupervisorOptions options) + { + return new ServerSupervisor(new AutomaticRetryServerComponentWrapper(component), options); } } } diff --git a/src/Hangfire.Core/Server/ServerBootstrapper.cs b/src/Hangfire.Core/Server/ServerBootstrapper.cs index 8ff31c452..c25890eb1 100644 --- a/src/Hangfire.Core/Server/ServerBootstrapper.cs +++ b/src/Hangfire.Core/Server/ServerBootstrapper.cs @@ -102,7 +102,7 @@ public void Execute(CancellationToken cancellationToken) public override string ToString() { - return "Server Core"; + return "Server Bootstrapper"; } public void Dispose() diff --git a/tests/Hangfire.Core.Tests/BackgroundJobServerFacts.cs b/tests/Hangfire.Core.Tests/BackgroundJobServerFacts.cs index 7181c2f6c..31f296887 100644 --- a/tests/Hangfire.Core.Tests/BackgroundJobServerFacts.cs +++ b/tests/Hangfire.Core.Tests/BackgroundJobServerFacts.cs @@ -92,14 +92,21 @@ public void Dispose_DisposesBootstrapSupervisor() } [Fact] - public void GetBootstrapSupervisor_ReturnsNonNullResult() + public void GetBootstrapSupervisor_ReturnsBootstrapper_WrappedWithAutomaticRetry() { + // Arrange var server = CreateServer(); + // Act var supervisor = server.GetBootstrapSupervisor(); + // Assert Assert.NotNull(supervisor); - Assert.IsType(((ServerSupervisor) supervisor).Component); + + var wrapper = ((ServerSupervisor) supervisor).Component; + + Assert.IsType(wrapper); + Assert.IsType(((AutomaticRetryServerComponentWrapper)wrapper).InnerComponent); } [Fact]