Closed Will-at-FreedomDev closed 5 months ago
You should use IHostedService
to initialize data.
You should use
IHostedService
to initialize data.
Can you elaborate? Will fixtures/tests wait to initialize if we implement this?
Also, I feel like this is still a workaround to the bug report I submitted. Unless this is a known behavior/bug/limitation, that comment doesn't really address the root issue.
But as mentioned, we have an acceptable workaround as it is. I just wanted to submit this issue in case it was not known / other people will be able to find this issue for documentation purposes at least.
services.AddHostedService<SomeHostedService>();
class SomeHostedService : IHostedService
{
public Task StartAsync(CancellationToken stoppingToken)
{
// Do any thing if you want.
}
public Task StopAsync(CancellationToken stoppingToken)
{
// Do any thing if you want.
}
}
That works too as a workaround to the bug I reported. I would suggest updating some documentation somewhere to avoid using the host methods ConfigureServices
and Configure
as they have this race condition issue. I feel like the bug itself isn't worth addressing (assuming it's possible)
Thanks for your reminder. I have added a section titled Initialize some data on startup
.
Describe the bug This might be the expected behavior, but I couldn't find any documentation leading me to believe that it was.
We had this setup, but when you put a delay in
Configure()
, it was apparent that Startup did not complete before the first test was executed. Actually, many of our tests started and completed beforeConfigure()
was completely finished.To Reproduce Steps to reproduce the behavior:
Expected behavior Nothing of XUnit should be created/initialized/started until Startup and every method, including
.Configure()
has completed. This includes:Screenshots If applicable, add screenshots to help explain your problem.
Desktop (please complete the following information):
Additional context This is our automated testing csproj contents
This was an acceptable workaround that DID prevent any XUnit constructs from initializing/starting:
Edit: fixed a typo in the workaround code snippet.