perrich / Hangfire.MemoryStorage

A memory storage for Hangfire.
Apache License 2.0
131 stars 43 forks source link

MemoryStorage Behaviour needs to be made explicit #24

Closed gupta-ankit closed 5 years ago

gupta-ankit commented 5 years ago

I am using MemoryStorage for my unit tests to check if background jobs are enqueued. I initialize like this

Hangfire.JobStorage.Current = new MemoryStorage();

During my tests, I often use the following to check the number of enqueued jobs increased.

Hangfire.JobStorage.Current.GetMonitoringApi().EnqueuedCount("default")

Since MemoryStorage() uses a static dictionary, the storage is shared across tests, which can be confusing. It is an issue since I am assuming the most common use of MemoryStorage is during tests, and therefore I think it might be useful if this point is made clear in the README. Alternatively, a flag to create a new dictionary for storing jobs can be added either to the MemoryStorage constructor or the MemoryStorageOptions to allow the developers to make that choice.

perrich commented 5 years ago

Hi, I will check to remove the static dictionary or add a parameter to enable/disable that.

perrich commented 5 years ago

I've checked but it's complex to change internal behavior.

First of all, I will update the readme as you said.

JelleHissink commented 5 years ago

Hi I implemented this.

So I hope you consider accepting the pull-request and publish a new version.

perrich commented 5 years ago

Thanks, I'll check and merge your PR as soon as possible.