Skip to content

Commit

Permalink
Make SyncFixture users use seperate directories and clean them up
Browse files Browse the repository at this point in the history
  • Loading branch information
myieye committed Dec 11, 2024
1 parent ce28810 commit d2804e0
Showing 1 changed file with 6 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -17,21 +17,23 @@ public class SyncFixture : IAsyncLifetime
_services.ServiceProvider.GetRequiredService<CrdtFwdataProjectSyncService>();
public IServiceProvider Services => _services.ServiceProvider;
private readonly string _projectName;
private readonly string _projectFolder;
private readonly IDisposable _cleanup;

public static SyncFixture Create([CallerMemberName] string projectName = "", [CallerMemberName] string projectFolder = "") => new(projectName, projectFolder);

private SyncFixture(string projectName, string projectFolder)
{
_projectName = projectName;
_projectFolder = projectFolder;
var crdtServices = new ServiceCollection()
.AddSyncServices(projectFolder);
var rootServiceProvider = crdtServices.BuildServiceProvider();
_cleanup = Defer.Action(() => rootServiceProvider.Dispose());
_services = rootServiceProvider.CreateAsyncScope();
}

public SyncFixture(): this("sena-3_" + Guid.NewGuid().ToString("N"), "FwLiteSyncFixture")
public SyncFixture(): this("sena-3_" + Guid.NewGuid().ToString().Split("-")[0], "FwLiteSyncFixture" + Guid.NewGuid().ToString().Split("-")[0])
{
}

Expand All @@ -58,6 +60,9 @@ public async Task DisposeAsync()
{
await _services.DisposeAsync();
_cleanup.Dispose();

Microsoft.Data.Sqlite.SqliteConnection.ClearAllPools();
Directory.Delete(_projectFolder, true);
}

public CrdtMiniLcmApi CrdtApi { get; set; } = null!;
Expand Down

0 comments on commit d2804e0

Please sign in to comment.