Files
server/test/SeederApi.IntegrationTest/SeederApiApplicationFactory.cs
Matt Gibson 2e6bf44504 Add SeederApi PlayData delete scheduled job (#7281)
* Use Quartz-based hosted service to clear old play data

We need to stop possible bloat of databases should users of a seeded data fail to appropriately clean up after themselves.

Using the hosted services present in other projects, this adds an alive job and play data delete job to the SeederApi

* Trigger play data delete frequently enough for dev servers

Development servers are unlikely to be running at midnight UTC, so we need to delete more frequently to ensure data is cleaned up. The Job still deletes things older than a day, it just checks much more frequently, now.

* Fixup sonarqube

* Fixup parallel test issues with jobs hosted services

* Remove alive job and unneeded fixme

* Revert "Remove alive job and unneeded fixme"

This reverts commit 0c10e4a675.

* Simplify alive job

Used the wrong job as a template, the api alive job is much more like what we want.

* Update readme to callout ephemeral data
2026-04-13 09:57:23 -07:00

44 lines
1.4 KiB
C#

using Bit.Core.Services;
using Bit.IntegrationTestCommon;
using Bit.IntegrationTestCommon.Factories;
using Microsoft.AspNetCore.TestHost;
namespace Bit.SeederApi.IntegrationTest;
public class SeederApiApplicationFactory : WebApplicationFactoryBase<Startup>
{
public SeederApiApplicationFactory()
{
TestDatabase = new SqliteTestDatabase();
_configureTestServices.Add(serviceCollection =>
{
serviceCollection.AddSingleton<IPlayIdService, NeverPlayIdServices>();
serviceCollection.AddHttpContextAccessor();
});
}
protected override void ConfigureWebHost(IWebHostBuilder builder)
{
base.ConfigureWebHost(builder);
builder.ConfigureTestServices(services =>
{
// Remove scheduled background jobs to prevent errors in parallel test execution
var jobService = services.First(sd => sd.ServiceType == typeof(IHostedService) && sd.ImplementationType == typeof(Jobs.JobsHostedService));
services.Remove(jobService);
});
}
public void ConfigureAuth(string username, string password)
{
UpdateConfiguration(builder =>
{
builder.AddInMemoryCollection(new Dictionary<string, string>
{
{ "seederSettings:Username", username},
{ "seederSettings:Password", password}
});
});
}
}