HangfireIO / Hangfire

An easy way to perform background job processing in .NET and .NET Core applications. No Windows Service or separate process required
https://www.hangfire.io
Other
9.33k stars 1.69k forks source link

Recreation of Hangfire Services results in Jobs not getting queued in integration tests #2293

Open tt-es opened 1 year ago

tt-es commented 1 year ago

I wrote a base class for integration tests of custom job filters. The class completely recreates the DI-Container and the HangfireJobClient and Server for every test. I currently have three tests for a cutom filter we use which all pass when run in isolation but as soon as I run them in one session (NUnit) only the first one passes. In subsequent test runs the job client won't return a job id when enqueueing.

Does hangfire keep some static settings in memory that has to be cleared for this to work?

the flow of the tests is as follow:

Register all relevant services (incl. hangfire) -> Create DI-Container -> Create JobClient & Server -> Run test method -> Dispose Server.

JenPullUp commented 3 weeks ago

did you end up fixing this? i am running into the exact same problem, on their own they succeed but in a batch only the first one succeeds, the hangfire service seems to try to access something that is taken down in the teardown. here is a link to my stackoverflow page:

https://stackoverflow.com/questions/78931021/how-to-properly-dispose-hangfire-after-reqnroll-integration-testing

tt-es commented 2 weeks ago

@JenPullUp it's been a while but I think we just put all tests per test class in a single method. My guess is that NUnit runs the tests per class in a single process and hangfire has some persistent/static stuff that is not properly cleaned up or recreated. So you could also put each test in it's own class I guess.