HangfireIO / HangfireIO/Hangfire
Hangfire fails on app.UseHangfireServer() during tests
- Dominant language
- C#
- Stars
- 10.1k
- Forks
- 1.8k
- Avg merge
- 1h 19m
- Merged PRs (30d)
- 1
Description
I am using net core TestHost which is re-created between acceptance tests. However very often when tests are run startup fails randomly on test at line 'app.UseHangfireServer()'. This smells issue where hangfire is using global static state.
Environment .Net core 1.1.2. (netcoreapp1.1)
Error and stack trace:
```
System.InvalidOperationException : JobStorage.Current property value has not been initialized. You must set it before using Hangfire Client or Server API.
at Hangfire.JobStorage.get_Current()
at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitScoped(ScopedCallSite scopedCallSite, ServiceProvider provider)
at Microsoft.Extensions.DependencyInjection.ServiceProvider.<>c__DisplayClass16_0.b__0(ServiceProvider provider)
at Microsoft.Extensions.DependencyInjection.ServiceProviderServiceExtensions.GetRequiredService(IServiceProvider provider, Type serviceType)
at Microsoft.Extensions.DependencyInjection.ServiceProviderServiceExtensions.GetRequiredService[T](IServiceProvider provider)
at Hangfire.HangfireApplicationBuilderExtensions.UseHangfireServer(IApplicationBuilder app, BackgroundJobServerOptions options, IEnumerable`1 additionalProcesses, JobStorage storage)
at Pdf.Storage.Test.TestStartup.Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory) in C:\work\pdf-storage\Test\TestStartup.cs:line 39
```
Meaningfull lines on Startup:
```
Services:
services.AddHangfire(config => config.UseMemoryStorage());
Configuration:
app.UseHangfireServer(); // Error occurs here.
app.UseHangfireDashboard();
```
Contributor guide
Research direction
Start by reproducing the failure with the recreated TestHost acceptance tests and inspect Test/TestStartup.cs around line 39. Trace the AddHangfire registration and UseHangfireServer startup path, focusing on the reported JobStorage.Current initialization error. Done means repeated test startup no longer fails intermittently with this exception.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- csharp
- Domain
- backend, testing
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100