Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion backend/FwLite/LcmCrdt.Tests/SnapshotAtCommitServiceTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using SIL.Harmony.Db;
using Microsoft.Data.Sqlite;
using SIL.Harmony.Core;
using Bogus.DataSets;

namespace LcmCrdt.Tests;

Expand Down Expand Up @@ -329,8 +330,10 @@ await _api.CreateWritingSystem(new WritingSystem()
public async Task DisposeAsync()
{
await _dbContext.Database.CloseConnectionAsync();
SqliteConnection.ClearAllPools();
using var clearConn = new SqliteConnection($"Data Source={_dbPath}");
SqliteConnection.ClearPool(clearConn);
await _dbContext.Database.EnsureDeletedAsync();
await _dbContext.DisposeAsync();
await _services.DisposeAsync();
if (File.Exists(_dbPath))
{
Expand Down
9 changes: 5 additions & 4 deletions backend/FwLite/LcmCrdt/SnapshotAtCommitService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public class SnapshotAtCommitService(
{
using var activity = _activitySource.StartActivity();
activity?.SetTag("app.commit_id", commitId);
var dbContext = await crdtDbContextFactory.CreateDbContextAsync();
await using var dbContext = await crdtDbContextFactory.CreateDbContextAsync();
var commit = await dbContext.Commits.SingleOrDefaultAsync(c => c.Id == commitId);
if (commit is null)
{
Expand All @@ -42,7 +42,7 @@ public class SnapshotAtCommitService(
await ForkDatabase(dbPath, forkDbPath);

var project = new CrdtProject(currentProjectService.Project.Name, forkDbPath);
var serviceScope = serviceProvider.CreateAsyncScope();
await using var serviceScope = serviceProvider.CreateAsyncScope();
var scopedCurrentProjectService = serviceScope.ServiceProvider.GetRequiredService<CurrentProjectService>();
var projectData = await scopedCurrentProjectService.SetupProjectContext(project);

Expand All @@ -51,7 +51,7 @@ public class SnapshotAtCommitService(
var optionsBuilder = new DbContextOptionsBuilder<LcmCrdtDbContext>()
.UseSqlite($"Data Source={forkDbPath}");
LcmCrdtKernel.ConfigureDbOptions(serviceScope.ServiceProvider, optionsBuilder);
ICrdtDbContext forkDbContext = new LcmCrdtDbContext(optionsBuilder.Options, crdtConfig);
await using var forkDbContext = new LcmCrdtDbContext(optionsBuilder.Options, crdtConfig);

var deleted = await DeleteCommitsAfter(forkDbContext, commit, preserveAllFieldWorksCommits);
logger.LogInformation("Deleted {Deleted} commits after {CommitId}", deleted, commitId);
Expand All @@ -68,7 +68,8 @@ public class SnapshotAtCommitService(
{
try
{
SqliteConnection.ClearAllPools();
using var clearConn = new SqliteConnection($"Data Source={forkDbPath}");
SqliteConnection.ClearPool(clearConn);
File.Delete(forkDbPath);
}
catch (Exception ex)
Expand Down
Loading