-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Use injected repository service instead of static singleton #1453
Comments
I think this requires some breaking changes in order to work. Unless you can figure out a way to support in 3.x without breaking API and compatibility? Scheduling for v4 for now. |
@lahma Is this problem still present on latest dev version? I added quartz into my integration tests using |
Probably is still present in the latest dev version. A lot of changes are needed to make Quartz use DI services instead of current configuration scheme (and still support the old one to a degree). In tests you could manually try to remove scheduler from scheduler repository or assign unique name (GUID or something) for each created scheduler. |
@lahma Exactly what I am trying right now, thank you for quick response. |
I'm not sure if you ever got it to work. I ran into exactly the same issue: I'm trying to run multiple integration tests for jobs in parallel using The solution that ended up working for me was instantiating a new services.AddQuartz(q =>
{
q.UseInMemoryStore();
q.UseMicrosoftDependencyInjectionJobFactory();
if (Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT") == "IntegrationTest")
{
q.SchedulerId = Guid.NewGuid().ToString();
q.SchedulerName = Guid.NewGuid().ToString();
}
// Rest of config...
}); |
@kolpav it's in v3 branch and available on MyGet already, but not in v4 (main). |
And I mean thread-safety, not injection. |
Is your feature request related to a problem? Please describe.
I observed this problem when added quartz to my ASP.NET project and integration tests started to fail because of the error "Scheduler with the name xxx already exists". After investigations, I found out that this is because of a shared context between different instances of
WebApplicationFactory
. Reading the source codes led me to this line which shows a static repository is being used as a singleton. As the tests run in shared memory space, this static object is also shared between them.Although the error could be solved by defining locks in custom hosted services, this behavior is breaking the isolation of tests and requires additional considerations in any case. For example, we cannot use separate databases for each test if they are going to run in parallel.
Describe the solution you'd like
Register the repository as a singleton service and inject it into the dependent classes.
Also relates to #399.
The text was updated successfully, but these errors were encountered: